summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/RunningActionHandler.java
blob: 7ef5391ea4936509c868a0ffae40fa33255ffb12 (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*     */ package NET.worlds.scape;
/*     */ 
/*     */ import NET.worlds.console.Console;
/*     */ import java.io.IOException;
/*     */ import java.text.MessageFormat;
/*     */ import java.util.Vector;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class RunningActionHandler
/*     */   extends SuperRoot
/*     */   implements FrameHandler, NonPersister
/*     */ {
/*     */   private Action action;
/*     */   private Persister seqID;
/*     */   private RunningActionCallback callback;
/*     */   private Object callbackCookie;
/*     */   
/*     */   public static void trigger(Action act, World w, Event event)
/*     */   {
/*  40 */     trigger(act, w, event, null, null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void trigger(Action act, World w, Event event, RunningActionCallback callb, Object o)
/*     */   {
/*  59 */     if (act.isActive())
/*     */     {
/*  61 */       Persister seqID = null;
/*  62 */       if ((seqID = act.trigger(event, seqID)) != null)
/*     */       {
/*     */ 
/*     */ 
/*  66 */         new RunningActionHandler(w, act, seqID, callb, o);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public static void trigger(Vector<Action> v, World w, Event event)
/*     */   {
/*  74 */     trigger(v, w, event, null, null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void trigger(Vector<Action> v, World w, Event event, RunningActionCallback callb, Object o)
/*     */   {
/*  85 */     Vector<Action> acts = (Vector)v.clone();
/*     */     
/*  87 */     int sz = acts.size();
/*  88 */     for (int i = 0; i < sz; i++)
/*     */     {
/*  90 */       Action act = (Action)acts.elementAt(i);
/*  91 */       if (v.contains(act)) {
/*  92 */         trigger(act, w, event, callb, o);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   RunningActionHandler() {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private RunningActionHandler(World world, Action a, Persister seqID, RunningActionCallback callb, Object o)
/*     */   {
/* 114 */     this.action = a;
/* 115 */     this.seqID = seqID;
/* 116 */     this.callback = callb;
/* 117 */     this.callbackCookie = o;
/* 118 */     world.addHandler(this);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean handle(FrameEvent e)
/*     */   {
/* 131 */     if ((!this.action.isActive()) || ((this.seqID = this.action.trigger(e, this.seqID)) == null)) {
/* 132 */       if (this.callback != null)
/* 133 */         this.callback.actionDone(this.action, e, this.callbackCookie);
/* 134 */       getWorld().removeHandler(this);
/*     */     }
/* 136 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public Object properties(int index, int offset, int mode, Object value)
/*     */     throws NoSuchPropertyException
/*     */   {
/* 145 */     Object ret = null;
/* 146 */     switch (index - offset) {
/*     */     case 0: 
/* 148 */       if (mode == 0) {
/* 149 */         ret = new Property(this, index, "Action");
/* 150 */       } else if (mode == 1)
/* 151 */         ret = this.action;
/* 152 */       break;
/*     */     case 1: 
/* 154 */       if (mode == 0) {
/* 155 */         ret = new Property(this, index, "Sequence ID Object");
/* 156 */       } else if (mode == 1)
/* 157 */         ret = this.seqID;
/* 158 */       break;
/*     */     default: 
/* 160 */       ret = super.properties(index, offset + 2, mode, value);
/*     */     }
/* 162 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 169 */   private static Object classCookie = new Object();
/*     */   
/*     */   public void saveState(Saver s) throws IOException
/*     */   {
/* 173 */     Console.println(Console.message("Save-running"));
/* 174 */     s.saveVersion(3, classCookie);
/* 175 */     super.saveState(s);
/* 176 */     s.save(this.action);
/* 177 */     s.saveMaybeNull(this.seqID);
/* 178 */     s.saveMaybeNull((Persister)this.callback);
/*     */   }
/*     */   
/*     */   public void restoreState(Restorer r) throws IOException, TooNewException
/*     */   {
/* 183 */     switch (r.restoreVersion(classCookie)) {
/*     */     case 3: 
/* 185 */       super.restoreState(r);
/* 186 */       this.action = ((Action)r.restore());
/* 187 */       this.seqID = r.restoreMaybeNull();
/* 188 */       this.callback = ((RunningActionCallback)r.restoreMaybeNull());
/* 189 */       break;
/*     */     case 2: 
/* 191 */       super.restoreState(r);
/* 192 */       this.action = ((Action)r.restore());
/* 193 */       this.seqID = r.restoreMaybeNull();
/* 194 */       this.callback = null;
/* 195 */       break;
/*     */     case 1: 
/* 197 */       super.restoreState(r);
/* 198 */       this.action = ((Action)r.restore());
/* 199 */       this.callback = null;
/* 200 */       break;
/*     */     case 0: 
/* 202 */       super.restoreState(r);
/* 203 */       r.restore();
/* 204 */       this.action = ((Action)r.restoreMaybeNull());
/* 205 */       this.callback = null;
/* 206 */       break;
/*     */     default: 
/* 208 */       throw new TooNewException();
/*     */     }
/*     */   }
/*     */   
/*     */   public void postRestore(int version)
/*     */   {
/* 214 */     super.postRestore(version);
/* 215 */     Object[] arguments = { new String(getName()) };
/* 216 */     Console.println(MessageFormat.format(
/* 217 */       Console.message("Discarding-old"), arguments));
/* 218 */     SuperRoot owner = getOwner();
/* 219 */     if ((owner instanceof WObject)) {
/* 220 */       ((WObject)owner).removeHandler(this);
/* 221 */     } else if ((owner instanceof World)) {
/* 222 */       ((World)owner).removeHandler(this);
/*     */     } else {
/* 224 */       Console.println(MessageFormat.format(
/* 225 */         Console.message("Unable-discard"), arguments));
/*     */     }
/*     */   }
/*     */   
/*     */   public String toString() {
/* 230 */     return super.toString() + ":" + this.action.getName() + "[" + this.seqID + "]";
/*     */   }
/*     */ }


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