diff options
Diffstat (limited to 'NET/worlds/scape/SequenceActionState.java')
| -rw-r--r-- | NET/worlds/scape/SequenceActionState.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/NET/worlds/scape/SequenceActionState.java b/NET/worlds/scape/SequenceActionState.java new file mode 100644 index 0000000..b7e17ed --- /dev/null +++ b/NET/worlds/scape/SequenceActionState.java @@ -0,0 +1,91 @@ +package NET.worlds.scape; + +import java.io.IOException; +import java.util.Vector; + +class SequenceActionState implements Persister { + int currentLoop; + boolean loopInfinite; + Vector actions; + Persister seqID; + int currentAct; + private static Object classCookie = new Object(); + + SequenceActionState() { + } + + SequenceActionState(SequenceAction sa) { + this.currentLoop = sa.loopCount; + this.loopInfinite = sa.loopInfinite; + this.actions = (Vector)sa.actions.clone(); + } + + boolean run(Event evt) { + if (this.currentLoop <= 0 && !this.loopInfinite) { + return false; + } else { + while (this.currentAct < this.actions.size()) { + Action act = (Action)this.actions.elementAt(this.currentAct); + if ((this.seqID = act.trigger(evt, this.seqID)) != null) { + return true; + } + + this.currentAct++; + } + + this.currentAct = 0; + if (this.currentLoop > 0) { + this.currentLoop--; + } + + return true; + } + } + + @Override + public String toString() { + String stateString = "Action #" + this.currentAct + " of loop " + this.currentLoop + ", status " + this.seqID; + if (!this.loopInfinite) { + stateString = stateString + " NOT"; + } + + return stateString + " Infinite"; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveVersion(1, classCookie); + s.saveBoolean(this.loopInfinite); + s.saveInt(this.currentLoop); + s.saveInt(this.currentAct); + s.saveVector(this.actions); + s.saveMaybeNull(this.seqID); + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + switch (r.restoreVersion(classCookie)) { + case 0: + this.currentLoop = r.restoreInt(); + this.loopInfinite = this.currentLoop < 0; + this.currentLoop = Math.abs(this.currentLoop); + this.currentAct = r.restoreInt(); + this.actions = r.restoreVector(); + this.seqID = r.restoreMaybeNull(); + break; + case 1: + this.loopInfinite = r.restoreBoolean(); + this.currentLoop = r.restoreInt(); + this.currentAct = r.restoreInt(); + this.actions = r.restoreVector(); + this.seqID = r.restoreMaybeNull(); + break; + default: + throw new TooNewException(); + } + } + + @Override + public void postRestore(int version) { + } +} |