-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3caca12
commit e7e0cd7
Showing
5 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/me/retrodaredevil/action/SupplementaryAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.retrodaredevil.action; | ||
|
||
class SupplementaryAction implements Action { | ||
private final Action mainAction, supplementaryAction; | ||
public SupplementaryAction(Action mainAction, Action supplementaryAction) { | ||
this.mainAction = mainAction; | ||
this.supplementaryAction = supplementaryAction; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
mainAction.update(); | ||
supplementaryAction.update(); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
mainAction.end(); | ||
supplementaryAction.end(); | ||
} | ||
|
||
@Override | ||
public boolean isDone() { | ||
return mainAction.isDone(); | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return mainAction.isActive(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/me/retrodaredevil/action/SupplementaryLinkedAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package me.retrodaredevil.action; | ||
|
||
public class SupplementaryLinkedAction implements LinkedAction { | ||
|
||
private final LinkedAction linkedAction; | ||
private final Action supplementaryAction; | ||
|
||
public SupplementaryLinkedAction(LinkedAction linkedAction, Action supplementaryAction) { | ||
this.linkedAction = linkedAction; | ||
this.supplementaryAction = supplementaryAction; | ||
} | ||
|
||
@Override | ||
public Action getNextAction() { | ||
return linkedAction.getNextAction(); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
linkedAction.update(); | ||
supplementaryAction.update(); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
linkedAction.end(); | ||
supplementaryAction.end(); | ||
} | ||
|
||
@Override | ||
public boolean isDone() { | ||
return linkedAction.isDone(); | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return linkedAction.isActive(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/me/retrodaredevil/action/test/SupplementaryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package me.retrodaredevil.action.test; | ||
|
||
import me.retrodaredevil.action.Action; | ||
import me.retrodaredevil.action.Actions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
final class SupplementaryTest { | ||
@Test | ||
void testSupplementaryAction(){ | ||
final int[] timesRan = {0}; | ||
final int[] timesRanSupplementary = {0}; | ||
final Action mainAction = Actions.createRunForever(() -> timesRan[0]++); | ||
final Action supplementaryAction = Actions.createRunOnce(() -> timesRanSupplementary[0]++); | ||
final Action action = Actions.createSupplementaryAction(mainAction, supplementaryAction); | ||
|
||
assertFalse(action.isActive()); | ||
assertFalse(mainAction.isActive()); | ||
assertFalse(supplementaryAction.isActive()); | ||
|
||
action.update(); | ||
assertTrue(action.isActive()); | ||
assertTrue(mainAction.isActive()); | ||
assertTrue(supplementaryAction.isActive()); | ||
assertFalse(action.isDone()); | ||
assertFalse(mainAction.isDone()); | ||
assertTrue(supplementaryAction.isDone()); | ||
|
||
action.update(); | ||
assertEquals(2, timesRan[0]); | ||
assertEquals(1, timesRanSupplementary[0]); | ||
|
||
action.end(); | ||
assertFalse(action.isActive()); | ||
assertFalse(mainAction.isActive()); | ||
assertFalse(supplementaryAction.isActive()); | ||
|
||
} | ||
} |