summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/AnimatedActionManager.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/AnimatedActionManager.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/AnimatedActionManager.java')
-rw-r--r--NET/worlds/scape/AnimatedActionManager.java329
1 files changed, 329 insertions, 0 deletions
diff --git a/NET/worlds/scape/AnimatedActionManager.java b/NET/worlds/scape/AnimatedActionManager.java
new file mode 100644
index 0000000..5ab97a9
--- /dev/null
+++ b/NET/worlds/scape/AnimatedActionManager.java
@@ -0,0 +1,329 @@
+package NET.worlds.scape;
+
+import NET.worlds.core.IniFile;
+import NET.worlds.network.NetUpdate;
+import NET.worlds.network.URL;
+import java.awt.Menu;
+import java.awt.MenuItem;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class AnimatedActionManager implements ActionListener, BGLoaded {
+ private AnimatedAction _currentAction = null;
+ static final String actionFile = "actions/actions.dat";
+ static final String localActionFile = "actions.dat";
+ static final String version = "VERSION";
+ static final String action = "ACTION";
+ private Vector actionList;
+ private Vector currentMenuActions;
+ private static AnimatedActionManager theAnimatedActionManager = null;
+
+ public static AnimatedActionManager get() {
+ if (theAnimatedActionManager == null) {
+ theAnimatedActionManager = new AnimatedActionManager();
+ }
+
+ return theAnimatedActionManager;
+ }
+
+ private Vector getActionList(URL avatar, URL object) {
+ if (this.actionList != null && avatar != null && object != null) {
+ String av = PosableShape.getBodyType(avatar);
+ if (av == null) {
+ return null;
+ } else {
+ String ob = object.toString();
+ int dot = ob.lastIndexOf(".");
+ if (dot != -1) {
+ ob = ob.substring(0, dot);
+ }
+
+ Vector ret = new Vector();
+ Enumeration e = this.actionList.elements();
+
+ while (e.hasMoreElements()) {
+ AnimatedAction a = (AnimatedAction)e.nextElement();
+ if (this.vectorCheck(av, a.avatarNames) && this.vectorCheck(ob, a.targetObjects)) {
+ ret.addElement(a);
+ }
+ }
+
+ return ret;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ private boolean vectorCheck(String s, Vector v) {
+ Enumeration e = v.elements();
+
+ while (e.hasMoreElements()) {
+ String element = (String)e.nextElement();
+ if (s.toLowerCase().endsWith(element.toLowerCase())) {
+ return true;
+ }
+
+ if (element.equals("any")) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean buildActionMenu(Menu m, Shape target) {
+ assert m != null;
+
+ if (this._currentAction != null) {
+ return false;
+ } else {
+ SuperRoot ultimateOwner = target;
+
+ while (ultimateOwner.getOwner() != null) {
+ ultimateOwner = ultimateOwner.getOwner();
+ if (ultimateOwner instanceof PosableShape) {
+ target = (Shape)ultimateOwner;
+ break;
+ }
+ }
+
+ Pilot p = Pilot.getActive();
+ if (p == null) {
+ return false;
+ } else if (!(p instanceof HoloPilot)) {
+ return false;
+ } else {
+ HoloPilot hp = (HoloPilot)p;
+ if (hp.getInternalDrone().getRoom() != target.getRoom()) {
+ return false;
+ } else {
+ Vector v = this.getActionList(hp.getInternalDrone().getCurrentURL(), target.getURL());
+ this.currentMenuActions = v;
+ if (v == null) {
+ return false;
+ } else if (v.size() == 0) {
+ return false;
+ } else {
+ Enumeration e = v.elements();
+
+ while (e.hasMoreElements()) {
+ AnimatedAction a = (AnimatedAction)e.nextElement();
+ a.setTargetShape(target);
+ int idx = a.actionName.indexOf("\\");
+ if (idx != -1) {
+ String action = a.actionName.substring(idx + 1);
+ String submenu = a.actionName.substring(0, idx);
+ int items = m.getItemCount();
+ boolean inserted = false;
+
+ for (int i = 0; i < items; i++) {
+ MenuItem item = m.getItem(i);
+ if (item.getLabel().equals(submenu) && item instanceof Menu) {
+ ((Menu)item).add(action);
+ inserted = true;
+ break;
+ }
+ }
+
+ if (!inserted) {
+ Menu sm = new Menu(submenu);
+ sm.addActionListener(this);
+ sm.add(action);
+ m.add(sm);
+ }
+ } else {
+ m.add(a.actionName);
+ }
+ }
+
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ public boolean processMenuClick(String actionName) {
+ if (this.currentMenuActions == null) {
+ return false;
+ } else {
+ Enumeration e = this.currentMenuActions.elements();
+
+ while (e.hasMoreElements()) {
+ AnimatedAction a = (AnimatedAction)e.nextElement();
+ String thisAction = a.actionName;
+ int idx = thisAction.indexOf(92);
+ if (idx != -1) {
+ thisAction = thisAction.substring(idx + 1);
+ }
+
+ if (thisAction.equals(actionName)) {
+ Pilot p = Pilot.getActive();
+ if (p == null) {
+ return false;
+ }
+
+ if (!(p instanceof HoloPilot)) {
+ return false;
+ }
+
+ HoloPilot hp = (HoloPilot)p;
+ if (this._currentAction != null) {
+ this._currentAction.abort();
+ }
+
+ this._currentAction = a;
+ a.execute(hp);
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ public void actionCompleted(AnimatedAction a) {
+ assert a == this._currentAction;
+
+ this._currentAction = null;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ this.processMenuClick(e.getActionCommand());
+ }
+
+ private AnimatedActionManager() {
+ System.out.println("Loading action manager");
+ this.actionList = new Vector();
+ this.loadActionsFile();
+ }
+
+ private void loadActionsFile() {
+ File f = new File("actions.dat");
+ if (f.exists()) {
+ this.parseActionFile("actions.dat");
+ }
+
+ String serv = NetUpdate.getUpgradeServerURL();
+ String s = IniFile.override().getIniString("actionFile", "actions/actions.dat");
+ BackgroundLoader.get(this, URL.make(serv + s));
+ }
+
+ @Override
+ public synchronized Object asyncBackgroundLoad(String localName, URL remoteURL) {
+ return localName;
+ }
+
+ @Override
+ public boolean syncBackgroundLoad(Object obj, URL remoteURL) {
+ System.out.println("Got actions file ");
+ String localName = (String)obj;
+ if (localName != null && new File(localName).exists()) {
+ this.parseActionFile(localName);
+ }
+
+ return false;
+ }
+
+ @Override
+ public Room getBackgroundLoadRoom() {
+ return null;
+ }
+
+ private String getLine(RandomAccessFile fIn) throws IOException {
+ while (fIn.getFilePointer() < fIn.length()) {
+ String line = fIn.readLine().trim();
+ if (line == null) {
+ return null;
+ }
+
+ if (!line.startsWith("//") && line.length() != 0) {
+ return line;
+ }
+ }
+
+ return null;
+ }
+
+ private void parseActionFile(String fileName) {
+ int verNum = 0;
+
+ assert this.actionList != null;
+
+ this.actionList.removeAllElements();
+
+ try {
+ RandomAccessFile fIn = new RandomAccessFile(fileName, "r");
+
+ String line;
+ while ((line = this.getLine(fIn)) != null) {
+ StringTokenizer tok = new StringTokenizer(line);
+ String firstWord = tok.nextToken();
+ if (firstWord.equals("VERSION")) {
+ String ver = tok.nextToken();
+ if (ver.equals("1")) {
+ verNum = 1;
+ } else {
+ if (!ver.equals("2")) {
+ throw new Exception("Bad version.");
+ }
+
+ verNum = 2;
+ }
+ } else if (firstWord.equals("ACTION")) {
+ if (verNum == 0) {
+ throw new Exception("Actions file version not specified.");
+ }
+
+ AnimatedAction a = new AnimatedAction();
+ a.actionName = line.substring("ACTION".length() + 1);
+ this.readVector(fIn, a.avatarNames);
+ this.readVector(fIn, a.targetObjects);
+ if (verNum > 1) {
+ a.consentRequired = this.getLine(fIn).toLowerCase().equals("consent");
+ }
+
+ StringTokenizer tok2 = new StringTokenizer(this.getLine(fIn));
+ Float x = new Float(tok2.nextToken());
+ Float y = new Float(tok2.nextToken());
+ a.targetRelPosition = new Point2(x, y);
+ Float yaw = new Float(this.getLine(fIn));
+ a.targetRelYaw = yaw.floatValue();
+ a.preAnimationAction = AnimatedAction.getAction(this.getLine(fIn));
+ a.preAnimationParameter = this.getLine(fIn);
+ a.actionName1 = this.getLine(fIn);
+ if (verNum > 1) {
+ a.simultaneousAction = AnimatedAction.getAction(this.getLine(fIn));
+ a.simultaneousParameter = this.getLine(fIn);
+ }
+
+ a.postAnimationAction = AnimatedAction.getAction(this.getLine(fIn));
+ a.postAnimationParameter = this.getLine(fIn);
+ a.actionName2 = this.getLine(fIn);
+ this.actionList.addElement(a);
+ }
+ }
+
+ fIn.close();
+ } catch (Exception var12) {
+ System.out.println("Error reading actions.dat: " + var12.toString());
+ }
+ }
+
+ private void readVector(RandomAccessFile fIn, Vector v) throws IOException {
+ String line = this.getLine(fIn);
+ StringTokenizer tok = new StringTokenizer(line);
+
+ while (tok.hasMoreTokens()) {
+ v.addElement(tok.nextToken());
+ }
+ }
+}