2121import com .minecrafttas .tasmod .playback .metadata .PlaybackMetadata ;
2222import com .minecrafttas .tasmod .playback .tasfile .exception .PlaybackLoadException ;
2323import com .minecrafttas .tasmod .registries .TASmodAPIRegistry ;
24+ import com .minecrafttas .tasmod .virtual .Subtickable ;
2425import com .minecrafttas .tasmod .virtual .VirtualCameraAngle ;
2526import com .minecrafttas .tasmod .virtual .VirtualKey ;
2627import com .minecrafttas .tasmod .virtual .VirtualKeyboard ;
@@ -90,6 +91,7 @@ protected void serialiseFileCommandNames(List<String> out) {
9091 List <PlaybackFileCommandExtension > extensionList = TASmodAPIRegistry .PLAYBACK_FILE_COMMAND .getEnabled ();
9192 extensionList .forEach (extension -> stringlist .add (extension .getExtensionName ()));
9293 out .add ("FileCommand-Extensions: " + String .join (", " , stringlist ));
94+ out .add ("" );
9395 }
9496
9597 protected void serialiseMetadata (List <String > out ) {
@@ -122,14 +124,17 @@ public BigArrayList<String> serialise(BigArrayList<TickContainer> inputs, long t
122124 currentTick = i ;
123125 TickContainer container = inputs .get (i );
124126 serialiseContainer (out , container );
127+ previousTickContainer = container ;
125128 }
126129 return out ;
127130 }
128131
129132 protected void serialiseContainer (BigArrayList <String > out , TickContainer container ) {
133+ currentLine = out .size ()-1 ;
130134 List <String > serialisedKeyboard = serialiseKeyboard (container .getKeyboard ());
131135 List <String > serialisedMouse = serialiseMouse (container .getMouse ());
132136 List <String > serialisedCameraAngle = serialiseCameraAngle (container .getCameraAngle ());
137+ pruneListEndEmpty (serialisedCameraAngle );
133138
134139 PlaybackFileCommandContainer fileCommandsInline = TASmodAPIRegistry .PLAYBACK_FILE_COMMAND .handleOnSerialiseInline (currentTick , container );
135140 PlaybackFileCommandContainer fileCommandsEndline = TASmodAPIRegistry .PLAYBACK_FILE_COMMAND .handleOnSerialiseEndline (currentTick , container );
@@ -163,25 +168,42 @@ protected String serialiseFileCommandsInLine(List<PlaybackFileCommand> fileComma
163168
164169 protected List <String > serialiseKeyboard (VirtualKeyboard keyboard ) {
165170 List <String > out = new ArrayList <>();
166- List <VirtualKeyboard > list = keyboard .getAll ();
167- for (VirtualKeyboard subtick : list ) {
171+
172+ List <VirtualKeyboard > subticks = new ArrayList <>(keyboard .getAll ());
173+ pruneListEndEmptySubtickable (subticks );
174+
175+ for (VirtualKeyboard subtick : subticks ) {
168176 out .add (subtick .toString2 ());
169177 }
170178 return out ;
171179 }
172180
173181 protected List <String > serialiseMouse (VirtualMouse mouse ) {
174182 List <String > out = new ArrayList <>();
175- for (VirtualMouse subtick : mouse .getAll ()) {
183+
184+ List <VirtualMouse > subticks = new ArrayList <>(mouse .getAll ());
185+ pruneListEndEmptySubtickable (subticks );
186+
187+ for (VirtualMouse subtick : subticks ) {
176188 out .add (subtick .toString2 ());
177189 }
178190 return out ;
179191 }
180192
181193 protected List <String > serialiseCameraAngle (VirtualCameraAngle cameraAngle ) {
194+
195+ VirtualCameraAngle previousCamera = null ;
196+ if (previousTickContainer != null ) {
197+ previousCamera = previousTickContainer .getCameraAngle ();
198+ }
199+
182200 List <String > out = new ArrayList <>();
183201 for (VirtualCameraAngle subtick : cameraAngle .getAll ()) {
184- out .add (subtick .toString2 ());
202+
203+ if (!subtick .equals (previousCamera ))
204+ out .add (subtick .toString2 ());
205+
206+ previousCamera = subtick ;
185207 }
186208 return out ;
187209 }
@@ -588,7 +610,7 @@ protected void deserialiseContainer(BigArrayList<TickContainer> out, List<String
588610
589611 splitInputs (containerLines , keyboardStrings , mouseStrings , cameraAngleStrings , endlineComments , endlineFileCommands );
590612
591- pruneListEnd (endlineComments );
613+ pruneListEndNull (endlineComments );
592614
593615 VirtualKeyboard keyboard = deserialiseKeyboard (keyboardStrings );
594616 VirtualMouse mouse = deserialiseMouse (mouseStrings );
@@ -819,18 +841,28 @@ protected Float deserialiseRelativeFloat(String name, String floatstring, Float
819841
820842 protected void splitInputs (List <String > lines , List <String > serialisedKeyboard , List <String > serialisedMouse , List <String > serialisedCameraAngle , List <String > commentsAtEnd , List <List <PlaybackFileCommand >> endlineFileCommands ) {
821843
844+ String previousCamera = null ;
845+ if (previousTickContainer != null ) {
846+ previousCamera = previousTickContainer .getCameraAngle ().toString2 ();
847+ }
848+
822849 for (String line : lines ) {
823-
824850 Matcher tickMatcher = extract ("^\\ t?\\ d+\\ |(.*?)\\ |(.*?)\\ |(\\ S*)\\ s?" , line );
851+
825852 if (tickMatcher .find ()) {
826853 if (!tickMatcher .group (1 ).isEmpty ()) {
827854 serialisedKeyboard .add (tickMatcher .group (1 ));
828855 }
829856 if (!tickMatcher .group (2 ).isEmpty ()) {
830857 serialisedMouse .add (tickMatcher .group (2 ));
831858 }
859+
832860 if (!tickMatcher .group (3 ).isEmpty ()) {
833861 serialisedCameraAngle .add (tickMatcher .group (3 ));
862+ previousCamera = tickMatcher .group (3 );
863+ } else {
864+ if (previousCamera !=null )
865+ serialisedCameraAngle .add (previousCamera );
834866 }
835867
836868 List <PlaybackFileCommand > deserialisedFileCommands = new ArrayList <>();
@@ -926,12 +958,12 @@ public static <T extends Serializable> void addAll(BigArrayList<T> list, List<T>
926958 }
927959
928960 /**
929- * Empties the list if it only consists of null values
961+ * Empties the list starting from the back if the values are null
930962 *
931963 * @param <T> The element of the list
932964 * @param list The list to prune
933965 */
934- protected <T > void pruneListEnd (List <T > list ) {
966+ protected <T > void pruneListEndNull (List <T > list ) {
935967 List <T > copy = new ArrayList <>(list );
936968 for (int i = copy .size () - 1 ; i >= 0 ; i --) {
937969 T element = copy .get (i );
@@ -940,6 +972,39 @@ protected <T> void pruneListEnd(List<T> list) {
940972 list .remove (list .size () - 1 );
941973 }
942974 }
975+
976+ /**
977+ * Empties the list starting from the back if the values are empty
978+ *
979+ * @param <T> The element of the list
980+ * @param list The list to prune
981+ */
982+ protected void pruneListEndEmpty (List <String > list ) {
983+ List <String > copy = new ArrayList <>(list );
984+ for (int i = copy .size () - 1 ; i >= 0 ; i --) {
985+ String element = copy .get (i );
986+ if (!element .isEmpty ())
987+ return ;
988+ list .remove (list .size () - 1 );
989+ }
990+ }
991+
992+ /**
993+ * Empties the list starting from the back if the values are empty
994+ *
995+ * @param <T> The element of the list
996+ * @param list The list to prune
997+ */
998+ protected <T extends Subtickable <T >> void pruneListEndEmptySubtickable (List <T > list ) {
999+ List <T > copy = new ArrayList <>(list );
1000+ for (int i = copy .size () - 1 ; i >= 0 ; i --) {
1001+ T element = copy .get (i );
1002+ if (!element .isEmpty ())
1003+ return ;
1004+ list .remove (list .size () - 1 );
1005+ }
1006+ }
1007+
9431008
9441009 @ Override
9451010 public abstract SerialiserFlavorBase clone ();
0 commit comments