Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module cleanup + Potion "durability" + Documentation #3

Merged
merged 6 commits into from
Nov 15, 2016
Merged

Conversation

xrtariq2594
Copy link
Member

@xrtariq2594 xrtariq2594 commented Nov 10, 2016

Contains

  • Moved potion prefabs from Alchemy module to this one.
  • Cleanup performed on the potion prefabs and related components to remove unnecessary stuff.
  • Potions can now be turned back into their original bottle prefabs as long as they have enough durability remaining (Add "durability" to potion bottles #1).
  • Added documentation to all classes.

How to Test

  • Spawn potions using the console, and drink them. If no potion bottle is returned, then it's a success.

  • To test the other scenario, modify one of the potion prefabs to include the following code:

    "Durability": {
        "durability": 9,
        "maxDurability": 9
    },

Then, spawn that potion and drink it. It should return an empty GlassBottle.

  • Proofread the documentation.

Issues

None so far.

Credits

@AWebb3701 and @Cervator for advice.

@xrtariq2594 xrtariq2594 added Category: Doc Requests, Issues and Changes targeting javadoc and module documentation Type: Improvement Request for or addition/enhancement of a feature labels Nov 10, 2016
Copy link
Contributor

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, and probably one of the best documented pieces of code in the whole project 😆
Have a look at the comments, mabye they are helpful at some point.

Tested out the durability, and it looks to work just right.

* @param instigator The instigator who is applying this effect on the entity. It can be a herb, potion, etc.
* @param entity The entity who the herb effect is being applied on.
* @param magnitude The magnitude of the effect.
* @param duration The duration of the effect.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the unit of duration? Imho this should be stated in the javadoc, e.g., "The duration of the effect in seconds"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. And actually the duration is in milliseconds.

* @param id This particular HerbEffect's ID. Can be used to differentiate different effects under the
* same family.
* @param magnitude The magnitude of the effect.
* @param duration The duration of the effect.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing unit spec (2)

@@ -15,7 +15,10 @@
*/
package org.terasology.potions;

// Class containing a list of constant Strings used for potion-related effect type checks.
/**
* This class contains a list of constant Strings used for potion-related effect type checks. Most are self-explanatory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call the "constant Strings" just constants. Are these the effect IDs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, they are basically effect IDs.

@@ -17,10 +17,15 @@

import org.terasology.reflection.MappedContainer;

// This class or container contains details on a particular effect of a potion.
/** This class or mapped container contains details on a particular effect of a potion. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik, the mapped container allows to serialize the effect list. I'd just go for "Common class for describing a potion effect" or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, going with:

Common class for describing an effect that may be present in a potion.

/**
* This HerbEffect wraps any AlterationEffect so that the latter can function within the herbalism systems and be treated
* as a HerbEffect.
*/
public class AlterationEffectWrapperHerbEffect implements HerbEffect {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neatpicking on naming 😛 what about AlterationToHerbEffectWrapper?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! That was an old class from older maintainer (from WoodAndStone in fact).

* Informs whether or not this event has been consumed.
*
* @return True if the the event has been consumed, false otherwise.
*/
@Override
public boolean isConsumed() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may checkout {@inheritDoc} and use cases. this case seems like the javadoc should be same in the parent class (the consumable event). If you don't write javadoc at all, it is automatically copied from the override method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is done.

@@ -20,34 +20,76 @@
import org.terasology.entitySystem.event.Event;
import org.terasology.potions.component.PotionComponent;

/**
* This event is sent to an entity to indicate that it'll be drinking a given potion.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this event treating the potion as one or is it sent for each effect, as the BeforeDrink event?

Copy link
Member Author

@xrtariq2594 xrtariq2594 Nov 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treated the Potion as one.

DrinkPotionEvent sends the entire potion.
BeforeDrinkPotionEvent (now titled BeforeApplyPotionEffectEvent) works on one potion effect at a time.

*
* @param instigator The entity who is trying to consume this potion.
* @param item A reference to the potion item entity which has the potion effect.
* @param p The PotionComponent of the potion item.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although well documented, please remove the abbreviated variable names and change them to something more clear

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I un-abbreviated the names.

EntityRef potion = event.getItem();
DurabilityComponent durability = potion.getComponent(DurabilityComponent.class);

// If the Durability component exists.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some people might argue about the usefulness of such comments... I don't mind them, but in this case it is very clear from the code what is happening


// If the Durability component exists.
if (durability != null) {
// If the new durability value will be above 0 following the potion drink, or the bottle has inf durability, proceed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is fine, though ;-)

@xrtariq2594
Copy link
Member Author

xrtariq2594 commented Nov 11, 2016

Overall, I thank you for the suggestions @skaldarnar . I applied to them to the module, and I'll be pushing them tomorrow.

@skaldarnar
Copy link
Contributor

Changes look good! What keeps you from merging this? Anything outstanding to be tested?

@xrtariq2594
Copy link
Member Author

Nothing. I was just waiting for your confirmation before merging @skaldarnar.

Now that I have it, I'll merge this in now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Doc Requests, Issues and Changes targeting javadoc and module documentation Type: Improvement Request for or addition/enhancement of a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants