-
Notifications
You must be signed in to change notification settings - Fork 1
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
winspeednl
committed
Oct 21, 2016
1 parent
1783f1d
commit 37e4e62
Showing
10 changed files
with
170 additions
and
70 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.winspeednl.libz.actions; | ||
|
||
public abstract class Action { | ||
public boolean isStarted, isFinished, isBlocking; | ||
public long startTime, elapsed, duration; | ||
public ActionContainer owner; | ||
|
||
public abstract void onStart(); | ||
public abstract void onEnd(); | ||
public abstract void update(); | ||
|
||
public void finish() { | ||
isFinished = true; | ||
isBlocking = false; | ||
} | ||
} |
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,76 @@ | ||
package me.winspeednl.libz.actions; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ActionContainer { | ||
|
||
private ArrayList<Action> actions = new ArrayList<Action>(); | ||
private boolean isRunning; | ||
|
||
public void update() { | ||
if (isRunning) { | ||
ArrayList<Action> completedActions = null; | ||
|
||
for (Action action : actions) { | ||
if (action.isStarted) action.update(); | ||
else { | ||
action.onStart(); | ||
action.isStarted = true; | ||
} | ||
if (action.isBlocking) break; | ||
if (action.isFinished) { | ||
action.onEnd(); | ||
if (completedActions == null) completedActions = new ArrayList<Action>(); | ||
completedActions.add(action); | ||
} | ||
} | ||
if (completedActions != null) for (Action action : completedActions) actions.remove(action); | ||
} | ||
} | ||
|
||
public void start() { | ||
isRunning = true; | ||
} | ||
|
||
public void stop() { | ||
isRunning = false; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return actions.isEmpty(); | ||
} | ||
|
||
public void pushFront(Action action) { | ||
if (actions.contains(action)) { | ||
int id = actions.indexOf(action); | ||
if (id + 1 < actions.size()) { | ||
actions.remove(action); | ||
actions.add(id + 1, action); | ||
} | ||
} | ||
} | ||
|
||
public void pushBack(Action action) { | ||
if (actions.contains(action)) { | ||
int id = actions.indexOf(action); | ||
if (id - 1 > 0) { | ||
actions.remove(action); | ||
actions.add(id - 1, action); | ||
} | ||
} | ||
} | ||
|
||
public void insertAfter(Action action, Action newAction) { | ||
int id = actions.indexOf(action); | ||
actions.add(id + 1, newAction); | ||
} | ||
|
||
public void insertBehind(Action action, Action newAction) { | ||
int id = actions.indexOf(action); | ||
actions.add(id - 1, newAction); | ||
} | ||
|
||
public void add(Action action) { | ||
actions.add(action); | ||
} | ||
} |
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
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
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
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