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
|
package NET.worlds.scape;
import NET.worlds.core.Std;
import java.io.IOException;
public class AnimateAction extends Action {
int startTime;
public int cycleTime = 1000;
public String frameList = "";
protected int frameListCount = 0;
protected Material[] frameMaterialArray = null;
public int cycles = 0;
public boolean infiniteLoop = false;
protected int cycleNo;
protected int currentFrameNo;
private boolean running = false;
private static Object classCookie = new Object();
public AnimateAction() {
this.startAnimation();
}
public void startAnimation() {
this.cycleNo = 0;
this.currentFrameNo = -1;
this.startTime = Std.getRealTime();
}
public void preprocessFrameList(String frameList) {
this.frameMaterialArray = AnimatingDoor.namesToMaterialArray(this, frameList);
this.frameListCount = this.frameMaterialArray == null ? 0 : this.frameMaterialArray.length;
}
@Override
public void detach() {
if (this.frameMaterialArray != null) {
int i = this.frameMaterialArray.length;
while (--i >= 0) {
this.frameMaterialArray[i].setKeepLoaded(false);
}
this.frameMaterialArray = null;
this.frameListCount = 0;
}
super.detach();
}
@Override
public Persister trigger(Event e, Persister seqID) {
Object owner = this.getOwner();
if (!(owner instanceof Animatable)) {
this.frameMaterialArray = null;
this.frameListCount = 0;
return null;
} else {
Animatable o = (Animatable)owner;
if (!o.hasClump()) {
this.frameMaterialArray = null;
this.frameListCount = 0;
return seqID;
} else {
if (this.frameMaterialArray == null) {
this.preprocessFrameList(this.frameList);
}
if (seqID == null) {
if (this.running && !this.infiniteLoop) {
return null;
}
this.startAnimation();
}
int nextFrameNo = 0;
if (this.frameListCount != 0 && this.cycleTime > 0) {
int runTime = Std.getRealTime() - this.startTime;
long frameNo = (long)this.frameListCount * runTime / this.cycleTime;
this.cycleNo = (int)(frameNo / this.frameListCount);
nextFrameNo = (int)(frameNo - this.cycleNo * this.frameListCount);
} else {
this.cycleNo = 1000000000;
}
if (this.cycleNo >= this.cycles && !this.infiniteLoop) {
nextFrameNo = this.frameListCount - 1;
this.running = false;
} else {
this.running = true;
}
if (nextFrameNo != this.currentFrameNo) {
this.currentFrameNo = nextFrameNo;
if (o.hasClump() && this.currentFrameNo >= 0) {
o.setMaterial(this.frameMaterialArray[this.currentFrameNo]);
}
}
return this.running ? this : null;
}
}
}
@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 = IntegerPropertyEditor.make(new Property(this, index, "Cycle Time"));
} else if (mode == 1) {
ret = new Integer(this.cycleTime);
} else if (mode == 2) {
this.cycleTime = (Integer)value;
}
break;
case 1:
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 2:
if (mode == 0) {
ret = BooleanPropertyEditor.make(new Property(this, index, "Infinite Loop"), "False", "True");
} else if (mode == 1) {
ret = new Boolean(this.infiniteLoop);
} else if (mode == 2) {
this.infiniteLoop = (Boolean)value;
}
break;
case 3:
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 + 4, mode, value);
}
return ret;
}
@Override
public String toString() {
String ret = super.toString() + "[cycleTime " + this.cycleTime + ", cycles " + this.cycles + ",";
if (!this.infiniteLoop) {
ret = ret + " not ";
}
return ret + "Infinite ]";
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(3, classCookie);
super.saveState(s);
s.saveBoolean(this.infiniteLoop);
s.saveInt(this.cycleTime);
s.saveInt(this.cycles);
s.saveString(this.frameList);
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 1:
super.restoreState(r);
case 0:
this.cycleTime = (int)r.restoreFloat();
this.cycles = r.restoreInt();
this.infiniteLoop = this.cycles == 0;
this.frameList = r.restoreString();
break;
case 2:
super.restoreState(r);
this.cycleTime = r.restoreInt();
this.cycles = r.restoreInt();
this.infiniteLoop = this.cycles == 0;
this.frameList = r.restoreString();
break;
case 3:
super.restoreState(r);
this.infiniteLoop = r.restoreBoolean();
this.cycleTime = r.restoreInt();
this.cycles = r.restoreInt();
this.frameList = r.restoreString();
break;
default:
throw new TooNewException();
}
}
}
|