Skip to content

Commit 5f86eba

Browse files
committed
Add camera clamp tests and improve javadocs
1 parent 48f0f4e commit 5f86eba

File tree

14 files changed

+414
-68
lines changed

14 files changed

+414
-68
lines changed

buildSrc/src/main/groovy/testing-defaults.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@ jacocoTestReport {
1313
xml.required = true
1414
}
1515
}
16+
17+
configurations {
18+
mockitoAgent
19+
}
20+
21+
dependencies {
22+
testImplementation(libs.mockito.core)
23+
mockitoAgent(libs.mockito.core) {
24+
transitive = false
25+
}
26+
}
27+
28+
tasks {
29+
test {
30+
jvmArgs += "-javaagent:${configurations.mockitoAgent.asPath}"
31+
}
32+
}

litiengine/src/main/java/de/gurkenlabs/litiengine/abilities/effects/AttributeEffect.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected AttributeEffect(final TargetingStrategy targetingStrategy, final Modif
3232
* @param targetingStrategy the strategy to determine the targets of the effect
3333
* @param modification the type of modification to apply to the attribute
3434
* @param delta the value to modify the attribute by
35+
* @param duration the duration of the effect in milliseconds
3536
*/
3637
protected AttributeEffect(final TargetingStrategy targetingStrategy, final Modification modification, final double delta,
3738
final int duration) {
@@ -58,6 +59,7 @@ protected AttributeEffect(final TargetingStrategy targetingStrategy, final IComb
5859
* @param executingEntity the entity executing the effect
5960
* @param modification the type of modification to apply to the attribute
6061
* @param delta the value to modify the attribute by
62+
* @param duration the duration of the effect in milliseconds
6163
*/
6264
protected AttributeEffect(final TargetingStrategy targetingStrategy, final ICombatEntity executingEntity, final Modification modification,
6365
final double delta, final int duration) {

litiengine/src/main/java/de/gurkenlabs/litiengine/abilities/effects/Effect.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public void onEffectApplied(final EffectAppliedListener listener) {
7878
this.appliedListeners.add(listener);
7979
}
8080

81+
/**
82+
* Removes a listener that was previously registered to be notified when the effect is applied.
83+
*
84+
* @param listener The listener to remove.
85+
*/
8186
public void removeEffectAppliedListener(final EffectAppliedListener listener) {
8287
this.appliedListeners.remove(listener);
8388
}
@@ -91,6 +96,11 @@ public void onEffectCeased(final EffectCeasedListener listener) {
9196
this.ceasedListeners.add(listener);
9297
}
9398

99+
/**
100+
* Removes a listener that was previously registered to be notified when the effect ceases.
101+
*
102+
* @param listener The listener to remove.
103+
*/
94104
public void removeEffectCeasedListener(final EffectCeasedListener listener) {
95105
this.ceasedListeners.remove(listener);
96106
}

litiengine/src/main/java/de/gurkenlabs/litiengine/abilities/effects/EffectEvent.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,49 @@
33
import de.gurkenlabs.litiengine.entities.ICombatEntity;
44
import java.util.EventObject;
55

6+
/**
7+
* Represents an event related to an {@code Effect} being applied to a combat entity. This class provides information about the effect and the entity
8+
* it is applied to.
9+
*/
610
public class EffectEvent extends EventObject {
711
private static final long serialVersionUID = -6911987630602502891L;
12+
13+
/**
14+
* The combat entity associated with this event. This field is transient to avoid serialization issues.
15+
*/
816
private final transient ICombatEntity combatEntity;
17+
18+
/**
19+
* The effect associated with this event. This field is transient to avoid serialization issues.
20+
*/
921
private final transient Effect effect;
1022

23+
/**
24+
* Initializes a new instance of the {@code EffectEvent} class.
25+
*
26+
* @param effect The effect that triggered this event.
27+
* @param combatEntity The combat entity affected by the effect.
28+
*/
1129
EffectEvent(final Effect effect, final ICombatEntity combatEntity) {
1230
super(effect);
1331
this.effect = effect;
1432
this.combatEntity = combatEntity;
1533
}
1634

35+
/**
36+
* Gets the combat entity associated with this event.
37+
*
38+
* @return The {@code ICombatEntity} affected by the effect.
39+
*/
1740
public ICombatEntity getCombatEntity() {
1841
return this.combatEntity;
1942
}
2043

44+
/**
45+
* Gets the effect associated with this event.
46+
*
47+
* @return The {@code Effect} that triggered this event.
48+
*/
2149
public Effect getEffect() {
2250
return this.effect;
2351
}

litiengine/src/main/java/de/gurkenlabs/litiengine/attributes/Attribute.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313
* @param <T> the type of the attribute value, which must be a Number
1414
*/
1515
public class Attribute<T extends Number> implements IAttribute<T>, Serializable {
16-
private static final String VALUE_PROPERTY = "value";
16+
/**
17+
* The support object used to manage and notify property change listeners. It allows other components to listen for changes to the properties of
18+
* this object.
19+
*/
1720
protected final PropertyChangeSupport support;
21+
/**
22+
* The base value of the attribute. This value represents the unmodified state of the attribute before any modifiers are applied.
23+
*/
24+
protected T value;
25+
private static final String VALUE_PROPERTY = "value";
1826
private final transient PropertyChangeListener modifierListener;
1927
private final List<AttributeModifier<T>> modifiers = new ArrayList<>();
20-
protected T value;
28+
2129

2230
/**
2331
* Default no-argument constructor.

litiengine/src/main/java/de/gurkenlabs/litiengine/entities/behavior/AStarGrid.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020
* managing and rendering a grid of A* nodes. It supports diagonal movement and allows updating the walkable state of nodes based on collisions.</p>
2121
*/
2222
public class AStarGrid implements IRenderable {
23+
/**
24+
* The penalty value assigned to nodes that intersect with static, indestructible props.
25+
*/
2326
public static final double PENALTY_STATIC_PROP = 5;
27+
/**
28+
* The penalty value assigned to nodes that have non-walkable neighboring nodes.
29+
*/
2430
public static final double PENALTY_NOT_WALKABLE_NEIGHBOR = 4;
31+
2532
private final AStarNode[][] grid;
2633
private final int nodeSize;
2734
private final Dimension size;

litiengine/src/main/java/de/gurkenlabs/litiengine/entities/behavior/AStarNode.java

Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,52 @@
33
import java.awt.Point;
44
import java.awt.Rectangle;
55

6+
/**
7+
* Represents a node in the A* pathfinding algorithm. Each node contains information about its position, costs, and walkability.
8+
*/
69
public class AStarNode {
7-
// diagonal length: 1 * Math.sqrt(2) ~ 1.4
810
private static final double DIAGONAL_COST = 1.4;
911
private final Rectangle bound;
1012
private final int gridX;
1113
private final int gridY;
1214
private double gCost;
1315
private double hCost;
14-
1516
private double penalty;
1617
private AStarNode predecessor;
1718
private boolean walkable;
1819

20+
/**
21+
* Constructs a new AStarNode with the specified properties.
22+
*
23+
* @param walkable Whether the node is walkable.
24+
* @param bound The rectangular bounds of the node.
25+
* @param gridX The x-coordinate of the node in the grid.
26+
* @param gridY The y-coordinate of the node in the grid.
27+
*/
1928
public AStarNode(
20-
final boolean walkable, final Rectangle bound, final int gridX, final int gridY) {
29+
final boolean walkable, final Rectangle bound, final int gridX, final int gridY) {
2130
this.bound = bound;
2231
this.gridX = gridX;
2332
this.gridY = gridY;
2433
this.walkable = walkable;
2534
}
2635

36+
/**
37+
* Gets the rectangular bounds of this node.
38+
*
39+
* @return The bounds of the node.
40+
*/
2741
public Rectangle getBounds() {
2842
return this.bound;
2943
}
3044

45+
/**
46+
* Calculates the movement cost from this node to the target node.
47+
*
48+
* @param target The target node.
49+
* @return The movement cost to the target node.
50+
*/
3151
public double getCosts(final AStarNode target) {
32-
3352
final int dstX = Math.abs(this.getGridX() - target.getGridX());
3453
final int dstY = Math.abs(this.getGridY() - target.getGridY());
3554

@@ -41,95 +60,157 @@ public double getCosts(final AStarNode target) {
4160
}
4261

4362
/**
44-
* Gets the total costs for this node.
63+
* Gets the total cost (f-cost) for this node. The f-cost is the sum of g-cost and h-cost.
4564
*
46-
* @return The total costs.
65+
* @return The total cost.
4766
*/
4867
public double getFCost() {
4968
return this.getGCost() + this.getHCost();
5069
}
5170

5271
/**
53-
* Gets the costs so far for this node.
72+
* Gets the cost from the start node to this node (g-cost).
5473
*
55-
* @return The costs so far.
74+
* @return The g-cost.
5675
*/
5776
public double getGCost() {
5877
return this.gCost;
5978
}
6079

80+
/**
81+
* Gets the x-coordinate of this node in the grid.
82+
*
83+
* @return The x-coordinate.
84+
*/
6185
public int getGridX() {
6286
return this.gridX;
6387
}
6488

89+
/**
90+
* Gets the y-coordinate of this node in the grid.
91+
*
92+
* @return The y-coordinate.
93+
*/
6594
public int getGridY() {
6695
return this.gridY;
6796
}
6897

6998
/**
70-
* Gets the estimated costs for this node.
99+
* Gets the estimated cost from this node to the target node (h-cost).
71100
*
72-
* @return The estimated costs.
101+
* @return The h-cost.
73102
*/
74103
public double getHCost() {
75104
return this.hCost;
76105
}
77106

107+
/**
108+
* Gets the center location of this node as a Point.
109+
*
110+
* @return The center location of the node.
111+
*/
78112
public Point getLocation() {
79113
return new Point((int) this.getBounds().getCenterX(), (int) this.getBounds().getCenterY());
80114
}
81115

116+
/**
117+
* Gets the penalty cost for this node.
118+
*
119+
* @return The penalty cost.
120+
*/
82121
public double getPenalty() {
83122
return this.penalty;
84123
}
85124

125+
/**
126+
* Gets the predecessor node in the path.
127+
*
128+
* @return The predecessor node.
129+
*/
86130
public AStarNode getPredecessor() {
87131
return this.predecessor;
88132
}
89133

134+
/**
135+
* Checks if this node is walkable.
136+
*
137+
* @return True if the node is walkable, false otherwise.
138+
*/
90139
public boolean isWalkable() {
91140
return this.walkable;
92141
}
93142

143+
/**
144+
* Sets the cost from the start node to this node (g-cost).
145+
*
146+
* @param gCost The g-cost to set.
147+
*/
94148
public void setGCost(final double gCost) {
95149
this.gCost = gCost;
96150
}
97151

152+
/**
153+
* Sets the estimated cost from this node to the target node (h-cost).
154+
*
155+
* @param hCost The h-cost to set.
156+
*/
98157
public void setHCost(final double hCost) {
99158
this.hCost = hCost;
100159
}
101160

161+
/**
162+
* Sets the penalty cost for this node.
163+
*
164+
* @param penalty The penalty cost to set.
165+
*/
102166
public void setPenalty(final double penalty) {
103167
this.penalty = penalty;
104168
}
105169

170+
/**
171+
* Sets the predecessor node in the path.
172+
*
173+
* @param predecessor The predecessor node to set.
174+
*/
106175
public void setPredecessor(final AStarNode predecessor) {
107176
this.predecessor = predecessor;
108177
}
109178

179+
/**
180+
* Sets whether this node is walkable.
181+
*
182+
* @param walkable True if the node is walkable, false otherwise.
183+
*/
110184
public void setWalkable(final boolean walkable) {
111185
this.walkable = walkable;
112186
}
113187

114-
/** Clears the assigned costs and the predecessor. */
188+
/**
189+
* Clears the assigned costs and the predecessor for this node.
190+
*/
115191
public void clear() {
116192
this.setGCost(0);
117193
this.setHCost(0);
118194
this.setPredecessor(null);
119195
}
120196

197+
/**
198+
* Returns a string representation of this node, including its grid position and costs.
199+
*
200+
* @return A string representation of the node.
201+
*/
121202
@Override
122203
public String toString() {
123204
return "["
124-
+ this.getGridX()
125-
+ ","
126-
+ this.getGridY()
127-
+ "] - (f:"
128-
+ this.getFCost()
129-
+ ", g:"
130-
+ this.getGCost()
131-
+ ", h:"
132-
+ this.getHCost()
133-
+ ")";
205+
+ this.getGridX()
206+
+ ","
207+
+ this.getGridY()
208+
+ "] - (f:"
209+
+ this.getFCost()
210+
+ ", g:"
211+
+ this.getGCost()
212+
+ ", h:"
213+
+ this.getHCost()
214+
+ ")";
134215
}
135216
}

0 commit comments

Comments
 (0)