-
Notifications
You must be signed in to change notification settings - Fork 0
/
DissertationSketch.java
1109 lines (927 loc) · 23.9 KB
/
DissertationSketch.java
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import javax.swing.*;
import controlP5.*;
import java.util.LinkedList;
import java.util.Random;
import controlP5.*;
import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class DissertationSketch extends PApplet {
int counter = 0;
LinkedList<PShape> unitList;
LinkedList<Shape> units;
Boolean playing;
Random rng;
int j;
float rotX, rotY;
int closestShape;
int colour1 = color(255,0,0);
int colour2 = color(0,0,255);
boolean highlighted;
boolean buttonClicked;
ControlP5 cp5;
GUI gui;
Time t;
int clickCounter;
public void setup()
{
j = 2;
rng = new Random();
playing = false;
unitList = new LinkedList<PShape>();
units = new LinkedList<Shape>();
t = new Time();
t.createFrame(1);
t.firstFrameKeyFrame();
frameRate(2);
//gui setup
cp5 = new ControlP5(this);
gui = new GUI();
gui.setCP5(cp5);
gui.setPApplet(this);
gui.display();
for(int i = 1; i < gui.getFrameCount(); i++)
{
t.createFrame(i);
}
getExistingShapes();
}
public void draw()
{
clear();
background(170);
//attempt at making play button work, unsuccessful
if(playing)
{
j++;
if(j == (gui.getFrameCount() - 1))
{
j = 2;
}
setFrame(j);
delay(1000);
}
for(int i = 0; i < unitList.size(); i++)
{
PShape temp = unitList.get(i);
int x = units.get(i).getXPos();
int y = units.get(i).getYPos();
int scale = units.get(i).getScale(i,gui.getCurrentFrame());
if(units.get(i).getFaction() == 0)
fill(colour1);
else
fill(colour2);
if(units.get(i).getType(i).equals("Infantry"))
{
temp = createShape(RECT,x,y,scale,scale/2);
}
else if(units.get(i).getType(i).equals("Archer"))
{
temp = createShape(ELLIPSE,x,y,30,30);
}
//else shape is cavalry
else
{
temp = createShape(TRIANGLE, x,y,x-30,y-30,x+30,y-30);
}
if(i == closestShape && highlighted)
{
stroke(200);
strokeWeight(5);
}
else
{
stroke(100);
strokeWeight(1);
}
shape(temp);
fill(0,0,0);
text(units.get(i).getUnitName(i),x+5,y+10);
text(units.get(i).getTroopCount(),x+10,y+40);
// text(units.get(i).getTroopCount(i,gui.getCurrentFrame()),x+10,y+40);
}
}
//drag to move the unit
public void mouseDragged()
{
if(highlighted && !units.isEmpty())
{
units.get(closestShape).setPos(closestShape, gui.getCurrentFrame(),mouseX,mouseY);
}
}
//click to highlight, delete, etc.
public void mouseClicked()
{
if(mouseButton == LEFT)
{
print("clicked");
highlighted ^= true;
if(highlighted)
{
if(!getClosestShape())
{
highlighted = false;
}
}
else
{
print("no unit nearby");
if(!units.isEmpty())
{
units.get(closestShape).savePosAfterMove(gui.getCurrentFrame());
}
}
}
}
//stores closest shape in closestShape variable
//if returns true it's in range, else it's not
public boolean getClosestShape()
{
int x = mouseX;
int y = mouseY;
int closest = 0;
int shapeClosest = 0;
int difference = 0;
for(int i = 0; i < unitList.size(); i++)
{
difference = abs(x - units.get(i).getXPos());
difference += abs(y - units.get(i).getYPos());
if(i == 0)
{
closest = difference;
shapeClosest = 0;
}
if(closest > difference)
{
closest = difference;
shapeClosest = i;
}
}
closestShape = shapeClosest;
if (closest > 20)
return false;
return true;
}
//sets frame to the desired frame, calculates where the units should be
public void setFrame(int frame)
{
units.clear();
unitList.clear();
//checks if keyframe, if so get the position
if(t.checkKeyFrame(frame))
{
getExistingShapes();
}
//if there's a keyframe afterwards, interpolate position
else if(t.checkNextKeyFrame(frame,gui.getFrameCount()) != 0)
{
interpolationPos(frame);
}
//else onionskin position
else
{
int previousFrame = t.getPreviousKeyFrame(frame);
getExistingShapes(previousFrame);
}
}
public void interpolationPos(int frame)
{
int previousFrame = t.getPreviousKeyFrame(frame);
int i = 0;
if(previousFrame != 0)
{
while(t.checkUnitExists(i, previousFrame))
{
i++;
}
for(int counter = 0; counter < i; counter++)
{
Shape temp = new Shape(counter);
units.add(temp);
PShape p;
int x = t.interpolate(counter,gui.getCurrentFrame(),50)[0];
int y = t.interpolate(counter,gui.getCurrentFrame(),50)[1];
temp.movingPos(x,y);
p = createShape(RECT, x,y,10,10);
unitList.add(p);
}
}
}
//adds new shape to the scene
public void addNewShape(int size, String type)
{
Shape tempShape = new Shape(counter);
tempShape.createUnit(counter,gui.getFrameCount(),rng.nextInt(300),rng.nextInt(300),type);
PShape temp;
if(type.equals("Infantry")){
temp = createShape(BOX,1);
}
else if(type.equals("Cavalry"))
{
temp = createShape(SPHERE,1);
}
else if(type.equals("Archer"))
{
temp = createShape(TRIANGLE,1,1,1,1,1,1);
}
else
{
temp = createShape(BOX,1);
}
unitList.add(temp);
units.add(tempShape);
counter++;
}
//gets all existing shapes for the frame
public void getExistingShapes()
{
counter = 0;
int i = 0;
while(t.checkUnitExists(i,gui.getCurrentFrame()))
{
Shape temp = new Shape(i);
units.add(temp);
PShape p;
temp.firstTimeSetup(i,gui.getCurrentFrame());
p = createShape(RECT,
temp.getXPos(),
temp.getYPos(),
10,10);
unitList.add(p);
i++;
counter++;
}
}
//gets all existing shapes for the specified frame
public void getExistingShapes(int frame)
{
int i = 0;
counter = 0;
while(t.checkUnitExists(i, frame))
{
Shape temp = new Shape(i);
units.add(temp);
PShape p;
temp.firstTimeSetup(i,frame);
p = createShape(RECT,
temp.getXPos(),
temp.getYPos(),
10,10);
unitList.add(p);
i++;
counter++;
}
}
class GUI implements ControlListener
{
ControlP5 cp5;
PApplet p;
int numberOfFrames;
String[] items = {"Infantry", "Cavalry", "Archer"};
public GUI()
{
numberOfFrames = 50;
}
//set max number of frames to desired value
public void setFrameCount(int numberOfFrames)
{
this.numberOfFrames = numberOfFrames;
}
//returns max frame value
public int getFrameCount()
{
return numberOfFrames;
}
public void setCP5(ControlP5 cp5)
{
this.cp5 = cp5;
}
public void setPApplet(PApplet p)
{
this.p = p;
}
//displays all of the ui components, adds listeners to them also
public void display()
{
cp5.addButton("Create new unit")
.setPosition(440,290)
.setSize(70,70)
.setId(1)
.addListener(this);
cp5.addButton("Delete unit")
.setPosition(520,290)
.setSize(70,70)
.setId(2)
.addListener(this);
cp5.addDropdownList("list")
.setPosition(440,230)
.setSize(150,50)
.addItems(items)
.setLabel("Preset unit types")
.setId(3);
cp5.addSlider("Frames")
.setRange(1,numberOfFrames)
.setSize(400,20)
.setLabel("")
.setPosition(50,380)
.setNumberOfTickMarks(numberOfFrames)
.setSliderMode(Slider.FLEXIBLE)
.setId(4)
.addListener(this);
cp5.addButton("KeyFrame")
.setSize(60,30)
.setLabel("Make keyframe")
.setPosition(470, 380)
.setId(5)
.addListener(this);
cp5.addButton("Play")
.setSize(30,20)
.setPosition(10,380)
.setLabel("Play")
.setId(6)
.addListener(this);
cp5.addButton("ChangeUnitName")
.setSize(90,20)
.setLabel("Change unit name")
.setPosition(430,70)
.setId(7)
.addListener(this);
cp5.addButton("ChangeTroopCount")
.setSize(90,20)
.setLabel("Change troop count")
.setPosition(430,100)
.setId(8)
.addListener(this);
cp5.addButton("swapFaction")
.setSize(90,20)
.setLabel("Swap faction")
.setPosition(430,130)
.setId(9)
.addListener(this);
}
public int getCurrentFrame()
{
return (int)cp5.getController("Frames").getValue();
}
public void controlEvent(ControlEvent theEvent)
{
switch(theEvent.getId())
{
case(1):
int size = 1000;
String unitType = items[(int)cp5.getController("list").getValue()];
addNewShape(size,unitType);
break;
case(4):
setFrame((int)cp5.getController("Frames").getValue());
break;
case(5):
t.makeKeyFrame((int)cp5.getController("Frames").getValue());
break;
case(6):
playing = true;
break;
case(7):
String name = JOptionPane.showInputDialog("please enter new unit name");
units.get(closestShape).setUnitName(closestShape,name);
break;
case(8):
String stringValue = JOptionPane.showInputDialog("Please enter new troop count");
int troopCount = Integer.parseInt(stringValue);
units.get(closestShape).setTroopCount(closestShape, troopCount);
break;
case(9):
units.get(closestShape).swapFaction(closestShape);
}
}
}
public class Position
{
public Position()
{
try
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
}
catch(Exception e)
{}
}
public void writePosition(int frame, String objName, int posX, int posY)
{
}
public int readXPosition(int frame, String objName)
{
return 1;
}
public int readYPosition(int frame, String objName)
{
return 1;
}
}
class Shape {
int xPos;
int yPos;
int unitSize;
int faction;
int unitID;
String unitName;
String shapeType;
PShape shape;
PApplet p;
Time time;
public Shape(int unitValue)
{
faction = 0;
xPos = 0;
yPos = 0;
unitSize = 1000;
unitID = unitValue;
unitName = "unit" + unitID;
time = new Time();
}
public void createUnit(int unitID, int maxFrame, int x, int y, String unitType)
{
int troopSize = 1000;
int tempfaction = 1;
time.createUnit(unitID,maxFrame,x,y,unitType,troopSize,tempfaction);
}
public void setShapeType(int unitID,String type)
{
shapeType = type;
time.writeUnitType(unitID, type);
}
public void setTroopCount(int unitID, int size)
{
unitSize = size;
time.setTroopCount(unitID, size);
}
public String getType(int unitID)
{
return time.getUnitType(unitID);
}
public void createPos(int frame, int xPos, int yPos, int size)
{
time.writePos(unitID, frame, xPos, yPos, size);
}
public void storeShapeType(int unitID, String type)
{
shapeType = type;
time.writeUnitType(unitID, type);
}
public int getXPos()
{
return xPos;
}
public int getYPos()
{
return yPos;
}
public void setPos(int unitValue, int frame, int x, int y)
{
xPos = x;
yPos = y;
updatePos(unitValue, frame, x, y);
}
public void movingPos(int x, int y)
{
xPos = x;
yPos = y;
}
public void savePosAfterMove(int frame)
{
updatePos(unitID, frame, xPos,yPos);
}
public int getScale(int unitValue, int frame)
{
return unitSize /20;
}
private void updatePos(int unitValue, int frame, int x, int y)
{
xPos = x;
yPos = y;
time.updatePos(unitValue, frame, x, y);
}
public void setUnitName(int unitID, String name)
{
unitName = name;
time.setName(unitID,name);
}
public String getUnitName(int unitID)
{
return time.getName(unitID);
}
public int getTroopCount()
{
return unitSize;
//return time.readPosAtTime(unitValue, frame)[2];
}
public int getFaction()
{
return faction;
}
public void swapFaction(int unitID)
{
if (faction == 0)
faction = 1;
else
faction = 0;
time.setFaction(unitID, faction);
}
//initialises all of the necessary instance variables.
public void firstTimeSetup(int unitID, int frame)
{
getPosFromXML(unitID, frame);
getNameFromXML(unitID);
getFactionFromXML(unitID);
getShapeFromXML(unitID);
getTroopCountFromXML(unitID);
}
private void getPosFromXML(int unitID, int frame)
{
int[] temp = new int[2];
temp = time.readPosAtTime(unitID, frame);
xPos = temp[0];
yPos = temp[1];
}
private void getNameFromXML(int unitID)
{
unitName = time.getName(unitID);
}
private void getFactionFromXML(int unitID)
{
faction = time.getFaction(unitID);
}
private void getShapeFromXML(int unitID)
{
shapeType = time.getUnitType(unitID);
}
private void getTroopCountFromXML(int unitID)
{
unitSize = time.getTroopCount(unitID);
}
}
class Time {
//solution, can keep track of keyframes within array, and then can check
//if the xml value exists in said array
private XML xml;
public Time()
{
}
public void createFrame(int frame)
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+frame);
if(children.length == 0)
{
xml.addChild("frame"+frame);
saveXML(xml, "xmldoc.XML");
}
}
public int[] readPosAtTime(int unitID, int frame)
{
int[] posArray = new int[3];
xml = loadXML("xmldoc.XML");
XML[] children = xml.getChildren("frame" + frame);
XML child = children[0].getChild("unit" + unitID);
if(child != null)
{
XML pos = child.getChild("position");
posArray[0] = pos.getInt("x");
posArray[1] = pos.getInt("y");
XML count = child.getChild("troopCount");
posArray[2] = count.getInt("size");
return posArray;
}
int[] temp = {0,0,0};
return temp;
}
//store unit type in XML
public void writeUnitType(int unitID, String unitShape)
{
xml = loadXML("xmldoc.XML");
XML[] children = xml.getChildren("frame1");
XML child = children[0].getChild("unit" + unitID);
child.addChild("unitType");
XML unitType = child.getChild("unitType");
unitType.setString("type", unitShape);
saveXML(xml, "xmldoc.XML");
}
public String getUnitType(int unitID)
{
xml = loadXML("xmldoc.XML");
XML[] children = xml.getChildren("frame1");
XML child = children[0].getChild("unit" + unitID);
XML unitType = child.getChild("unitType");
String type = unitType.getString("type");
return type;
}
//creates the unit fully, includes all of the required info
public void createUnit(int unitID,int maxFrame, int x, int y, String unitType, int troopSize, int faction)
{
for(int i = 1; i < maxFrame; i++)
{
if(checkKeyFrame(i))
{
writePos(unitID, i, x,y,troopSize);
}
}
writeUnitType(unitID, unitType);
setFaction(unitID, faction);
}
public void writePos(int unitID, int frame, int x, int y, int size)
{
xml = loadXML("xmldoc.XML");
XML[] children = xml.getChildren("frame" + frame);
if(children[0].getChild("unit" + unitID) == null)
{
children[0].addChild("unit" + unitID);
XML child = children[0].getChild("unit" + unitID);
child.addChild("troopCount");
child.addChild("position");
XML pos = child.getChild("position");
pos.setInt("x", x);
pos.setInt("y", y);
XML troop = child.getChild("troopCount");
troop.setInt("size",size);
}
saveXML(xml, "xmldoc.XML");
}
public void updatePos(int unitID, int frame, int x, int y)
{
xml = loadXML("xmldoc.XML");
XML[] children = xml.getChildren("frame"+frame);
XML child = children[0].getChild("unit"+unitID);
XML pos = child.getChild("position");
pos.setInt("x", x);
pos.setInt("y", y);
saveXML(xml, "xmldoc.XML");
}
//frame 1 is always a keyframe
public void firstFrameKeyFrame()
{
if(!checkKeyFrame(1))
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+1);
children[0].addChild("keyframe");
saveXML(xml, "xmldoc.XML");
}
}
public void makeKeyFrame(int frame)
{
if(!checkKeyFrame(frame))
{
int previousFrame = getPreviousKeyFrame(frame);
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+frame);
children[0].addChild("keyframe");
saveXML(xml, "xmldoc.XML");
savePositionAsPreviousKeyFrame(frame, previousFrame);
}
}
//stores all of the potions from last keyframe in current keyframe
private void savePositionAsPreviousKeyFrame(int frame, int previousFrame)
{
int[] posArray = new int[3];
int i = 0;
while(checkUnitExists(i, previousFrame))
{
posArray = readPosAtTime(i, previousFrame);
writePos(i, frame, posArray[0], posArray[1], posArray[2]);
i++;
}
}
//checks if the frame is a keyframe
public boolean checkKeyFrame(int frame)
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+frame);
XML child = children[0].getChild("keyframe");
if(child != null)
{
return true;
}
return false;
}
//check if unit exists in xmldocument
public boolean checkUnitExists(int unitID, int frame)
{
try
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+frame);
XML child = children[0].getChild("unit" + unitID);
if(child != null)
{
return true;
}
}
catch(ArrayIndexOutOfBoundsException e)
{
print("Exception Caught");
return false;
}
return false;
}
public void removeUnitAllFrames(int unitID, int maxFrame)
{
xml = loadXML("xmldoc.XML");
while(checkNextKeyFrame(1,maxFrame) != 0)
{
int temp = checkNextKeyFrame(1,maxFrame);
XML children[] = xml.getChildren("frame"+temp);
XML child = children[0].getChild("unit" + unitID);
children[0].removeChild(child);
saveXML(xml, "xmlDoc.XML");
}
}
public int[] interpolate(int unitID, int frame, int maxFrame)
{
int pastFrame = checkPreviousKeyFrame(frame);
int nextFrame = checkNextKeyFrame(frame, maxFrame);
//shouldn't ever be 0, because frame 1 is always a keyframe
int[] temp = new int[2];
if(pastFrame != 0 && nextFrame != 0)
{
int[] pastPos = readPosAtTime(unitID, pastFrame);
int[] nextPos = readPosAtTime(unitID, nextFrame);
int frameDifference = nextFrame - pastFrame;
int xDifference = nextPos[0] - pastPos[0];
int yDifference = nextPos[1] - pastPos[1];
int xChangePerFrame = xDifference/frameDifference;
int yChangePerFrame = yDifference/frameDifference;
temp[0] = pastPos[0] + (xChangePerFrame * (frame - pastFrame));
temp[1] = pastPos[1] + (yChangePerFrame * (frame - pastFrame));
return temp;
}
return temp;
}
public int getPreviousKeyFrame(int frame)
{
for(int i = frame; i > 0; i--)
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+i);
XML child = children[0].getChild("keyframe");
//if not null, it's position is stored and therefore a keyframe
if(child != null)
{
return i;
}
}
return 0;
}
//gets value of keyframe previously
private int checkPreviousKeyFrame(int frame)
{
for(int i = frame; i > 0; i--)
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+i);
XML child = children[0].getChild("keyframe");
//if not null, it's position is stored and therefore a keyframe
if(child != null)
{
return i;
}
}
return 0;
}
public int checkNextKeyFrame(int frame, int maxFrame)
{
for(int i = frame; i < maxFrame; i++)
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame"+i);
XML child = children[0].getChild("keyframe");
//if not null, it's position is stored and therefore a keyframe
if(child != null)
{
return i;
}
}
return 0;
}
public void setFaction(int unitID, int factionValue)
{
xml = loadXML("xmldoc.XML");
XML children[] = xml.getChildren("frame1");
XML child = children[0].getChild("unit"+ unitID);
XML faction = child.getChild("faction");
if(faction == null)
{
child.addChild("faction");