summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/RunningActionHandler.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/RunningActionHandler.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/RunningActionHandler.java')
-rw-r--r--NET/worlds/scape/RunningActionHandler.java153
1 files changed, 153 insertions, 0 deletions
diff --git a/NET/worlds/scape/RunningActionHandler.java b/NET/worlds/scape/RunningActionHandler.java
new file mode 100644
index 0000000..a821458
--- /dev/null
+++ b/NET/worlds/scape/RunningActionHandler.java
@@ -0,0 +1,153 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Vector;
+
+public class RunningActionHandler extends SuperRoot implements FrameHandler, NonPersister {
+ private Action action;
+ private Persister seqID;
+ private RunningActionCallback callback;
+ private Object callbackCookie;
+ private static Object classCookie = new Object();
+
+ public static void trigger(Action act, World w, Event event) {
+ trigger(act, w, event, null, null);
+ }
+
+ public static void trigger(Action act, World w, Event event, RunningActionCallback callb, Object o) {
+ if (act.isActive()) {
+ Persister seqID = null;
+ if ((seqID = act.trigger(event, seqID)) != null) {
+ new RunningActionHandler(w, act, seqID, callb, o);
+ }
+ }
+ }
+
+ public static void trigger(Vector v, World w, Event event) {
+ trigger(v, w, event, null, null);
+ }
+
+ public static void trigger(Vector v, World w, Event event, RunningActionCallback callb, Object o) {
+ Vector acts = (Vector)v.clone();
+ int sz = acts.size();
+
+ for (int i = 0; i < sz; i++) {
+ Action act = (Action)acts.elementAt(i);
+ if (v.contains(act)) {
+ trigger(act, w, event, callb, o);
+ }
+ }
+ }
+
+ RunningActionHandler() {
+ }
+
+ private RunningActionHandler(World world, Action a, Persister seqID, RunningActionCallback callb, Object o) {
+ this.action = a;
+ this.seqID = seqID;
+ this.callback = callb;
+ this.callbackCookie = o;
+ world.addHandler(this);
+ }
+
+ @Override
+ public boolean handle(FrameEvent e) {
+ if (!this.action.isActive() || (this.seqID = this.action.trigger(e, this.seqID)) == null) {
+ if (this.callback != null) {
+ this.callback.actionDone(this.action, e, this.callbackCookie);
+ }
+
+ this.getWorld().removeHandler(this);
+ }
+
+ return true;
+ }
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = new Property(this, index, "Action");
+ } else if (mode == 1) {
+ ret = this.action;
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ ret = new Property(this, index, "Sequence ID Object");
+ } else if (mode == 1) {
+ ret = this.seqID;
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 2, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ Console.println(Console.message("Save-running"));
+ s.saveVersion(3, classCookie);
+ super.saveState(s);
+ s.save(this.action);
+ s.saveMaybeNull(this.seqID);
+ s.saveMaybeNull((Persister)this.callback);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ switch (r.restoreVersion(classCookie)) {
+ case 0:
+ super.restoreState(r);
+ r.restore();
+ this.action = (Action)r.restoreMaybeNull();
+ this.callback = null;
+ break;
+ case 1:
+ super.restoreState(r);
+ this.action = (Action)r.restore();
+ this.callback = null;
+ break;
+ case 2:
+ super.restoreState(r);
+ this.action = (Action)r.restore();
+ this.seqID = r.restoreMaybeNull();
+ this.callback = null;
+ break;
+ case 3:
+ super.restoreState(r);
+ this.action = (Action)r.restore();
+ this.seqID = r.restoreMaybeNull();
+ this.callback = (RunningActionCallback)r.restoreMaybeNull();
+ break;
+ default:
+ throw new TooNewException();
+ }
+ }
+
+ @Override
+ public void postRestore(int version) {
+ super.postRestore(version);
+ Object[] arguments = new Object[]{new String(this.getName())};
+ Console.println(MessageFormat.format(Console.message("Discarding-old"), arguments));
+ SuperRoot owner = this.getOwner();
+ if (owner instanceof WObject) {
+ ((WObject)owner).removeHandler(this);
+ } else if (owner instanceof World) {
+ ((World)owner).removeHandler(this);
+ } else {
+ Console.println(MessageFormat.format(Console.message("Unable-discard"), arguments));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + ":" + this.action.getName() + "[" + this.seqID + "]";
+ }
+}