diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/SameRoomSensor.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/SameRoomSensor.java')
| -rw-r--r-- | NET/worlds/scape/SameRoomSensor.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/NET/worlds/scape/SameRoomSensor.java b/NET/worlds/scape/SameRoomSensor.java new file mode 100644 index 0000000..268573c --- /dev/null +++ b/NET/worlds/scape/SameRoomSensor.java @@ -0,0 +1,60 @@ +package NET.worlds.scape; + +import java.io.IOException; + +public class SameRoomSensor extends Sensor implements FrameHandler { + private Room lastCamRoom; + private static Object classCookie = new Object(); + + public SameRoomSensor(Action a) { + if (a != null) { + this.addAction(a); + } + } + + public SameRoomSensor() { + } + + @Override + public void detach() { + this.lastCamRoom = null; + super.detach(); + } + + @Override + public boolean handle(FrameEvent e) { + Object owner = this.getOwner(); + if (owner != null && owner instanceof WObject) { + WObject o = (WObject)owner; + Room thisRoom = o.getRoom(); + Room thisCamRoom = Pilot.getActiveRoom(); + if (thisCamRoom == thisRoom && this.lastCamRoom != thisCamRoom) { + this.trigger(e); + } + + this.lastCamRoom = thisCamRoom; + return true; + } else { + return true; + } + } + + @Override + public void saveState(Saver s) throws IOException { + super.saveState(s); + s.saveVersion(0, classCookie); + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + int vers = super.restoreStateVers(r); + if (vers > 1) { + switch (r.restoreVersion(classCookie)) { + case 0: + return; + default: + throw new TooNewException(); + } + } + } +} |