Skip to content

Commit c77be11

Browse files
committed
(#99) Add calls to reset behaviors
Additions: - `BehaviorManager.destroyListenerList` for destroying the behaviors of any `BehaviorHandler`'s behavior listener list. - `BehaviorHandler.destroyBehaviorListeners` for calling the `BehaviorManager`'s behavior destroying method. Bug Fixes: - (#99) Added behavior destroy calls to both `SimpleManager` and `Scene` classes' `reset` methods.
1 parent f7d932d commit c77be11

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/main/java/tech/fastj/systems/behaviors/BehaviorHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ default void updateBehaviorListeners() {
5252
BehaviorManager.updateBehaviorListeners(this);
5353
}
5454

55+
/** Destroys all behaviors in the behavior handler, without removing them. */
56+
default void destroyBehaviorListeners() {
57+
BehaviorManager.destroyListenerList(this);
58+
}
59+
5560
/** Removes all behavior listeners in the behavior handler. */
5661
default void clearBehaviorListeners() {
5762
BehaviorManager.clearListenerList(this);

src/main/java/tech/fastj/systems/behaviors/BehaviorManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public static void removeListenerList(BehaviorHandler behaviorHandler) {
7575
BehaviorListenerLists.remove(behaviorHandler);
7676
}
7777

78+
/**
79+
* Destroys all behaviors from the list aliased to the specified {@link BehaviorHandler}, without removing them.
80+
*
81+
* @param behaviorHandler The {@code BehaviorHandler} used as the alias to destroy all behavior listeners.
82+
*/
83+
public static void destroyListenerList(BehaviorHandler behaviorHandler) {
84+
for (GameObject listener : BehaviorListenerLists.get(behaviorHandler).values()) {
85+
listener.destroyAllBehaviors();
86+
}
87+
}
88+
7889
/**
7990
* Removes all elements from the list aliased to the specified {@link BehaviorHandler}.
8091
*

src/main/java/tech/fastj/systems/control/Scene.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void clearAllLists() {
122122
/** Resets the scene's state entirely. */
123123
public void reset() {
124124
this.setInitialized(false);
125+
this.destroyBehaviorListeners();
125126
this.clearAllLists();
126127
camera.reset();
127128
}

src/main/java/tech/fastj/systems/control/SimpleManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public Camera getCamera() {
8787
@Override
8888
public void reset() {
8989
camera.reset();
90+
this.destroyBehaviorListeners();
9091
inputManager.clearAllLists();
9192
drawableManager.clearAllLists();
9293
this.clearTaggableEntities();

0 commit comments

Comments
 (0)