summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Animation.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/Animation.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/Animation.java')
-rw-r--r--NET/worlds/scape/Animation.java285
1 files changed, 285 insertions, 0 deletions
diff --git a/NET/worlds/scape/Animation.java b/NET/worlds/scape/Animation.java
new file mode 100644
index 0000000..1f27085
--- /dev/null
+++ b/NET/worlds/scape/Animation.java
@@ -0,0 +1,285 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.network.URL;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.text.MessageFormat;
+import java.util.Date;
+
+class Animation extends TriggeredSwitchableBehavior implements FrameHandler, Persister, MouseDownHandler, BumpHandler {
+ long startFrameTime;
+ protected float cycleTime;
+ protected String frameList;
+ protected int cycles;
+ protected int cycleNo = 0;
+ protected String[] frameListArray;
+ protected Material[] frameMaterialArray;
+ protected int frameListCount;
+ protected int currentFrameNo;
+ protected boolean animationEnd = true;
+
+ public Animation() {
+ this.cycleTime = 1000.0F;
+ this.frameList = new String("");
+ this.trigger = new String("none");
+ this.externalTriggerTag = new String("");
+ this.cycles = 0;
+ this.frameListArray = new String[200];
+ this.frameMaterialArray = new Material[200];
+ this.frameListCount = 0;
+ this.startAnimation();
+ }
+
+ @Override
+ public void ExternalTrigger(Trigger trigger_source, int sequence_no, int event_no) {
+ this.trigger_source = trigger_source;
+ this.sequence_no = sequence_no;
+ this.event_no = event_no;
+ this.startAnimation();
+ }
+
+ public void startAnimation() {
+ Date timer = new Date();
+ this.startFrameTime = timer.getTime();
+ this.cycleNo = 0;
+ this.currentFrameNo = 0;
+ this.animationEnd = false;
+ }
+
+ public float getCycleTime() {
+ return this.cycleTime;
+ }
+
+ public void setCycleTime(float t) {
+ this.cycleTime = t;
+ }
+
+ public int getNextFrameNo() {
+ Date timer = new Date();
+ int nextFrameNo = 0;
+ if (this.frameListCount > 0) {
+ nextFrameNo = (int)(this.frameListCount * ((float)(timer.getTime() - this.startFrameTime) % this.cycleTime) / (this.cycleTime + 1.0F) + 1.0F);
+ if (this.currentFrameNo > nextFrameNo) {
+ this.cycleNo++;
+ }
+ }
+
+ return nextFrameNo;
+ }
+
+ public void preprocessFrameList(String frameList) {
+ int currentIndex = 1;
+ int currentSeparator = 0;
+ int nextSeparator = 0;
+ int lastSeparator = frameList.lastIndexOf(" ");
+ if (lastSeparator != -1 || frameList.length() != 0) {
+ if (lastSeparator == -1) {
+ this.frameListArray[currentIndex] = frameList;
+ } else {
+ nextSeparator = frameList.indexOf(" ");
+ this.frameListArray[currentIndex] = frameList.substring(0, nextSeparator);
+ currentIndex++;
+
+ while (nextSeparator != lastSeparator) {
+ currentSeparator = nextSeparator;
+ nextSeparator = frameList.indexOf(" ", nextSeparator + 1);
+ this.frameListArray[currentIndex] = frameList.substring(currentSeparator + 1, nextSeparator);
+ currentIndex++;
+ }
+
+ this.frameListArray[currentIndex] = frameList.substring(nextSeparator + 1);
+ this.frameListCount = currentIndex;
+ }
+ }
+
+ for (int var11 = 1; var11 <= this.frameListCount; var11++) {
+ String s = this.frameListArray[var11];
+
+ URL url;
+ try {
+ url = new URL(this, s);
+ } catch (MalformedURLException var9) {
+ url = URL.make("error:\"" + s + '"');
+ }
+
+ this.frameMaterialArray[var11] = new Material(url);
+ }
+ }
+
+ @Override
+ public boolean handle(FrameEvent e) {
+ if (this.enabled && e.receiver instanceof Rect) {
+ int nextFrameNo = this.getNextFrameNo();
+ if (this.cycleNo >= this.cycles && this.cycles != 0) {
+ if (this.currentFrameNo != this.frameListCount) {
+ Rect Wall = (Rect)e.receiver;
+ Wall.setMaterial(this.frameMaterialArray[this.frameListCount]);
+ this.currentFrameNo = this.frameListCount;
+ }
+ } else if (nextFrameNo > 0 && nextFrameNo != this.currentFrameNo) {
+ this.currentFrameNo = nextFrameNo;
+ Rect Wall = (Rect)e.receiver;
+ Wall.setMaterial(this.frameMaterialArray[this.currentFrameNo]);
+ }
+
+ if (this.cycleNo >= this.cycles && this.cycles != 0 && !this.animationEnd) {
+ this.animationEnd = true;
+ if (this.trigger_source != null) {
+ this.trigger_source.registerFinishedTriggerTag(this.sequence_no, this.event_no);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean handle(MouseDownEvent e) {
+ if (this.enabled && this.trigger.equals("click")) {
+ this.startAnimation();
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean handle(BumpEventTemp e) {
+ if (this.enabled && this.trigger.equals("bump")) {
+ this.startAnimation();
+ }
+
+ 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 ClassProperty(this, index, "Animation");
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ ret = FloatPropertyEditor.make(new Property(this, index, "Cycle Time"));
+ } else if (mode == 1) {
+ ret = new Float(this.cycleTime);
+ } else if (mode == 2) {
+ this.cycleTime = (Float)value;
+ }
+ break;
+ case 2:
+ if (mode == 0) {
+ ret = IntegerPropertyEditor.make(new Property(this, index, "Cycles"));
+ } else if (mode == 1) {
+ ret = new Integer(this.cycles);
+ } else if (mode == 2) {
+ this.cycles = (Integer)value;
+ }
+ break;
+ case 3:
+ if (mode == 0) {
+ ret = StringPropertyEditor.make(new Property(this, index, "Trigger"));
+ } else if (mode == 1) {
+ ret = new String(this.trigger);
+ } else if (mode == 2) {
+ this.trigger = ((String)value).toString().trim();
+ if (this.trigger.equals("external")) {
+ Trigger.TriggeredSwitchableBehaviorList[Trigger.TriggeredSwitchableBehaviorListCount] = this;
+ Trigger.TriggeredSwitchableBehaviorListCount++;
+ }
+ }
+ break;
+ case 4:
+ if (mode == 0) {
+ ret = StringPropertyEditor.make(new Property(this, index, "External Trigger Tag"));
+ } else if (mode == 1) {
+ ret = new String(this.externalTriggerTag);
+ } else if (mode == 2) {
+ this.externalTriggerTag = ((String)value).toString().trim();
+ }
+ break;
+ case 5:
+ if (mode == 0) {
+ ret = StringPropertyEditor.make(new Property(this, index, "Frame List"));
+ } else if (mode == 1) {
+ ret = new String(this.frameList);
+ } else if (mode == 2) {
+ this.frameList = ((String)value).toString().trim().toLowerCase();
+ this.preprocessFrameList(this.frameList);
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 6, mode, value);
+ }
+
+ if (mode == 2 && this.trigger.equals("none")) {
+ this.startAnimation();
+ }
+
+ return ret;
+ }
+
+ @Override
+ public String toString() {
+ return "Animation: cycleTime "
+ + this.cycleTime
+ + ", cycles "
+ + this.cycles
+ + ", enabled "
+ + this.enabled
+ + ", trigger "
+ + this.trigger
+ + ", externalTriggerTag "
+ + this.externalTriggerTag
+ + ", frameList "
+ + this.frameList;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveFloat(this.cycleTime);
+ s.saveInt(this.cycles);
+ s.saveString(this.trigger);
+ s.saveString(this.externalTriggerTag);
+ s.saveString(this.frameList);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException {
+ this.cycleTime = r.restoreFloat();
+ this.cycles = r.restoreInt();
+ this.trigger = r.restoreString();
+ if (this.trigger.equals("external")) {
+ Trigger.TriggeredSwitchableBehaviorList[Trigger.TriggeredSwitchableBehaviorListCount] = this;
+ Trigger.TriggeredSwitchableBehaviorListCount++;
+ }
+
+ this.externalTriggerTag = r.restoreString();
+ if (!this.trigger.equals("none")) {
+ this.cycleNo = this.cycles;
+ } else {
+ this.startAnimation();
+ }
+
+ this.frameList = r.restoreString();
+ this.preprocessFrameList(this.frameList);
+ }
+
+ @Override
+ public void postRestore(int version) {
+ String name = this.getName();
+ String arg1 = name == null ? "<null>" : name;
+ SuperRoot owner = this.getOwner();
+ String oname = "";
+ if (owner != null) {
+ oname = owner.getName();
+ }
+
+ String arg2 = oname == null ? "<null>" : oname;
+ Object[] arguments = new Object[]{new String(arg1), new String(arg2)};
+ Console.println(MessageFormat.format(Console.message("Animation-obs"), arguments));
+ }
+}