|
@@ -54,6 +54,7 @@ public class cubeWorker {
|
54
|
54
|
|
55
|
55
|
cubeWorker() {
|
56
|
56
|
animations.add(new Animation());
|
|
57
|
+ animations.get(0).setName("Animation 1");
|
57
|
58
|
}
|
58
|
59
|
|
59
|
60
|
cubeWorker(ArrayList<Animation> anims) {
|
|
@@ -93,7 +94,8 @@ public class cubeWorker {
|
93
|
94
|
return -1;
|
94
|
95
|
} else {
|
95
|
96
|
int s = animations.size();
|
96
|
|
- animations.add(s + 1, new Animation());
|
|
97
|
+ animations.add(s, new Animation());
|
|
98
|
+ animations.get(s).setName("Animation " + animations.size());
|
97
|
99
|
return s;
|
98
|
100
|
}
|
99
|
101
|
}
|
|
@@ -156,7 +158,7 @@ public class cubeWorker {
|
156
|
158
|
framesRemaining--;
|
157
|
159
|
int s = animations.get(anim).size();
|
158
|
160
|
animations.get(anim).add(s);
|
159
|
|
- animations.get(anim).get(s).setName("Frame " + (2016 - framesRemaining));
|
|
161
|
+ animations.get(anim).get(s).setName("Frame " + (2016 - framesRemaining));
|
160
|
162
|
return s;
|
161
|
163
|
}
|
162
|
164
|
|
|
@@ -191,10 +193,10 @@ public class cubeWorker {
|
191
|
193
|
if (dir == UP){
|
192
|
194
|
// frame moved up
|
193
|
195
|
if (frame > 0) {
|
194
|
|
- AFrame tmp = animations.get(anim).get(frame);
|
195
|
|
- animations.get(anim).set(animations.get(anim).get(frame - 1), frame);
|
196
|
|
- animations.get(anim).set(tmp, frame - 1);
|
197
|
|
- }
|
|
196
|
+ AFrame tmp = animations.get(anim).get(frame);
|
|
197
|
+ animations.get(anim).set(animations.get(anim).get(frame - 1), frame);
|
|
198
|
+ animations.get(anim).set(tmp, frame - 1);
|
|
199
|
+ }
|
198
|
200
|
} else if (dir == DOWN){
|
199
|
201
|
// frame moved down
|
200
|
202
|
if (frame < (animations.get(anim).size() - 1)) {
|
|
@@ -212,20 +214,20 @@ public class cubeWorker {
|
212
|
214
|
// Loads an animation file into this object
|
213
|
215
|
public int loadState(String path) {
|
214
|
216
|
changedState = false;
|
215
|
|
- try {
|
216
|
|
- animations = AnimationUtility.readFile(path);
|
217
|
|
- } catch (Exception e) {
|
218
|
|
- System.out.println(e.toString());
|
219
|
|
- return -1;
|
220
|
|
- }
|
221
|
|
- int size = 0;
|
222
|
|
- for (int i = 0; i < animations.size(); i++) {
|
223
|
|
- size += animations.get(i).size();
|
224
|
|
- }
|
225
|
|
- framesRemaining = 2016 - size;
|
226
|
|
- if (size > 2016) {
|
227
|
|
- return -1;
|
228
|
|
- }
|
|
217
|
+ try {
|
|
218
|
+ animations = AnimationUtility.readFile(path);
|
|
219
|
+ } catch (Exception e) {
|
|
220
|
+ System.out.println(e.toString());
|
|
221
|
+ return -1;
|
|
222
|
+ }
|
|
223
|
+ int size = 0;
|
|
224
|
+ for (int i = 0; i < animations.size(); i++) {
|
|
225
|
+ size += animations.get(i).size();
|
|
226
|
+ }
|
|
227
|
+ framesRemaining = 2016 - size;
|
|
228
|
+ if (size > 2016) {
|
|
229
|
+ return -1;
|
|
230
|
+ }
|
229
|
231
|
return 0;
|
230
|
232
|
}
|
231
|
233
|
|
|
@@ -276,13 +278,13 @@ class AnimationUtility {
|
276
|
278
|
|
277
|
279
|
public static ArrayList<Animation> readFile(String path) throws Exception {
|
278
|
280
|
Scanner sc = new Scanner(new File(path));
|
279
|
|
- ArrayList<Animation> animations = new ArrayList<Animation>();
|
|
281
|
+ ArrayList<Animation> animations = new ArrayList<Animation>();
|
280
|
282
|
|
281
|
|
- do {
|
282
|
|
- animations.add(readAnimation(sc));
|
283
|
|
- } while (sc.hasNextLine());
|
|
283
|
+ do {
|
|
284
|
+ animations.add(readAnimation(sc));
|
|
285
|
+ } while (sc.hasNextLine());
|
284
|
286
|
|
285
|
|
- return animations;
|
|
287
|
+ return animations;
|
286
|
288
|
}
|
287
|
289
|
|
288
|
290
|
public static void writeFile(String path, ArrayList<Animation> animations) {
|
|
@@ -323,56 +325,56 @@ class AnimationUtility {
|
323
|
325
|
}
|
324
|
326
|
|
325
|
327
|
private static Animation readAnimation(Scanner sc) {
|
326
|
|
- Animation anim = new Animation();
|
327
|
|
- AFrame f = null;
|
328
|
|
- int index = 0;
|
329
|
|
- int size = sc.nextInt();
|
330
|
|
- anim.setName(sc.nextLine());
|
331
|
|
- while (size > 0) {
|
332
|
|
- f = readFrame(sc, index);
|
333
|
|
- anim.add(index);
|
334
|
|
- anim.set(f, index);
|
335
|
|
- index++;
|
336
|
|
- size--;
|
337
|
|
- }
|
338
|
|
-
|
339
|
|
- return anim;
|
|
328
|
+ Animation anim = new Animation();
|
|
329
|
+ AFrame f = null;
|
|
330
|
+ int index = 0;
|
|
331
|
+ int size = sc.nextInt();
|
|
332
|
+ anim.setName(sc.nextLine());
|
|
333
|
+ while (size > 0) {
|
|
334
|
+ f = readFrame(sc, index);
|
|
335
|
+ anim.add(index);
|
|
336
|
+ anim.set(f, index);
|
|
337
|
+ index++;
|
|
338
|
+ size--;
|
|
339
|
+ }
|
|
340
|
+
|
|
341
|
+ return anim;
|
340
|
342
|
}
|
341
|
343
|
|
342
|
344
|
private static AFrame readFrame(Scanner sc, int index) {
|
343
|
|
- AFrame frame = new AFrame();
|
344
|
|
- frame.setName("Frame " + index);
|
345
|
|
- byte[] d = {};
|
346
|
|
- for (int i = 0; i < 8; i++) {
|
347
|
|
- byte[] data = hexConvert(sc.nextLine());
|
348
|
|
- d = concat(data, d);
|
349
|
|
- }
|
350
|
|
- frame.setData(d);
|
351
|
|
- d = hexConvert(sc.nextLine());
|
352
|
|
- frame.setTime(d[0]);
|
353
|
|
- return frame;
|
|
345
|
+ AFrame frame = new AFrame();
|
|
346
|
+ frame.setName("Frame " + index);
|
|
347
|
+ byte[] d = {};
|
|
348
|
+ for (int i = 0; i < 8; i++) {
|
|
349
|
+ byte[] data = hexConvert(sc.nextLine());
|
|
350
|
+ d = concat(data, d);
|
|
351
|
+ }
|
|
352
|
+ frame.setData(d);
|
|
353
|
+ d = hexConvert(sc.nextLine());
|
|
354
|
+ frame.setTime(d[0]);
|
|
355
|
+ return frame;
|
354
|
356
|
}
|
355
|
357
|
|
356
|
358
|
private static byte[] concat(byte[] a, byte[] b) {
|
357
|
|
- byte[] c = new byte[a.length + b.length];
|
358
|
|
- System.arraycopy(a, 0, c, 0, a.length);
|
359
|
|
- System.arraycopy(b, 0, c, a.length, b.length);
|
360
|
|
- return c;
|
|
359
|
+ byte[] c = new byte[a.length + b.length];
|
|
360
|
+ System.arraycopy(a, 0, c, 0, a.length);
|
|
361
|
+ System.arraycopy(b, 0, c, a.length, b.length);
|
|
362
|
+ return c;
|
361
|
363
|
}
|
362
|
364
|
|
363
|
365
|
private static byte[] hexConvert(String hex) {
|
364
|
|
- hex = hex.replaceAll("\\n", "");
|
365
|
|
- int length = hex.length();
|
366
|
|
- byte[] data = new byte[length / 2];
|
367
|
|
- for (int i = 0; i < length; i += 2) {
|
368
|
|
- data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
|
369
|
|
- }
|
370
|
|
- return data;
|
|
366
|
+ hex = hex.replaceAll("\\n", "");
|
|
367
|
+ int length = hex.length();
|
|
368
|
+ byte[] data = new byte[length / 2];
|
|
369
|
+ for (int i = 0; i < length; i += 2) {
|
|
370
|
+ data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
|
|
371
|
+ }
|
|
372
|
+ return data;
|
371
|
373
|
}
|
372
|
374
|
|
373
|
375
|
private static void writeAnimation(Animation anim, FileWriter f) throws IOException {
|
374
|
376
|
f.write(anim.size() + "\n");
|
375
|
|
- f.write(anim.getName() + "\n");
|
|
377
|
+ f.write(anim.getName() + "\n");
|
376
|
378
|
for (int i = 0; i < anim.size(); i++) {
|
377
|
379
|
writeFrame(anim.get(i), f);
|
378
|
380
|
}
|