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

Add javadoc to restore events and RestorationAuthoritySystem #17

Merged
merged 4 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
import org.terasology.logic.players.event.OnPlayerRespawnedEvent;
import org.terasology.math.TeraMath;

/**
* This system takes care of restoration of entities with HealthComponent.
* To increase the health of an entity, send DoRestoreEvent
* <p>
* Logic flow for restoration:
* - DoRestoreEvent
Copy link
Member

Choose a reason for hiding this comment

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

This is too big to consider as part of this PR (since the same word is in use many other places) but I wonder if do is a good term in general for the starting phase of an event chain like this one. "Do" to me very much means that the thing is happening right now. Maybe "Perform" would give a better impression that it is more like an action that is being performed, almost like a stage play might be going through several phases to arrive at an action :-)

This could be overly subjective as interpreting these kinds of words may differ subtly between individuals.

* - BeforeRestoreEvent
* - (HealthComponent saved)
* - OnRestoredEvent
* - OnFullyHealedEvent (if healed to full health)
*/
@RegisterSystem(RegisterMode.AUTHORITY)
public class RestorationAuthoritySystem extends BaseComponentSystem {

Expand All @@ -39,7 +50,8 @@ public void onRestore(DoRestoreEvent event, EntityRef entity, HealthComponent he
if (modifiedRestoreAmount > 0) {
restore(entity, health, modifiedRestoreAmount);
} else {
entity.send(new DoDamageEvent(-modifiedRestoreAmount));
// Cause "healing" damage to entity if modified value of restoration is negative
entity.send(new DoDamageEvent(-modifiedRestoreAmount, EngineDamageTypes.HEALING.get()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Modifications are accumulated as modifiers (additions), multipliers and postModifiers (additions after multipliers).
*/
public class BeforeRestoreEvent extends AbstractConsumableValueModifiableEvent {
/** The entity which is being regenerated. */
/** The entity which is being restored. */
private EntityRef entity;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.terasology.logic.health.event;

import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.event.Event;

/**
Expand All @@ -23,13 +24,20 @@
public class DoRestoreEvent implements Event {
/** The amount of health points being restored. */
private int amount;
/** The instigator of restoration */
Copy link
Member

Choose a reason for hiding this comment

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

Tiny suggestion: rather than use instigator which is already the variable name use a synonym to increase the odds that a reader will understand (instigator could be a somewhat rare word)

Suggested change
/** The instigator of restoration */
/** The entity that caused the restoration */

private EntityRef instigator;

/**
* Constructor for event providing amount of restoration.
* @param amount The amount of restoration.
*/
public DoRestoreEvent(int amount) {
this(amount, EntityRef.NULL);
}

public DoRestoreEvent(int amount, EntityRef entity) {
this.amount = amount;
this.instigator = entity;
}

/**
Expand All @@ -39,4 +47,12 @@ public DoRestoreEvent(int amount) {
public int getAmount() {
return amount;
}

/**
* Method to get the instigator of restoration.
Copy link
Member

Choose a reason for hiding this comment

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

Generally I'd excuse setters & getters from Javadoc unless there is any potential for confusion somehow.

* @return EntityRef of instigator.
*/
public EntityRef getInstigator() {
return instigator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,29 @@

import org.terasology.entitySystem.entity.EntityRef;

/**
* This event is sent after the entity is restored. Final event of restoration logic.
*/
public class OnRestoredEvent extends HealthChangedEvent {
/**
* The amount by which the entity is restored.
*/
private int amount;

/**
* Constructor for creating the event.
Copy link
Member

Choose a reason for hiding this comment

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

Another edge case: should plain constructors have javadoc? In this case maybe if the wording is a slight bit more meaningful (we already know by the constructors presence that it will create the event, so the text doesn't really add anything). I'm not sure if there's really any other meaning to add in this case.

* @param amount The amount of restoration.
* @param instigator EntityRef of cause of restoration.
*/
public OnRestoredEvent(int amount, EntityRef instigator) {
super(instigator, amount);
this.amount = amount;
}

/**
* Method to get the amount of restoration.
* @return amount of restoration.
*/
public int getRegenAmount() {
return amount;
}
Expand Down