summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Sensor.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/Sensor.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/Sensor.java')
-rw-r--r--NET/worlds/scape/Sensor.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/NET/worlds/scape/Sensor.java b/NET/worlds/scape/Sensor.java
new file mode 100644
index 0000000..8fb989d
--- /dev/null
+++ b/NET/worlds/scape/Sensor.java
@@ -0,0 +1,99 @@
+package NET.worlds.scape;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class Sensor extends SuperRoot {
+ protected Vector<Action> actions = new Vector<Action>();
+ private static Object classCookie = new Object();
+
+ public void addAction(Action o) {
+ this.actions.addElement(o);
+ }
+
+ public void deleteAction(Action o) {
+ this.actions.removeElement(o);
+ }
+
+ public void deleteActions() {
+ while (this.actions.size() > 0) {
+ this.deleteAction(this.actions.elementAt(0));
+ }
+ }
+
+ public Enumeration<Action> getActions() {
+ return this.actions.elements();
+ }
+
+ public int countActions() {
+ return this.actions.size();
+ }
+
+ public void trigger(Event event) {
+ RunningActionHandler.trigger(this.actions, this.getWorld(), event);
+ }
+
+ @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 = ObjectPropertyAdder.make(new VectorProperty(this, index, "Targets"), this.getRoot(), "NET.worlds.scape.Action");
+ } else if (mode == 1) {
+ ret = this.actions.clone();
+ } else if (mode == 4) {
+ this.deleteAction((Action)value);
+ } else if (mode == 3) {
+ this.addAction((Action)value);
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 1, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(2, classCookie);
+ super.saveState(s);
+ s.saveVector(this.actions);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ this.restoreStateVers(r);
+ }
+
+ protected int restoreStateVers(Restorer r) throws IOException, TooNewException {
+ int vers = r.restoreVersion(classCookie);
+ switch (vers) {
+ case 1:
+ case 2:
+ super.restoreState(r);
+ case 0:
+ this.actions = r.restoreVectorActions();
+ return vers;
+ default:
+ throw new TooNewException();
+ }
+ }
+
+ @Override
+ public void postRestore(int version) {
+ super.postRestore(version);
+ Enumeration<Action> en = this.getActions();
+
+ while (en.hasMoreElements()) {
+ Action a = en.nextElement();
+ if (this.getOwner() != null && a.getOwner() == null) {
+ System.out.println("Reparenting orphan action " + a.getName());
+ WObject w = (WObject)this.getOwner();
+ w.addAction(a);
+ }
+ }
+ }
+}