Browse Source

Ficed load/save in cubeWorker

Max Nuding 12 years ago
parent
commit
80e22b2106
2 changed files with 42 additions and 24 deletions
  1. 35
    20
      Cube Control/cubeWorker.java
  2. 7
    4
      Cube Control/layerEditFrame.java

+ 35
- 20
Cube Control/cubeWorker.java View File

170
     }
170
     }
171
 
171
 
172
     // Returns array with 64 bytes with led values
172
     // Returns array with 64 bytes with led values
173
-    public byte[] getFrame(int anim, int frame) {
173
+    public short[] getFrame(int anim, int frame) {
174
     return animations.get(anim).get(frame).getData();
174
     return animations.get(anim).get(frame).getData();
175
   }
175
   }
176
 
176
 
177
-    public void setFrame(byte[] data, int anim, int frame) {
177
+    public void setFrame(short[] data, int anim, int frame) {
178
     changedState = true;
178
     changedState = true;
179
     animations.get(anim).get(frame).setData(data);
179
     animations.get(anim).get(frame).setData(data);
180
     }
180
     }
181
 
181
 
182
   // Frame duration in 1/24th of a second
182
   // Frame duration in 1/24th of a second
183
-  public byte getFrameTime(int anim, int frame) {
183
+  public short getFrameTime(int anim, int frame) {
184
     return animations.get(anim).get(frame).getTime();
184
     return animations.get(anim).get(frame).getTime();
185
   }
185
   }
186
 
186
 
187
-  public void setFrameTime(byte time, int anim, int frame) {
187
+  public void setFrameTime(short time, int anim, int frame) {
188
     changedState = true;
188
     changedState = true;
189
     animations.get(anim).get(frame).setTime(time);
189
     animations.get(anim).get(frame).setTime(time);
190
   }
190
   }
352
   private static AFrame readFrame(Scanner sc, int index) {
352
   private static AFrame readFrame(Scanner sc, int index) {
353
   AFrame frame = new AFrame();
353
   AFrame frame = new AFrame();
354
   frame.setName(sc.nextLine());
354
   frame.setName(sc.nextLine());
355
-  byte[] d = {};
355
+  short[] d = {};
356
   for (int i = 0; i < 8; i++) {
356
   for (int i = 0; i < 8; i++) {
357
-    byte[] data = hexConvert(sc.nextLine());
357
+    short[] data = hexConvert(sc.nextLine());
358
     d = concat(data, d);
358
     d = concat(data, d);
359
   }
359
   }
360
   frame.setData(d);
360
   frame.setData(d);
363
   return frame;
363
   return frame;
364
   }
364
   }
365
 
365
 
366
-  private static byte[] concat(byte[] a, byte[] b) {
367
-  byte[] c = new byte[a.length + b.length];
366
+  private static short[] concat(short[] a, short[] b) {
367
+  short[] c = new short[a.length + b.length];
368
   System.arraycopy(a, 0, c, 0, a.length);
368
   System.arraycopy(a, 0, c, 0, a.length);
369
   System.arraycopy(b, 0, c, a.length, b.length);
369
   System.arraycopy(b, 0, c, a.length, b.length);
370
   return c;
370
   return c;
371
   }
371
   }
372
 
372
 
373
-  private static byte[] hexConvert(String hex) {
374
-  hex = hex.replaceAll("\\n", "");
375
-  HexBinaryAdapter a = new HexBinaryAdapter();
376
-  return a.unmarshal(hex);
373
+  private static short[] hexConvert(String hex) {
374
+    hex = hex.replaceAll("\\n", "");
375
+
376
+      short[] tmp = new short[hex.length()/2];
377
+      for (int i = 0; i < hex.length(); i=i+2){
378
+        char[] tmpString = new char[2];
379
+        tmpString[0] = hex.charAt(i);
380
+        tmpString[1] = hex.charAt(i+1);
381
+        String tmpS = String.copyValueOf(tmpString);
382
+        if(i == 0){
383
+          tmp[0] = Short.parseShort(tmpS, 16);
384
+        } else {
385
+          tmp[i/2] = Short.parseShort(tmpS, 16);
386
+        }
387
+
388
+      }
389
+      return tmp;
390
+
391
+
377
   }
392
   }
