summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WorldScriptToolkitImp.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/WorldScriptToolkitImp.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/WorldScriptToolkitImp.java')
-rw-r--r--NET/worlds/scape/WorldScriptToolkitImp.java429
1 files changed, 429 insertions, 0 deletions
diff --git a/NET/worlds/scape/WorldScriptToolkitImp.java b/NET/worlds/scape/WorldScriptToolkitImp.java
new file mode 100644
index 0000000..180f0ea
--- /dev/null
+++ b/NET/worlds/scape/WorldScriptToolkitImp.java
@@ -0,0 +1,429 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.console.DefaultConsole;
+import NET.worlds.console.NoWebControlException;
+import NET.worlds.console.OkCancelDialog;
+import NET.worlds.console.WebControl;
+import NET.worlds.console.WebControlImp;
+import NET.worlds.core.IniFile;
+import NET.worlds.core.Std;
+import NET.worlds.network.CacheEntry;
+import NET.worlds.network.Galaxy;
+import NET.worlds.network.URL;
+
+class WorldScriptToolkitImp extends WorldScriptToolkit {
+ @Override
+ public int getTime() {
+ return Std.getSynchronizedTime();
+ }
+
+ @Override
+ public void teleport(String destination, boolean showDlg) {
+ TeleportAction.teleport(destination, null, false, showDlg);
+ }
+
+ @Override
+ public float getPilotX() {
+ Pilot p = Pilot.getActive();
+ return p != null ? p.getX() : 0.0F;
+ }
+
+ @Override
+ public float getPilotY() {
+ Pilot p = Pilot.getActive();
+ return p != null ? p.getY() : 0.0F;
+ }
+
+ @Override
+ public float getPilotYaw() {
+ Pilot p = Pilot.getActive();
+ return p != null ? 360.0F - p.getYaw() : 0.0F;
+ }
+
+ private SmoothDriver getSmoothDriver() {
+ Pilot p = Pilot.getActive();
+ if (p != null && p instanceof HoloPilot) {
+ HoloPilot hp = (HoloPilot)p;
+ return hp.getSmoothDriver();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public float getWalkFriction() {
+ SmoothDriver sd = this.getSmoothDriver();
+ return sd != null ? sd.getVelocityDamping() : 0.0F;
+ }
+
+ @Override
+ public void setWalkFriction(float friction) {
+ SmoothDriver sd = this.getSmoothDriver();
+ if (sd != null) {
+ sd.setVelocityDamping(friction);
+ }
+ }
+
+ @Override
+ public void walkTo(float x, float y, float yaw, float velocity) {
+ Pilot p = Pilot.getActive();
+ if (p != null && p instanceof HoloPilot) {
+ HoloPilot hp = (HoloPilot)p;
+ hp.walkTo(new Point2(x, y), yaw, velocity);
+ }
+ }
+
+ @Override
+ public void walkTo(float x, float y, float yaw) {
+ Pilot p = Pilot.getActive();
+ if (p != null && p instanceof HoloPilot) {
+ HoloPilot hp = (HoloPilot)p;
+ hp.walkTo(new Point2(x, y), yaw);
+ }
+ }
+
+ @Override
+ public void walkTo(WorldScript script, float x, float y, float yaw, float velocity) {
+ Pilot p = Pilot.getActive();
+ if (p != null && p instanceof HoloPilot) {
+ HoloPilot hp = (HoloPilot)p;
+ hp.walkTo(new Point2(x, y), yaw, velocity);
+ hp.addCallback(script);
+ }
+ }
+
+ @Override
+ public void showWebPage(String url) {
+ this.showWebPage(url, 100, 100);
+ }
+
+ @Override
+ public void showWebPage(String url, int percentW, int percentH) {
+ Console c = Console.getActive();
+ if (c != null && c instanceof DefaultConsole) {
+ DefaultConsole dc = (DefaultConsole)c;
+
+ try {
+ WebControl wc = new WebControl(dc.getRender(), percentW, percentH, true, false, false);
+ wc.activate();
+ wc.setURL(url);
+ } catch (NoWebControlException var7) {
+ new SendURLAction(url).doIt();
+ }
+ }
+ }
+
+ @Override
+ public void showExternalWebPage(String url) {
+ new SendURLAction(url).doIt();
+ }
+
+ @Override
+ public void showAdBanner(String url, int width, int height) {
+ Pilot p = Pilot.getActive();
+ if (p != null) {
+ World w = p.getWorld();
+ if (w != null) {
+ w.setHasAdBanner(true);
+ w.setBannerURL(url);
+ w.setBannerWidth(width);
+ w.setBannerHeight(height);
+ w.setupAdBanner();
+ }
+ }
+ }
+
+ @Override
+ public Object playSound(String soundFile, int loop) {
+ Sound owner = new Sound(URL.make(soundFile));
+ SoundPlayer autoSound = null;
+ if (soundFile.toLowerCase().endsWith(".wav")) {
+ autoSound = new WavSoundPlayer(owner);
+ } else {
+ autoSound = new WMPSoundPlayer(owner);
+ }
+
+ autoSound.start(loop);
+ return autoSound;
+ }
+
+ @Override
+ public boolean serviceSound(Object soundPlayer) {
+ if (!(soundPlayer instanceof SoundPlayer)) {
+ System.out.println("Error - invalid handle passed to serviceSound");
+ return false;
+ } else {
+ SoundPlayer sp = (SoundPlayer)soundPlayer;
+ return sp.getState() == 0;
+ }
+ }
+
+ @Override
+ public void stopSound(Object soundPlayer) {
+ if (!(soundPlayer instanceof SoundPlayer)) {
+ System.out.println("Error - invalid handle passed to stopSound");
+ } else {
+ SoundPlayer autoSound = (SoundPlayer)soundPlayer;
+ autoSound.stop();
+ }
+ }
+
+ @Override
+ public String expandURLMacros(String urlIn) {
+ return WebControlImp.processURL(urlIn);
+ }
+
+ @Override
+ public int getIniInt(String entry, int defaultVal) {
+ return IniFile.gamma().getIniInt(entry, defaultVal);
+ }
+
+ @Override
+ public String getIniString(String entry, String defaultVal) {
+ return IniFile.gamma().getIniString(entry, defaultVal);
+ }
+
+ @Override
+ public void setIniInt(String entry, int val) {
+ IniFile.gamma().setIniInt(entry, val);
+ }
+
+ @Override
+ public void setIniString(String entry, String val) {
+ IniFile.gamma().setIniString(entry, val);
+ }
+
+ @Override
+ public int getClientVersion() {
+ return Std.getVersion();
+ }
+
+ @Override
+ public void messageBox(String text, String caption) {
+ Console c = Console.getActive();
+ if (c != null) {
+ new OkCancelDialog(Console.getFrame(), null, caption, null, Console.message("OK"), text, true);
+ }
+ }
+
+ @Override
+ public Object yesNoDialog(String text, String caption, String yes, String no, WorldScript callback) {
+ Console c = Console.getActive();
+ return c == null ? null : new OkCancelDialog(Console.getFrame(), callback, caption, no, yes, text);
+ }
+
+ @Override
+ public void printToChat(String text) {
+ Console c = Console.getActive();
+ if (c != null) {
+ Console.println(text);
+ }
+ }
+
+ @Override
+ public boolean watchVisibility(Object obj) {
+ if (obj == null) {
+ return false;
+ } else if (!(obj instanceof WObject)) {
+ return false;
+ } else {
+ WObject wobj = (WObject)obj;
+ Room r = wobj.getRoom();
+ if (r == null) {
+ return false;
+ } else {
+ r.addPrerenderHandler(wobj);
+ return true;
+ }
+ }
+ }
+
+ @Override
+ public int getVideoWallStatus(Object video) {
+ if (video != null && video instanceof VideoWall) {
+ VideoWall vw = (VideoWall)video;
+ return vw.getState();
+ } else {
+ return -1;
+ }
+ }
+
+ @Override
+ public boolean playVideo(Object video, int repeat) {
+ if (video != null && video instanceof VideoWall) {
+ VideoWall vw = (VideoWall)video;
+ VideoSurface vs = vw.getVideoSurface();
+ if (vs == null) {
+ return false;
+ } else {
+ vs.play(repeat);
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean stopVideo(Object video) {
+ if (video != null && video instanceof VideoWall) {
+ VideoWall vw = (VideoWall)video;
+ VideoSurface vs = vw.getVideoSurface();
+ if (vs == null) {
+ return false;
+ } else {
+ vs.stop();
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean setVideoURL(Object video, String url, int width, int height) {
+ if (video != null && video instanceof VideoWall) {
+ VideoWall vw = (VideoWall)video;
+ vw.changeURL(url, width, height);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean setWebWallURL(Object webWall, String url) {
+ if (webWall != null && webWall instanceof WebPageWall) {
+ WebPageWall wpw = (WebPageWall)webWall;
+ WebControlImp wci = wpw.getWebControlImp();
+ return wci != null && url != null ? wci.setURL(url) : false;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean setWebWallURL(Object webWall, String url, String postData) {
+ if (webWall != null && webWall instanceof WebPageWall) {
+ WebPageWall wpw = (WebPageWall)webWall;
+ WebControlImp wci = wpw.getWebControlImp();
+ return wci != null && url != null ? wci.setURL(url, postData) : false;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean animateBot(Object obj, String action) {
+ if (!(obj instanceof PosableShape)) {
+ return false;
+ } else {
+ PosableShape ps = (PosableShape)obj;
+ ps.animate(action);
+ return true;
+ }
+ }
+
+ @Override
+ public boolean setShapeURL(Object obj, String url) {
+ if (!(obj instanceof Shape)) {
+ return false;
+ } else {
+ Shape s = (Shape)obj;
+ s.setURL(URL.make(url));
+ return true;
+ }
+ }
+
+ @Override
+ public Object findObjectInRoom(String objectName) {
+ Room r = Pilot.getActive().getRoom();
+ if (r != null) {
+ DeepEnumeration e = new DeepEnumeration();
+ r.getChildren(e);
+
+ while (e.hasMoreElements()) {
+ SuperRoot wobj = (SuperRoot)e.nextElement();
+ if (wobj.getName().equals(objectName)) {
+ return wobj;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void walkObjectTo(WorldScript script, Object obj, float x, float y, float yaw, float vel) {
+ if (obj instanceof WObject) {
+ HandsOffDriver hod = new HandsOffDriver();
+ hod.setDestPos(new Point2(x, y), yaw, vel);
+ hod.setTarget((Transform)obj);
+ hod.addCallback(script);
+ ((WObject)obj).addHandler(hod);
+ }
+ }
+
+ @Override
+ public void moveObjectTo(Object obj, float x, float y, float yaw) {
+ if (obj instanceof Transform) {
+ Transform t = (Transform)obj;
+ t.moveTo(x, y, t.getZ()).yaw(yaw);
+ }
+ }
+
+ @Override
+ public void moveObjectTo(Object obj, float x, float y, float z, float yaw) {
+ if (obj instanceof Transform) {
+ Transform t = (Transform)obj;
+ t.moveTo(x, y, z).yaw(yaw);
+ }
+ }
+
+ public void moveObjectTo(Object obj, float x, float y, float z, float yaw, float sc) {
+ if (obj instanceof Transform) {
+ Transform t = (Transform)obj;
+ t.moveTo(x, y, z).yaw(yaw);
+ t.scale(sc);
+ }
+ }
+
+ @Override
+ public boolean isLoggedIn() {
+ Console c = Console.getActive();
+ if (c != null) {
+ Galaxy g = c.getGalaxy();
+ if (g != null) {
+ return g.getOnline();
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public int getConcurrentDownloads() {
+ return CacheEntry.getConcurrentDownloads();
+ }
+
+ @Override
+ public boolean getIsVIP() {
+ Console c = Console.getActive();
+ return c != null ? c.getVIP() : false;
+ }
+
+ @Override
+ public void setAdCube(boolean clickable, boolean usesGIF, String baseURL, String defaultURL) {
+ Pilot p = Pilot.getActive();
+ if (p != null) {
+ World w = p.getWorld();
+ if (w != null) {
+ w.setHasClickableAdCube(clickable);
+ w.setAdCubeFormatIsGif(usesGIF);
+ w.setAdCubeBaseURL(baseURL);
+ w.setDefaultAdCubeURL(defaultURL);
+ }
+ }
+ }
+}