@@ -35,7 +35,7 @@ public abstract class SerialiserFlavorBase {
35
35
/**
36
36
* Debug subtick field for error handling
37
37
*/
38
- protected Integer currentSubtick = null ;
38
+ protected int currentSubtick = 0 ;
39
39
40
40
public abstract String flavorName ();
41
41
@@ -256,7 +256,7 @@ protected void mergeInputs(BigArrayList<String> out, List<String> serialisedKeyb
256
256
257
257
out .add (String .format ("\t %s|%s|%s|%s" , currentSubtick , kb , ms , ca ));
258
258
}
259
- currentSubtick = null ;
259
+ currentSubtick = 0 ;
260
260
}
261
261
262
262
protected String getOrEmpty (String string ) {
@@ -267,7 +267,7 @@ protected String getOrEmpty(String string) {
267
267
* Joins strings together but ignores empty strings
268
268
*
269
269
* @param delimiter The delimiter of the joined string
270
- * @param args The strings to join
270
+ * @param args The strings to join
271
271
* @return Joined string
272
272
*/
273
273
protected String joinNotEmpty (String delimiter , Iterable <String > args ) {
@@ -302,6 +302,8 @@ protected String joinNotEmpty(String delimiter, String... args) {
302
302
*
303
303
*/
304
304
305
+ private TickContainer previousTickContainer = null ;
306
+
305
307
public boolean deserialiseFlavorName (List <String > headerLines ) {
306
308
for (String line : headerLines ) {
307
309
Matcher matcher = extract ("^Flavor: " + flavorName (), line );
@@ -397,9 +399,11 @@ public BigArrayList<TickContainer> deserialise(BigArrayList<String> lines, long
397
399
List <String > tick = new ArrayList <>();
398
400
// Extract the tick and set the index
399
401
i = extractContainer (tick , lines , i );
402
+ currentTick = i ;
400
403
// Extract container
401
404
deserialiseContainer (out , tick );
402
405
}
406
+ previousTickContainer = null ;
403
407
return out ;
404
408
}
405
409
@@ -456,6 +460,8 @@ protected void deserialiseContainer(BigArrayList<TickContainer> out, List<String
456
460
TASmodRegistry .PLAYBACK_FILE_COMMAND .handleOnDeserialiseInline (currentTick , deserialisedContainer , inlineFileCommands );
457
461
TASmodRegistry .PLAYBACK_FILE_COMMAND .handleOnDeserialiseEndline (currentTick , deserialisedContainer , endlineFileCommands );
458
462
463
+ previousTickContainer = deserialisedContainer ;
464
+
459
465
out .add (deserialisedContainer );
460
466
}
461
467
@@ -503,13 +509,14 @@ protected String deserialiseFileCommands(String comment, List<PlaybackFileComman
503
509
deserialisedFileCommands .add (new PlaybackFileCommand (name , args ));
504
510
comment = matcher .replaceFirst ("" );
505
511
}
506
-
512
+
507
513
return comment ;
508
514
}
509
515
510
516
protected VirtualKeyboard deserialiseKeyboard (List <String > keyboardStrings ) {
511
517
VirtualKeyboard out = new VirtualKeyboard ();
512
518
519
+ currentSubtick = 0 ;
513
520
for (String line : keyboardStrings ) {
514
521
Matcher matcher = extract ("(.*?);(.*)" , line );
515
522
if (matcher .find ()) {
@@ -519,13 +526,18 @@ protected VirtualKeyboard deserialiseKeyboard(List<String> keyboardStrings) {
519
526
int [] keycodes = deserialiseVirtualKey (keys , VirtualKey .ZERO );
520
527
out .updateFromState (keycodes , chars );
521
528
}
529
+ currentSubtick ++;
522
530
}
523
531
return out ;
524
532
}
525
533
526
534
protected VirtualMouse deserialiseMouse (List <String > mouseStrings ) {
527
535
VirtualMouse out = new VirtualMouse ();
528
536
537
+ currentSubtick = 0 ;
538
+ Integer previousCursorX = previousTickContainer == null ? null : previousTickContainer .getMouse ().getCursorX ();
539
+ Integer previousCursorY = previousTickContainer == null ? null : previousTickContainer .getMouse ().getCursorY ();
540
+
529
541
for (String line : mouseStrings ) {
530
542
Matcher matcher = extract ("(.*?);(.+)" , line );
531
543
if (matcher .find ()) {
@@ -538,51 +550,43 @@ protected VirtualMouse deserialiseMouse(List<String> mouseStrings) {
538
550
Integer cursorY ;
539
551
540
552
if (functions .length == 3 ) {
541
- try {
542
- scrollwheel = Integer .parseInt (functions [0 ]);
543
- cursorX = Integer .parseInt (functions [1 ]);
544
- cursorY = Integer .parseInt (functions [2 ]);
545
- } catch (NumberFormatException e ) {
546
- throw new PlaybackLoadException (e );
547
- }
553
+ scrollwheel = parseInt ("scrollwheel" , functions [0 ]);
554
+ cursorX = deserialiseRelativeInt ("cursorX" , functions [1 ], previousCursorX );
555
+ cursorY = deserialiseRelativeInt ("cursorY" , functions [2 ], previousCursorY );
548
556
} else {
549
557
throw new PlaybackLoadException ("Mouse functions do not have the correct length" );
550
558
}
551
559
552
560
out .updateFromState (keycodes , scrollwheel , cursorX , cursorY );
561
+
562
+ previousCursorX = cursorX ;
563
+ previousCursorY = cursorY ;
553
564
}
565
+ currentSubtick ++;
554
566
}
555
567
return out ;
556
568
}
557
569
558
570
protected VirtualCameraAngle deserialiseCameraAngle (List <String > cameraAngleStrings ) {
559
571
VirtualCameraAngle out = new VirtualCameraAngle ();
560
572
573
+ currentSubtick = 0 ;
574
+ Float previousPitch = previousTickContainer == null ? null : previousTickContainer .getCameraAngle ().getPitch ();
575
+ Float previousYaw = previousTickContainer == null ? null : previousTickContainer .getCameraAngle ().getYaw ();
576
+
561
577
for (String line : cameraAngleStrings ) {
562
578
Matcher matcher = extract ("(.+?);(.+)" , line );
563
579
564
580
if (matcher .find ()) {
565
581
String cameraPitchString = matcher .group (1 );
566
582
String cameraYawString = matcher .group (2 );
567
583
568
- float cameraPitch ;
569
- float cameraYaw ;
570
-
571
- if (isFloat (cameraPitchString ))
572
- cameraPitch = Float .parseFloat (cameraPitchString );
573
- else
574
- throw new PlaybackLoadException ("The camera pitch is not valid" );
575
-
576
- if (isFloat (cameraYawString ))
577
- cameraYaw = Float .parseFloat (cameraYawString );
578
- else
579
- throw new PlaybackLoadException ("The camera yaw is not valid" );
584
+ float cameraPitch = deserialiseRelativeFloat ("camera pitch" , cameraPitchString , previousPitch );
585
+ float cameraYaw = deserialiseRelativeFloat ("camera yaw" , cameraYawString , previousYaw );
580
586
581
587
out .updateFromState (cameraPitch , cameraYaw );
582
-
583
- } else {
584
- throw new PlaybackLoadException ("The cameraAngle is not valid" );
585
588
}
589
+ currentSubtick ++;
586
590
}
587
591
return out ;
588
592
}
@@ -614,6 +618,54 @@ protected int[] deserialiseVirtualKey(String[] keyString, VirtualKey defaultKey)
614
618
return out ;
615
619
}
616
620
621
+ protected int parseInt (String name , String intstring ) {
622
+ try {
623
+ return Integer .parseInt (intstring );
624
+ } catch (NumberFormatException e ) {
625
+ throw new PlaybackLoadException (currentTick , currentSubtick , e , "Can't parse integer in %s" , name );
626
+ }
627
+ }
628
+
629
+ protected int deserialiseRelativeInt (String name , String intstring , Integer previous ) {
630
+ int out = 0 ;
631
+ if (intstring .startsWith ("~" )) {
632
+ intstring = intstring .replace ("~" , "" );
633
+ int relative = parseInt (name , intstring );
634
+ if (previous != null ) {
635
+ out = previous + relative ;
636
+ } else {
637
+ throw new PlaybackLoadException (currentTick , currentSubtick , "Can't process relative value ~%s in %s. Previous value for comparing is not available" , intstring , name );
638
+ }
639
+ } else {
640
+ out = parseInt (name , intstring );
641
+ }
642
+ return out ;
643
+ }
644
+
645
+ protected float parseFloat (String name , String floatstring ) {
646
+ try {
647
+ return Float .parseFloat (floatstring );
648
+ } catch (NumberFormatException e ) {
649
+ throw new PlaybackLoadException (currentTick , currentSubtick , e , "Can't parse float in %s" , name );
650
+ }
651
+ }
652
+
653
+ protected float deserialiseRelativeFloat (String name , String floatstring , Float previous ) {
654
+ float out = 0 ;
655
+ if (floatstring .startsWith ("~" )) {
656
+ floatstring = floatstring .replace ("~" , "" );
657
+ float relative = parseFloat (name , floatstring );
658
+ if (previous != null ) {
659
+ out = previous + relative ;
660
+ } else {
661
+ throw new PlaybackLoadException (currentTick , currentSubtick , "Can't process relative value ~%s in %s. Previous value for comparing is not available" , floatstring , name );
662
+ }
663
+ } else {
664
+ out = parseFloat (name , floatstring );
665
+ }
666
+ return out ;
667
+ }
668
+
617
669
protected void splitInputs (List <String > lines , List <String > serialisedKeyboard , List <String > serialisedMouse , List <String > serialisedCameraAngle , List <String > commentsAtEnd , List <List <PlaybackFileCommand >> endlineFileCommands ) {
618
670
619
671
for (String line : lines ) {
@@ -635,10 +687,10 @@ protected void splitInputs(List<String> lines, List<String> serialisedKeyboard,
635
687
List <PlaybackFileCommand > deserialisedFileCommands = new ArrayList <>();
636
688
String endlineComment = line .substring (tickMatcher .group (0 ).length ());
637
689
commentsAtEnd .add (deserialiseEndlineComment (endlineComment , deserialisedFileCommands ));
638
-
639
- if (deserialisedFileCommands .isEmpty ())
690
+
691
+ if (deserialisedFileCommands .isEmpty ())
640
692
deserialisedFileCommands = null ;
641
-
693
+
642
694
endlineFileCommands .add (deserialisedFileCommands );
643
695
}
644
696
}
0 commit comments