378
 
393
 
379
   private static void writeAnimation(Animation anim, FileWriter f, boolean last) throws IOException {
394
   private static void writeAnimation(Animation anim, FileWriter f, boolean last) throws IOException {
395
     f.write(Integer.toString( (fr.getTime() & 0xff) + 0x100, 16).substring(1) + "\n");
410
     f.write(Integer.toString( (fr.getTime() & 0xff) + 0x100, 16).substring(1) + "\n");
396
   }
411
   }
397
 
412
 
398
-  private static void writeLayer(byte[] l, FileWriter f) throws IOException {
413
+  private static void writeLayer(short[] l, FileWriter f) throws IOException {
399
     String hex = "";
414
     String hex = "";
400
     for (int i = 0; i < l.length; i++) {
415
     for (int i = 0; i < l.length; i++) {
401
       hex += Integer.toString( (l[i] & 0xff) + 0x100, 16).substring(1);
416
       hex += Integer.toString( (l[i] & 0xff) + 0x100, 16).substring(1);
407
 }
422
 }
408
 
423
 
409
 class AFrame {
424
 class AFrame {
410
-  private byte[] data = new byte[64];
411
-  private byte duration = 1;
425
+  private short[] data = new short[64];
426
+  private short duration = 1;
412
   private String name = "Frame";
427
   private String name = "Frame";
413
 
428
 
414
   String getName() {
429
   String getName() {
419
     name = s;
434
     name = s;
420
   }
435
   }
421
 
436
 
422
-  void setData(byte[] d) {
437
+  void setData(short[] d) {
423
     data = d;
438
     data = d;
424
   }
439
   }
425
 
440
 
426
-  byte[] getData() {
441
+  short[] getData() {
427
     return data;
442
     return data;
428
   }
443
   }
429
 
444
 
430
-  void setTime(byte t) {
445
+  void setTime(short t) {
431
     duration = t;
446
     duration = t;
432
   }
447
   }
433
 
448
 
434
-  byte getTime() {
449
+  short getTime() {
435
     return duration;
450
     return duration;
436
   }
451
   }
437
 
452
 
438
-  byte[] getLayer(int i) {
453
+  short[] getLayer(int i) {
439
     return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
454
     return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
440
   }
455
   }
441
 }
456
 }

+ 7
- 4
Cube Control/layerEditFrame.java View File

51
     worker = work;
51
     worker = work;
52
     animI = animIndex;
52
     animI = animIndex;
53
     frameI = frameIndex;
53
     frameI = frameIndex;
54
-    frame =  byteToShortArray(worker.getFrame(animIndex, frameIndex));
54
+    //frame =  byteToShortArray(worker.getFrame(animIndex, frameIndex));
55
+    frame = worker.getFrame(animIndex, frameIndex);
55
     li = layerIndex;
56
     li = layerIndex;
56
     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
57
     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
57
     int frameWidth = 180;
58
     int frameWidth = 180;
144
 
145
 
145
   }
146
   }
146
 
147
 
147
-   byte[] getFinalFrame(){
148
+   short[] getFinalFrame(){
148
       if (finish == false) {
149
       if (finish == false) {
149
         return null;
150
         return null;
150
       }
151
       }
151
-      return shortToByteArray(frame);
152
+      //return shortToByteArray(frame);
153
+      return frame;
152
    }
154
    }
153
 
155
 
154
   public void btnClicked(int i, int j){
156
   public void btnClicked(int i, int j){
182
       reihe = 0;
184
       reihe = 0;
183
     }
185
     }
184
       frame = tmpFrame;
186
       frame = tmpFrame;
185
-      worker.setFrame(shortToByteArray(frame), animI, frameI);
187
+      //worker.setFrame(shortToByteArray(frame), animI, frameI);
188
+      worker.setFrame(frame, animI, frameI);
186
       dispose();
189
       dispose();
187
   }
190
   }
188
   
191
   

Loading…
Cancel
Save