-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOptions.pde
1727 lines (1477 loc) · 59.1 KB
/
Options.pde
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
//================================================================================================
// Author: Carly Smith
//
// Manages the save data xml file containing application options.
//================================================================================================
//------------------------------------------------------------------------------------------------
// INTERFACE
// The options object is a container for four inner objects which each handle
// different sections of the options XML file.
//------------------------------------------------------------------------------------------------
public interface IOptions
{
public IGameOptions getGameOptions();
public IIOOptions getIOOptions();
public IStats getStats();
public ICustomizeOptions getCustomizeOptions();
public ICredits getCredits();
public IUserInformation getUserInformation();
public ICalibrationData getCalibrationData();
public IFittsLawOptions getFittsLawOptions();
public IStory getStory();
public void setSaveDataFiles(String _saveDataFileIn, String _saveDataFileOut);
}
enum ControlPolicy
{
NORMAL,
DIRECTION_ASSIST,
SINGLE_MUSCLE,
}
enum DirectionAssistMode
{
LEFT_ONLY,
RIGHT_ONLY,
BOTH,
}
enum SingleMuscleMode
{
AUTO_LEFT,
AUTO_RIGHT,
}
enum BreakthroughMode
{
WAIT_2SEC,
CO_CONTRACTION,
}
public interface IGameOptions
{
public int getStartingLevel();
public boolean getLevelUpOverTime();
public ControlPolicy getControlPolicy();
public DirectionAssistMode getDirectionAssistMode();
public SingleMuscleMode getSingleMuscleMode();
public boolean getObstacles();
public boolean getPlatformMods();
public float getLowAvgSpeedThreshold();
public float getHighAvgSpeedThreshold();
public boolean isFittsLaw();
public boolean isInputPlatforms();
public boolean isLogFitts();
public boolean isStillPlatforms();
public boolean isLogRawData();
public BreakthroughMode getBreakthroughMode();
public int getDwellTime();
public void setStartingLevel(int startingLevel);
public void setLevelUpOverTime(boolean levelUpOverTime);
public void setControlPolicy(ControlPolicy policy);
public void setDirectionAssistMode(DirectionAssistMode mode);
public void setSingleMuscleMode(SingleMuscleMode mode);
public void setObstacles(boolean obstacles);
public void setPlatformMods(boolean platformMods);
public void setFittsLaw(boolean _fittsLaw);
public void setInputPlatforms(boolean _inputPlatforms);
public void setLogFitts(boolean _logFitts);
public void setStillPlatforms(boolean _stillplatforms);
public void setLogRawData(boolean _logRawData);
public void setBreakthroughMode(BreakthroughMode _mode);
public void setDwellTime(int _dwellTime);
}
enum EmgSamplingPolicy
{
DIFFERENCE,
MAX,
FIRST_OVER,
}
public interface IIOOptions
{
public float getMusicVolume();
public float getSoundEffectsVolume();
public EmgSamplingPolicy getEmgSamplingPolicy();
public Forearm getForearm();
public void setMusicVolume(float volume);
public void setSoundEffectsVolume(float volume);
public void setEmgSamplingPolicy(EmgSamplingPolicy policy);
public void setForearm(Forearm _myoForearm);
}
public interface IStats
{
public ArrayList<IGameRecord> getGameRecords();
public IGameRecord createGameRecord();
public void addGameRecord(IGameRecord record);
public void clear();
public int getHighScore();
public void setHighScore(int _highScore);
}
public interface IGameRecord
{
public Comparator<IGameRecord> createByLevelAchievedComparator();
public Comparator<IGameRecord> createByScoreAchievedComparator();
public Comparator<IGameRecord> createByTimePlayedComparator();
public Comparator<IGameRecord> createByAverageSpeedComparator();
public Comparator<IGameRecord> createByCoinsCollectedComparator();
public Comparator<IGameRecord> createByDateComparator();
public int getLevelAchieved();
public int getScoreAchieved();
public int getTimePlayed();
public float getAverageSpeed();
public int getCoinsCollected();
public long getDate();
public boolean isFittsLawMode();
public void setLevelAchieved(int levelAchieved);
public void setScoreAchieved(int scoreAchieved);
public void setTimePlayed(int timePlayed);
public void setAverageSpeed(float averageSpeed);
public void setCoinsCollected(int coinsCollected);
public void setDate(long date);
public void setIsFittsLawMode(boolean fittsLaw);
}
public interface ICustomizeOptions
{
public int getCoinsCollected();
public String getBackground();
public String getOpacityBackground();
public String[] getMusicOptions();
public void setCoinsCollected(int _newCoins);
public void setCoinsAfterPurchase(int _price);
public void setPlayer(int _newActivePlayerIndex);
public void setPlatform(int _newActivePlatformIndex, int _id);
public void setCoin(int _newActiveCoinIndex, int _id);
public void setObstacle(int _newActiveObstacleIndex, int _id);
public void setBackground(int _newActiveBackgroundIndex, int _id);
public void setMusic(int _newActiveMusicIndex, int _id);
public void purchase(int _custSpriteIndex);
public void preparePurchaseScreen(int _custSpriteIndex, RenderComponent renderComponent);
public void reset();
public void loadSavedSettings();
public boolean hasEnoughCoinsToBuySomething();
}
public interface IGameRecordViewHelper
{
public String getLevelAchieved();
public String getScoreAchieved();
public String getTimePlayed();
public String getAverageSpeed();
public String getCoinsCollected();
public String getDate();
}
public interface ICredits
{
public boolean isAnonymous();
}
public interface IUserInformation
{
public void getDefaultSetting();
public boolean setSaveDataFile(String loginID);
public String getUserID();
}
public interface ICalibrationData
{
public void setCalibrationFile(String loginID);
public String getCalibrationFile();
public HashMap<String, float[]> getCalibrationData();
public float getLeftReading();
public float getRightReading();
public float getLeftSensitivity();
public float getRightSensitivity();
}
public interface IFittsLawOptions
{
public String getInputFile();
public String getBonusFile();
}
public interface IStory
{
public boolean getShow();
public void setShow(boolean _show);
}
//------------------------------------------------------------------------------------------------
// IMPLEMENTATION
//------------------------------------------------------------------------------------------------
public class Options implements IOptions
{
private String SAVE_DATA_FILE_NAME_IN = "xml_data/save_data.xml";
private String SAVE_DATA_FILE_NAME_OUT = "data/xml_data/save_data.xml";
private final String SAVE_DATA_DEFAULT_FILE = "xml_data/default_save_data.xml";
private XML xmlSaveData;
private XML xmldefaultData;
private IGameOptions gameOptions;
private IStats stats;
private IIOOptions IOOptions;
private ICustomizeOptions customizeOptions;
private ICredits credits;
private IUserInformation userInfo;
private ICalibrationData calibrationData;
private IFittsLawOptions fittsLawOptions;
private IStory story;
public Options()
{
xmldefaultData = loadXML(SAVE_DATA_DEFAULT_FILE);
userInfo = new UserInformation();
xmlSaveData = loadXML(SAVE_DATA_FILE_NAME_IN);
gameOptions = new GameOptions();
stats = new Stats();
IOOptions = new IOOptions();
customizeOptions = new CustomizeOptions();
credits = new Credits();
calibrationData = new CalibrationData();
fittsLawOptions = new FittsLawOptions();
story = new Story();
}
public void reloadOptions()
{
xmlSaveData = loadXML(SAVE_DATA_FILE_NAME_IN);
gameOptions = new GameOptions();
stats = new Stats();
IOOptions = new IOOptions();
customizeOptions = new CustomizeOptions();
credits = new Credits();
calibrationData = new CalibrationData();
story = new Story();
}
@Override public IGameOptions getGameOptions()
{
return gameOptions;
}
@Override public IStats getStats()
{
return stats;
}
@Override public IIOOptions getIOOptions()
{
return IOOptions;
}
@Override public ICustomizeOptions getCustomizeOptions()
{
return customizeOptions;
}
@Override public ICredits getCredits()
{
return credits;
}
@Override public IUserInformation getUserInformation()
{
return userInfo;
}
@Override public IFittsLawOptions getFittsLawOptions()
{
return fittsLawOptions;
}
@Override public ICalibrationData getCalibrationData()
{
return calibrationData;
}
@Override public IStory getStory()
{
return story;
}
public void setSaveDataFiles(String _saveDataFileIn, String _saveDataFileOut)
{
SAVE_DATA_FILE_NAME_IN = _saveDataFileIn;
SAVE_DATA_FILE_NAME_OUT = _saveDataFileOut;
}
//--------------------------------------------
// GAME OPTIONS
//--------------------------------------------
public class GameOptions implements IGameOptions
{
private final String XML_GAME = "Game";
private final String STARTING_LEVEL = "starting_level";
private final String LEVEL_UP_OVER_TIME = "level_up_over_time";
private final String CONTROL_POLICY = "control_policy";
private final String DIRECTION_ASSIST_MODE = "direction_assist_mode";
private final String SINGLE_MUSCLE_MODE = "single_muscle_mode";
private final String OBSTACLES = "obstacles";
private final String PLATFORM_MODS = "platform_mods";
private final String LOW_AVG_SPEED_THRESHOLD = "low_avg_speed_threshold";
private final String HIGH_AVG_SPEED_THRESHOLD = "high_avg_speed_threshold";
private final String FITTS_LAW = "fitts_law";
private final String INPUT_PLATFORM = "input_platform";
private final String LOG_FITTS = "log_fitts";
private final String STILL_PLATFORM = "still_platform";
private final String LOG_RAW_DATA = "log_raw_data";
private final String BREAKTHROUGH_MODE = "breakthrough_mode";
private XML xmlGame;
private int startingLevel;
private boolean levelUpOverTime;
private ControlPolicy controlPolicy;
private DirectionAssistMode directionAssistMode;
private SingleMuscleMode singleMuscleMode;
private boolean obstacles;
private boolean platformMods;
private float lowAvgSpeedThreshold;
private float highAvgSpeedThreshold;
private BreakthroughMode breakMode;
private boolean fittsLaw;
private boolean inputPlatformGaps;
private boolean logFittsLaw;
private boolean stillPlatforms;
private boolean logRawData;
private GameOptions()
{
xmlGame = xmlSaveData.getChild(XML_GAME);
startingLevel = xmlGame.getInt(STARTING_LEVEL);
levelUpOverTime = xmlGame.getString(LEVEL_UP_OVER_TIME).equals("true") ? true : false;
obstacles = xmlGame.getString(OBSTACLES).equals("true") ? true : false;
platformMods = xmlGame.getString(PLATFORM_MODS).equals("true") ? true : false;
lowAvgSpeedThreshold = xmlGame.getFloat(LOW_AVG_SPEED_THRESHOLD);
highAvgSpeedThreshold = xmlGame.getFloat(HIGH_AVG_SPEED_THRESHOLD);
fittsLaw = xmlGame.getString(FITTS_LAW).equals("true") ? true : false;
inputPlatformGaps = xmlGame.getString(INPUT_PLATFORM).equals("true") ? true : false;
logFittsLaw = xmlGame.getString(LOG_FITTS).equals("true") ? true : false;
stillPlatforms = xmlGame.getString(STILL_PLATFORM).equals("true") ? true : false;
logRawData = xmlGame.getString(LOG_RAW_DATA).equals("true") ? true : false;
switch (xmlGame.getString(CONTROL_POLICY))
{
case ("normal"):
controlPolicy = ControlPolicy.NORMAL; break;
case ("direction_assist"):
controlPolicy = ControlPolicy.DIRECTION_ASSIST; break;
case ("single_muscle"):
controlPolicy = ControlPolicy.SINGLE_MUSCLE; break;
default:
println("[ERROR] Invalid control policy specified while parsing game options.");
break;
}
switch (xmlGame.getString(DIRECTION_ASSIST_MODE))
{
case ("left_only"):
directionAssistMode = DirectionAssistMode.LEFT_ONLY; break;
case ("right_only"):
directionAssistMode = DirectionAssistMode.RIGHT_ONLY; break;
case ("both"):
directionAssistMode = DirectionAssistMode.BOTH; break;
default:
println("[ERROR] Invalid direction assist mode specified while parsing game options.");
break;
}
switch (xmlGame.getString(SINGLE_MUSCLE_MODE))
{
case ("auto_left"):
singleMuscleMode = SingleMuscleMode.AUTO_LEFT; break;
case ("auto_right"):
singleMuscleMode = SingleMuscleMode.AUTO_RIGHT; break;
default:
println("[ERROR] Invalid single muscle mode specified while parsing game options.");
break;
}
switch (xmlGame.getString(BREAKTHROUGH_MODE))
{
case ("wait_2sec"):
breakMode = BreakthroughMode.WAIT_2SEC; break;
case ("jump_3times"):
breakMode = BreakthroughMode.CO_CONTRACTION; break;
default:
println("[ERROR] Invalid Breakthrough mode for Fitts Law whil parsing Game Optoins .");
break;
}
}
@Override public int getStartingLevel()
{
return startingLevel;
}
@Override public boolean getLevelUpOverTime()
{
return levelUpOverTime;
}
public ControlPolicy getControlPolicy()
{
return controlPolicy;
}
public DirectionAssistMode getDirectionAssistMode()
{
return directionAssistMode;
}
public SingleMuscleMode getSingleMuscleMode()
{
return singleMuscleMode;
}
@Override public boolean getObstacles()
{
return obstacles;
}
@Override public boolean getPlatformMods()
{
return platformMods;
}
public float getLowAvgSpeedThreshold()
{
return lowAvgSpeedThreshold;
}
public float getHighAvgSpeedThreshold()
{
return highAvgSpeedThreshold;
}
@Override public boolean isFittsLaw()
{
return fittsLaw;
}
@Override public boolean isInputPlatforms()
{
return inputPlatformGaps;
}
@Override public boolean isLogFitts()
{
return logFittsLaw;
}
@Override public boolean isStillPlatforms()
{
return stillPlatforms;
}
@Override public boolean isLogRawData()
{
return logRawData;
}
@Override public BreakthroughMode getBreakthroughMode()
{
return breakMode;
}
@Override public int getDwellTime() {
return 2;
}
@Override public void setStartingLevel(int _startingLevel)
{
startingLevel = _startingLevel;
xmlGame.setInt(STARTING_LEVEL, startingLevel);
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setLevelUpOverTime(boolean _levelUpOverTime)
{
levelUpOverTime = _levelUpOverTime;
xmlGame.setString(LEVEL_UP_OVER_TIME, levelUpOverTime ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public void setControlPolicy(ControlPolicy policy)
{
controlPolicy = policy;
if (controlPolicy == ControlPolicy.NORMAL)
xmlGame.setString(CONTROL_POLICY, "normal");
else if (controlPolicy == ControlPolicy.DIRECTION_ASSIST)
xmlGame.setString(CONTROL_POLICY, "direction_assist");
else if (controlPolicy == ControlPolicy.SINGLE_MUSCLE)
xmlGame.setString(CONTROL_POLICY, "single_muscle");
else
println("[ERROR] Unrecognized control policy specified in GameOptions::setControlPolicy()");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public void setDirectionAssistMode(DirectionAssistMode mode)
{
directionAssistMode = mode;
if (directionAssistMode == DirectionAssistMode.LEFT_ONLY)
xmlGame.setString(DIRECTION_ASSIST_MODE, "left_only");
else if (directionAssistMode == DirectionAssistMode.RIGHT_ONLY)
xmlGame.setString(DIRECTION_ASSIST_MODE, "right_only");
else if (directionAssistMode == DirectionAssistMode.BOTH)
xmlGame.setString(DIRECTION_ASSIST_MODE, "both");
else
println("[ERROR] Unrecognized direction assist mode specified in GameOptions::setDirectionAssistMode()");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public void setSingleMuscleMode(SingleMuscleMode mode)
{
singleMuscleMode = mode;
if (singleMuscleMode == SingleMuscleMode.AUTO_LEFT)
xmlGame.setString(SINGLE_MUSCLE_MODE, "auto_left");
else if (singleMuscleMode == SingleMuscleMode.AUTO_RIGHT)
xmlGame.setString(SINGLE_MUSCLE_MODE, "auto_right");
else
println("[ERROR] Unrecognized single muscle mode specified in GameOptions::setSingleMuscleMode()");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setObstacles(boolean _obstacles)
{
obstacles = _obstacles;
xmlGame.setString(OBSTACLES, obstacles ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setPlatformMods(boolean _platformMods)
{
platformMods = _platformMods;
xmlGame.setString(PLATFORM_MODS, platformMods ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setFittsLaw(boolean _fittsLaw)
{
fittsLaw = _fittsLaw;
xmlGame.setString(FITTS_LAW, fittsLaw ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setInputPlatforms(boolean _inputPlatforms)
{
inputPlatformGaps = _inputPlatforms;
xmlGame.setString(INPUT_PLATFORM, inputPlatformGaps ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setLogFitts(boolean _logFitts)
{
logFittsLaw = _logFitts;
xmlGame.setString(LOG_FITTS, logFittsLaw ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setStillPlatforms(boolean _stillPlatform)
{
stillPlatforms = _stillPlatform;
xmlGame.setString(STILL_PLATFORM, stillPlatforms ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setLogRawData(boolean _logRawData)
{
logRawData = _logRawData;
xmlGame.setString(LOG_RAW_DATA, logRawData ? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setBreakthroughMode(BreakthroughMode _mode)
{
breakMode = _mode;
if (breakMode == BreakthroughMode.WAIT_2SEC)
xmlGame.setString(BREAKTHROUGH_MODE, "wait_2sec");
else if (breakMode == BreakthroughMode.CO_CONTRACTION)
xmlGame.setString(BREAKTHROUGH_MODE, "jump_3times");
else
println("[ERROR] Unrecognized single muscle mode specified in GameOptions::setSingleMuscleMode()");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setDwellTime(int _dwellTime) {
// no-op: we don't really care about this anymore -- we don't want the ability to change this.
// TODO: completly remove dead code from project
}
}
//--------------------------------------------
// IO OPTIONS
//--------------------------------------------
public class IOOptions implements IIOOptions
{
private final String XML_IO = "IO";
private final String MUSIC_VOLUME = "music_volume";
private final String SOUND_EFFECTS_VOLUME = "sound_effects_volume";
private final String EMG_SAMPLING_POLICY = "emg_sampling_policy";
private final String THRESHOLD = "min_input_threshold";
private final String MYO_FOREARM = "myo_forearm";
private XML xmlIO;
private float musicVolume;
private float soundEffectsVolume;
private EmgSamplingPolicy emgSamplingPolicy;
private Forearm myoForearm;
private IOOptions()
{
xmlIO = xmlSaveData.getChild(XML_IO);
musicVolume = xmlIO.getFloat(MUSIC_VOLUME);
soundEffectsVolume = xmlIO.getFloat(SOUND_EFFECTS_VOLUME);
switch (xmlIO.getString(EMG_SAMPLING_POLICY))
{
case ("max"):
emgSamplingPolicy = EmgSamplingPolicy.MAX; break;
case ("difference"):
emgSamplingPolicy = EmgSamplingPolicy.DIFFERENCE; break;
case ("first_over"):
emgSamplingPolicy = EmgSamplingPolicy.FIRST_OVER; break;
default:
println("[ERROR] Unrecognized emg sampling policy while parsing IOOptions");
break;
}
myoForearm = xmlIO.getString(MYO_FOREARM).equals("left") ? Forearm.LEFT : Forearm.RIGHT;
}
@Override public float getMusicVolume()
{
return musicVolume;
}
@Override public float getSoundEffectsVolume()
{
return soundEffectsVolume;
}
public EmgSamplingPolicy getEmgSamplingPolicy()
{
return emgSamplingPolicy;
}
public Forearm getForearm()
{
return myoForearm;
}
@Override public void setMusicVolume(float volume)
{
musicVolume = volume / 100.0f;
xmlIO.setFloat(MUSIC_VOLUME, musicVolume);
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void setSoundEffectsVolume(float volume)
{
soundEffectsVolume = volume / 100.0f;
xmlIO.setFloat(SOUND_EFFECTS_VOLUME, soundEffectsVolume);
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public void setEmgSamplingPolicy(EmgSamplingPolicy policy)
{
emgSamplingPolicy = policy;
if (emgSamplingPolicy == EmgSamplingPolicy.MAX)
xmlIO.setString(EMG_SAMPLING_POLICY, "max");
else if (emgSamplingPolicy == EmgSamplingPolicy.DIFFERENCE)
xmlIO.setString(EMG_SAMPLING_POLICY, "difference");
else if (emgSamplingPolicy == EmgSamplingPolicy.FIRST_OVER)
xmlIO.setString(EMG_SAMPLING_POLICY, "first_over");
else
println("[ERROR] Unrecognized emg sampling policy in IOOptions::setEmgSamplingPolicy()");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public void setForearm(Forearm _myoForearm)
{
String arm = (_myoForearm == Forearm.LEFT) ? "left" : "right";
xmlIO.setString(MYO_FOREARM, arm);
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
myoForearm = _myoForearm;
}
}
//--------------------------------------------
// STATS OPTIONS
//--------------------------------------------
public class Stats implements IStats
{
public class GameRecord implements IGameRecord
{
private int levelAchieved;
private int scoreAchieved;
private int timePlayed;
private float averageSpeed;
private int coinsCollected;
private long date;
private boolean isFittsLaw;
public GameRecord()
{
levelAchieved = -1;
scoreAchieved = -1;
timePlayed = -1;
averageSpeed = -1.0f;
coinsCollected = -1;
date = -1;
isFittsLaw = false;
}
@Override public Comparator<IGameRecord> createByLevelAchievedComparator()
{
return new ByLevelAchievedComparator();
}
@Override public Comparator<IGameRecord> createByScoreAchievedComparator()
{
return new ByScoreAchievedComparator();
}
@Override public Comparator<IGameRecord> createByTimePlayedComparator()
{
return new ByTimePlayedComparator();
}
@Override public Comparator<IGameRecord> createByAverageSpeedComparator()
{
return new ByAverageSpeedComparator();
}
@Override public Comparator<IGameRecord> createByCoinsCollectedComparator()
{
return new ByCoinsCollectedComparator();
}
@Override public Comparator<IGameRecord> createByDateComparator()
{
return new ByDateComparator();
}
@Override public int getLevelAchieved()
{
return levelAchieved;
}
@Override public int getScoreAchieved()
{
return scoreAchieved;
}
@Override public int getTimePlayed()
{
return timePlayed;
}
@Override public float getAverageSpeed()
{
return averageSpeed;
}
@Override public int getCoinsCollected()
{
return coinsCollected;
}
@Override public long getDate()
{
return date;
}
@Override public boolean isFittsLawMode()
{
return isFittsLaw;
}
@Override public void setLevelAchieved(int _levelAchieved)
{
levelAchieved = _levelAchieved;
}
@Override public void setScoreAchieved(int _scoreAchieved)
{
scoreAchieved = _scoreAchieved;
}
@Override public void setTimePlayed(int _timePlayed)
{
timePlayed = _timePlayed;
}
@Override public void setAverageSpeed(float _averageSpeed)
{
averageSpeed = _averageSpeed;
}
@Override public void setCoinsCollected(int _coinsCollected)
{
coinsCollected = _coinsCollected;
}
@Override public void setDate(long _date)
{
date = _date;
}
@Override public void setIsFittsLawMode(boolean _fittsLaw)
{
isFittsLaw = _fittsLaw;
}
}
private final String XML_STATS = "Stats";
private final String XML_RECORD = "Record";
private final String XML_LEVEL_ACHIEVED = "level";
private final String XML_SCORE_ACHIEVED = "score";
private final String XML_TIME_PLAYED = "time_played_millis";
private final String XML_AVERAGE_SPEED = "avg_speed";
private final String XML_COINS_COLLECTED = "coins_collected";
private final String XML_DATE = "date";
private final String XML_HIGH_SCORE = "high_score";
private final String XML_FITTS_LAW = "fitts_law";
private XML xmlStats;
private ArrayList<IGameRecord> gameRecords;
private int highScore;
private Stats()
{
xmlStats = xmlSaveData.getChild(XML_STATS);
highScore = xmlStats.getInt(XML_HIGH_SCORE);
gameRecords = new ArrayList<IGameRecord>();
for (XML xmlRecord : xmlStats.getChildren())
{
if (xmlRecord.getName().equals(XML_RECORD))
{
IGameRecord record = new GameRecord();
record.setLevelAchieved(xmlRecord.getInt(XML_LEVEL_ACHIEVED));
record.setScoreAchieved(xmlRecord.getInt(XML_SCORE_ACHIEVED));
record.setTimePlayed(xmlRecord.getInt(XML_TIME_PLAYED));
record.setAverageSpeed(xmlRecord.getFloat(XML_AVERAGE_SPEED));
record.setCoinsCollected(xmlRecord.getInt(XML_COINS_COLLECTED));
record.setDate(Long.parseLong(xmlRecord.getString(XML_DATE)));
record.setIsFittsLawMode(xmlRecord.getString(XML_FITTS_LAW).equals("true")? true : false);
gameRecords.add(record);
}
}
}
@Override public ArrayList<IGameRecord> getGameRecords()
{
return gameRecords;
}
@Override public IGameRecord createGameRecord()
{
return new GameRecord();
}
@Override public void addGameRecord(IGameRecord record)
{
gameRecords.add(record);
XML xmlRecord = xmlStats.addChild(XML_RECORD);
xmlRecord.setInt(XML_LEVEL_ACHIEVED, record.getLevelAchieved());
xmlRecord.setInt(XML_SCORE_ACHIEVED, record.getScoreAchieved());
xmlRecord.setInt(XML_TIME_PLAYED, record.getTimePlayed());
xmlRecord.setFloat(XML_AVERAGE_SPEED, record.getAverageSpeed());
xmlRecord.setInt(XML_COINS_COLLECTED, record.getCoinsCollected());
xmlRecord.setString(XML_DATE, Long.toString(record.getDate()));
xmlRecord.setString(XML_FITTS_LAW, record.isFittsLawMode()? "true" : "false");
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
@Override public void clear()
{
gameRecords.clear();
for (String childName : xmlStats.listChildren())
{
xmlStats.removeChild(xmlStats.getChild(childName));
}
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public int getHighScore()
{
return highScore;
}
public void setHighScore(int _highScore)
{
highScore = _highScore;
xmlStats.setInt(XML_HIGH_SCORE, highScore);
saveXML(xmlSaveData, SAVE_DATA_FILE_NAME_OUT);
}
public class ByLevelAchievedComparator implements Comparator<IGameRecord>
{
@Override public int compare(IGameRecord g1, IGameRecord g2)
{
return Integer.compare(g1.getLevelAchieved(), g2.getLevelAchieved());
}
}
public class ByScoreAchievedComparator implements Comparator<IGameRecord>
{
@Override public int compare(IGameRecord g1, IGameRecord g2)
{
return Integer.compare(g1.getScoreAchieved(), g2.getScoreAchieved());
}
}
public class ByTimePlayedComparator implements Comparator<IGameRecord>
{
@Override public int compare(IGameRecord g1, IGameRecord g2)
{
return Integer.compare(g1.getTimePlayed(), g2.getTimePlayed());
}
}
public class ByAverageSpeedComparator implements Comparator<IGameRecord>
{
@Override public int compare(IGameRecord g1, IGameRecord g2)
{
return Float.compare(g1.getAverageSpeed(), g2.getAverageSpeed());
}
}
public class ByCoinsCollectedComparator implements Comparator<IGameRecord>
{
@Override public int compare(IGameRecord g1, IGameRecord g2)
{
return Integer.compare(g1.getCoinsCollected(), g2.getCoinsCollected());
}
}
public class ByDateComparator implements Comparator<IGameRecord>
{
@Override public int compare(IGameRecord g1, IGameRecord g2)
{
return Long.compare(g1.getDate(), g2.getDate());
}
}
}
//--------------------------------------------
// CUSTOMIZE OPTIONS
//--------------------------------------------
public class CustomizeOptions implements ICustomizeOptions
{
private final String PLAYER_FILE_NAME_IN = "xml_data/player.xml";
private final String PLAYER_FILE_NAME_OUT = "data/xml_data/player.xml";
private final String PLAYER_BONUS_FILE_NAME_IN = "xml_data/player_bonus.xml";