summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WorldScriptManager.java
blob: e0fbebaabc05c145adaf9435e3ef5571387ac5ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*     */ package NET.worlds.scape;
/*     */ 
/*     */ import NET.worlds.console.Console;
/*     */ import NET.worlds.console.DefaultConsole;
/*     */ import NET.worlds.console.Main;
/*     */ import NET.worlds.console.MainCallback;
/*     */ import NET.worlds.console.MainTerminalCallback;
/*     */ import NET.worlds.console.RenderCanvas;
/*     */ import java.awt.PopupMenu;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import java.io.PrintStream;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Vector;
/*     */ 
/*     */ public class WorldScriptManager
/*     */   implements ActionListener, MainCallback, MainTerminalCallback
/*     */ {
/*  19 */   private static WorldScriptManager instance = new WorldScriptManager();
/*     */   
/*     */ 
/*  22 */   private static WorldScriptLoader loader = new WorldScriptLoader();
/*     */   
/*  24 */   public static WorldScriptManager getInstance() { return instance; }
/*     */   
/*     */   private WorldScriptManager()
/*     */   {
/*  28 */     this.currentScript = null;
/*  29 */     Main.register(this);
/*     */   }
/*     */   
/*     */   public void terminalCallback()
/*     */   {
/*  34 */     if (this.currentScript != null) {
/*  35 */       this.currentScript.worldExit();
/*     */     }
/*  37 */     this.currentScript = null;
/*     */     
/*  39 */     Main.unregister(this);
/*     */   }
/*     */   
/*     */ 
/*     */   private WorldScript currentScript;
/*     */   private String lastRoom;
/*     */   public void worldEntered(String worldName)
/*     */   {
/*  47 */     if (this.currentScript != null) {
/*  48 */       this.currentScript.worldExit();
/*     */     }
/*  50 */     this.currentScript = null;
/*     */     
/*  52 */     if (worldName == null) {
/*  53 */       return;
/*     */     }
/*  55 */     worldName = worldName.replace(' ', '_');
/*  56 */     worldName = worldName.replace('-', '_');
/*  57 */     worldName = worldName.replace('.', '_');
/*  58 */     worldName = worldName.replace('/', '_');
/*  59 */     worldName = worldName.replace('\\', '_');
/*     */     
/*     */     try
/*     */     {
/*  63 */       this.currentScript = 
/*  64 */         ((WorldScript)loader.loadClass("WorldScript" + worldName + ".class", true).newInstance());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/*  68 */       System.out.println("Exception constructing world script: " + e);
/*     */     }
/*     */     catch (Error e)
/*     */     {
/*  72 */       System.out.println("Error constructing world script: " + e);
/*     */     }
/*     */     
/*  75 */     if (this.currentScript != null)
/*     */     {
/*     */ 
/*  78 */       if (this.currentScript.getMinScriptVersion() > 15)
/*     */       {
/*  80 */         System.out.println("Script requires newer client version. script is ver. " + 
/*  81 */           this.currentScript.getMinScriptVersion() + 
/*  82 */           " and client has ver. " + 15);
/*  83 */         this.currentScript = null;
/*     */       }
/*     */       else
/*     */       {
/*  87 */         this.currentScript.worldEnter();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void mainCallback()
/*     */   {
/*  94 */     if (this.currentScript != null) {
/*  95 */       this.currentScript.onEachFrame();
/*     */     }
/*     */   }
/*     */   
/*     */   public void onPrerender(WObject obj, Camera cam) {
/* 100 */     if (this.currentScript != null)
/*     */     {
/* 102 */       Console c = Console.getActive();
/* 103 */       if (c == null) return;
/* 104 */       if (!(c instanceof DefaultConsole))
/* 105 */         return;
/* 106 */       DefaultConsole dc = (DefaultConsole)c;
/* 107 */       RenderCanvas rc = dc.getRender();
/* 108 */       if (rc == null) { return;
/*     */       }
/* 110 */       Camera renderCam = rc.getCamera();
/* 111 */       if (cam != renderCam) { return;
/*     */       }
/* 113 */       Point3Temp p = obj.inCamSpace(cam);
/*     */       
/*     */ 
/*     */ 
/* 117 */       boolean v = (p != null) && (p.z > 1.0F) && (p.x < p.z) && (-p.x < p.z);
/*     */       
/* 119 */       this.currentScript.objectVisibilityNotification(obj, v);
/*     */     }
/*     */   }
/*     */   
/*     */   public void action(String message)
/*     */   {
/* 125 */     if (this.currentScript != null) {
/* 126 */       this.currentScript.onTriggerAction(message);
/*     */     }
/*     */   }
/*     */   
/*     */   public PopupMenu shapeClicked(Shape shape) {
/* 131 */     if (this.currentScript != null)
/*     */     {
/* 133 */       SuperRoot ultimateOwner = shape;
/* 134 */       while (ultimateOwner.getOwner() != null)
/*     */       {
/* 136 */         ultimateOwner = ultimateOwner.getOwner();
/* 137 */         if ((ultimateOwner instanceof PosableShape))
/*     */         {
/* 139 */           shape = (Shape)ultimateOwner;
/* 140 */           break;
/*     */         }
/*     */       }
/*     */       
/* 144 */       Vector<String> v = this.currentScript.onShapeClick(shape, shape.getName());
/* 145 */       if (v != null)
/*     */       {
/* 147 */         PopupMenu m = new PopupMenu();
/* 148 */         Enumeration<String> e = v.elements();
/* 149 */         while (e.hasMoreElements())
/*     */         {
/* 151 */           m.add((String)e.nextElement());
/*     */         }
/* 153 */         return m;
/*     */       }
/*     */     }
/*     */     
/* 157 */     return null;
/*     */   }
/*     */   
/*     */   public void actionPerformed(ActionEvent e)
/*     */   {
/* 162 */     if (this.currentScript != null) {
/* 163 */       this.currentScript.onMenuClick(e.getActionCommand(), e.getSource());
/*     */     }
/*     */   }
/*     */   
/*     */   public void roomEntered(String roomName) {
/* 168 */     if (this.currentScript == null) {
/* 169 */       return;
/*     */     }
/* 171 */     if (this.lastRoom != null) {
/* 172 */       this.currentScript.roomExit(this.lastRoom);
/*     */     }
/* 174 */     this.currentScript.roomEnter(roomName);
/*     */     
/* 176 */     this.lastRoom = new String(roomName);
/*     */   }
/*     */   
/*     */   public void onConversation(String who, String what)
/*     */   {
/* 181 */     if (this.currentScript == null) {
/* 182 */       return;
/*     */     }
/* 184 */     this.currentScript.onConversation(who, what);
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\WorldScriptManager.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */