Skip to content

Commit c022077

Browse files
committed
[Flavor] Finish alpha serialisation and deserialisation
- A lot of fixes and changes to get old files to load - Fixed some error messages not displaying the correct values - More tweaks to SerialiserFlavorBase
1 parent 063302d commit c022077

File tree

5 files changed

+229
-24
lines changed

5 files changed

+229
-24
lines changed

src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java

+1
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
846846
if (mc.world != null)
847847
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + "Loading failed, something went very wrong"));
848848
LOGGER.catching(e);
849+
return;
849850
}
850851

851852
if (mc.world != null)

src/main/java/com/minecrafttas/tasmod/playback/filecommands/builtin/DesyncMonitorFileCommandExtension.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void onPlayback(long tick, TickContainer tickContainer) {
135135
private MonitorContainer loadFromFile(long tick, String[] args) throws PlaybackLoadException {
136136

137137
if (args.length != 6)
138-
throw new PlaybackLoadException("Tick %s: desyncMonitorArgsLength ");
138+
throw new PlaybackLoadException("Could not load desyncMonitor file command in tick %s. The amount of arguments doesn't match: %s", tick, args.length);
139139

140140
double x = 0;
141141
double y = 0;

src/main/java/com/minecrafttas/tasmod/playback/tasfile/PlaybackSerialiser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static BigArrayList<TickContainer> loadFromFile(Path file, String flavorN
177177
// Read the head of the TASfile to check if the flavors match
178178
SerialiserFlavorBase flavorInFile = readFlavor(file);
179179
if (!flavor.equals(flavorInFile)) {
180-
throw new PlaybackLoadException("Detected flavor %s in the TASfile, which does not match the specified flavor: %s");
180+
throw new PlaybackLoadException("Detected flavor %s in the TASfile, which does not match the specified flavor: %s", flavorInFile.getExtensionName(), flavor.getExtensionName());
181181
}
182182

183183
flavor.setProcessExtensions(processExtensions);

src/main/java/com/minecrafttas/tasmod/playback/tasfile/flavor/SerialiserFlavorBase.java

+45-16
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ protected void serialiseMetadataValues(List<String> out, LinkedHashMap<String, S
307307
* ├── {@link #serialiseCameraAngle(VirtualCameraAngle)}
308308
* │ └── {@link #serialiseCameraAngleSubtick(VirtualCameraAngle)}
309309
* ├── {@link #serialiseInlineComments(List, List)}
310-
* │ └── {@link #serialiseFileCommandsInLine(List)}
310+
* │ └── {@link #serialiseFileCommandsInline(List)}
311311
* │ └── {@link #serialiseFileCommand(PlaybackFileCommand)}
312312
* ├── {@link #serialiseEndlineComments(List, List)} // Same as serialiseInlineComments
313-
* │ └── {@link #serialiseFileCommandsEndLine(List)} // Unused
313+
* │ └── {@link #serialiseFileCommandsEndline(List)} // Unused
314314
* │ └── {@link #serialiseFileCommand(PlaybackFileCommand)}
315315
* └── {@link #mergeInputs(BigArrayList, List, List, List, List)}
316316
* ├── {@link #mergeInput(long, String, String, String, String)}
@@ -489,7 +489,7 @@ protected String serialiseCameraAngleSubtick(VirtualCameraAngle cameraAngleSubti
489489

490490
/**
491491
* <p>Serialise comments that take up an entire line
492-
* <p>In addition, comments can contain {@link PlaybackFileCommand FileCommands} that are serialised in {@link #serialiseFileCommandsInLine(List)}
492+
* <p>In addition, comments can contain {@link PlaybackFileCommand FileCommands} that are serialised in {@link #serialiseFileCommandsInline(List)}
493493
* <h5>Example</h5>
494494
* <pre>
495495
* // Inline comment
@@ -518,7 +518,7 @@ protected List<String> serialiseInlineComments(List<String> inlineComments, List
518518

519519
String command = null;
520520
if (fileCommandQueue != null) {
521-
command = serialiseFileCommandsInLine(fileCommandQueue.poll()); // Trying to poll a fileCommand. Command can be null at this point
521+
command = serialiseFileCommandsInline(fileCommandQueue.poll()); // Trying to poll a fileCommand. Command can be null at this point
522522
}
523523

524524
// Add an empty line if comment and command is null
@@ -537,7 +537,7 @@ protected List<String> serialiseInlineComments(List<String> inlineComments, List
537537
// add the rest of the fileCommands to the end
538538
while (!fileCommandQueue.isEmpty()) {
539539

540-
String command = serialiseFileCommandsInLine(fileCommandQueue.poll());
540+
String command = serialiseFileCommandsInline(fileCommandQueue.poll());
541541
if (command != null) {
542542
out.add(serialiseInlineComment(command));
543543
} else {
@@ -582,7 +582,7 @@ protected List<String> serialiseEndlineComments(List<String> endlineComments, Li
582582

583583
String command = null;
584584
if (fileCommandQueue != null) {
585-
command = serialiseFileCommandsEndLine(fileCommandQueue.poll()); // Trying to poll a fileCommand. Command can be null at this point
585+
command = serialiseFileCommandsEndline(fileCommandQueue.poll()); // Trying to poll a fileCommand. Command can be null at this point
586586
}
587587

588588
// Add an empty line if comment and command is null
@@ -601,7 +601,7 @@ protected List<String> serialiseEndlineComments(List<String> endlineComments, Li
601601
// add the rest of the fileCommands to the end
602602
while (!fileCommandQueue.isEmpty()) {
603603

604-
String command = serialiseFileCommandsEndLine(fileCommandQueue.poll());
604+
String command = serialiseFileCommandsEndline(fileCommandQueue.poll());
605605
if (command != null) {
606606
out.add(serialiseEndlineComment(command));
607607
} else {
@@ -629,7 +629,7 @@ protected String serialiseEndlineComment(String comment) {
629629
* @param fileCommands The file commands to serialise
630630
* @return A string of serialised file commands or null if fileCommands is null
631631
*/
632-
protected String serialiseFileCommandsInLine(List<PlaybackFileCommand> fileCommands) {
632+
protected String serialiseFileCommandsInline(List<PlaybackFileCommand> fileCommands) {
633633
// File commands is null if there are no file commands in the comment.
634634
// Return null if that is the case
635635
if (fileCommands == null) {
@@ -645,16 +645,16 @@ protected String serialiseFileCommandsInLine(List<PlaybackFileCommand> fileComma
645645
/**
646646
* <p>Serialises a list of file commands in an endline comment
647647
* <p>This is added in case a flavor needs a different format for endline and inline commands,<br>
648-
* but by default this is the same as {@link #serialiseFileCommandsInLine(List) serialiseFileCommandsInLine}
648+
* but by default this is the same as {@link #serialiseFileCommandsInline(List) serialiseFileCommandsInLine}
649649
* <h5>Example</h5>
650650
* <pre>
651651
* 12|W;w||0;0 // $fileCommandName1(argument1); $fileCommandName2(argument1, argument2);
652652
* </pre>
653653
* @param fileCommands The file commands to serialise
654654
* @return A string of serialised file commands or null if fileCommands is null
655655
*/
656-
protected String serialiseFileCommandsEndLine(List<PlaybackFileCommand> fileCommands) {
657-
return serialiseFileCommandsInLine(fileCommands);
656+
protected String serialiseFileCommandsEndline(List<PlaybackFileCommand> fileCommands) {
657+
return serialiseFileCommandsInline(fileCommands);
658658
}
659659

660660
/**
@@ -990,7 +990,7 @@ public BigArrayList<TickContainer> deserialise(BigArrayList<String> lines, long
990990
// Extract the tick and set the index
991991
i = extractContainer(container, lines, i);
992992
currentLine = i;
993-
// Extract container
993+
// Deserialise container
994994
deserialiseContainer(out, container);
995995
currentTick++;
996996
}
@@ -1222,7 +1222,7 @@ protected void deserialiseMultipleInlineComments(List<String> inlineComments, Li
12221222
}
12231223

12241224
protected String deserialiseInlineComment(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
1225-
comment = deserialiseFileCommands(comment, deserialisedFileCommands);
1225+
comment = deserialiseFileCommandsInline(comment, deserialisedFileCommands);
12261226
comment = extract("^// ?(.+)", comment, 1);
12271227
if (comment != null) {
12281228
comment = comment.trim();
@@ -1234,11 +1234,36 @@ protected String deserialiseInlineComment(String comment, List<PlaybackFileComma
12341234
}
12351235

12361236
protected String deserialiseEndlineComment(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
1237-
return deserialiseInlineComment(comment, deserialisedFileCommands);
1237+
comment = deserialiseFileCommandsEndline(comment, deserialisedFileCommands);
1238+
comment = extract("^// ?(.+)", comment, 1);
1239+
if (comment != null) {
1240+
comment = comment.trim();
1241+
if (comment.isEmpty()) {
1242+
comment = null;
1243+
}
1244+
}
1245+
return comment;
12381246
}
12391247

1240-
protected String deserialiseFileCommands(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
1248+
protected String deserialiseFileCommandsInline(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
1249+
Matcher matcher = extract("\\$(.+?)\\((.*?)\\);", comment);
1250+
1251+
// Iterate through all file commands and add each to the list
1252+
while (matcher.find()) {
1253+
String name = matcher.group(1);
1254+
String[] args = matcher.group(2).split(", ?");
1255+
1256+
if (processExtensions)
1257+
deserialisedFileCommands.add(new PlaybackFileCommand(name, args));
12411258

1259+
comment = matcher.replaceFirst("");
1260+
matcher.reset(comment);
1261+
}
1262+
1263+
return comment;
1264+
}
1265+
1266+
protected String deserialiseFileCommandsEndline(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
12421267
Matcher matcher = extract("\\$(.+?)\\((.*?)\\);", comment);
12431268

12441269
// Iterate through all file commands and add each to the list
@@ -1467,7 +1492,7 @@ protected void splitInputs(List<String> lines, List<String> serialisedKeyboard,
14671492
}
14681493

14691494
for (String line : lines) {
1470-
Matcher tickMatcher = extract("^\\t?\\d+\\|(.*?)\\|(.*?)\\|(\\S*)\\s?", line);
1495+
Matcher tickMatcher = extract(splitInputRegex(), line);
14711496

14721497
if (tickMatcher.find()) {
14731498
if (!tickMatcher.group(1).isEmpty()) {
@@ -1498,6 +1523,10 @@ protected void splitInputs(List<String> lines, List<String> serialisedKeyboard,
14981523
}
14991524
}
15001525

1526+
protected String splitInputRegex() {
1527+
return "^\\t?\\d+\\|(.*?)\\|(.*?)\\|(\\S*)\\s?";
1528+
}
1529+
15011530
protected Matcher extract(String regex, String haystack) {
15021531
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
15031532
Matcher matcher = pattern.matcher(haystack);

0 commit comments

Comments
 (0)