Skip to content

Commit 48e6ac2

Browse files
committed
[Flavor] Add inlineFileCommand support for AlphaFlavor
1 parent 9e651ea commit 48e6ac2

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public String[] getFileCommandNames() {
4444
return new String[] { "hud" };
4545
}
4646

47+
@Override
48+
public PlaybackFileCommandContainer onSerialiseInlineComment(long tick, TickContainer tickContainer) {
49+
// TODO Implement
50+
return null;
51+
}
52+
4753
@Override
4854
public void onDeserialiseInlineComment(long tick, TickContainer container, PlaybackFileCommandContainer fileCommandContainer) {
4955
if (fileCommandContainer.containsKey("hud")) {

src/main/java/com/minecrafttas/tasmod/playback/tasfile/flavor/builtin/AlphaFlavor.java

+43
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,23 @@ protected List<String> serialiseCameraAngle(VirtualCameraAngle subticks) {
236236
return out;
237237
}
238238

239+
@Override
240+
protected String serialiseFileCommandsInline(List<PlaybackFileCommand> fileCommands) {
241+
if (fileCommands == null) {
242+
return null;
243+
}
244+
List<String> serialisedCommands = new ArrayList<>();
245+
for (PlaybackFileCommand command : fileCommands) {
246+
if ("hud".equals(command.getName())) {
247+
serialisedCommands.add(String.format("$hud %s", command.getArgs()[0].equals("true") ? "on" : "off"));
248+
}
249+
if ("label".equals(command.getName())) {
250+
serialisedCommands.add(String.format("$info %s", command.getArgs().length == 0 ? "off" : String.join(" ", command.getArgs())));
251+
}
252+
}
253+
return String.join(" ", serialisedCommands);
254+
}
255+
239256
@Override
240257
protected String serialiseFileCommandsEndline(List<PlaybackFileCommand> fileCommands) {
241258
if (fileCommands == null) {
@@ -320,6 +337,32 @@ protected String splitInputRegex() {
320337
return "^\\d+\\|(.*?)\\|(.*?)\\|(\\S*)~&";
321338
}
322339

340+
@Override
341+
protected String deserialiseFileCommandsInline(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
342+
Matcher matcher = extract("\\$(.+?) (.+?)", comment);
343+
344+
// Iterate through all file commands and add each to the list
345+
while (matcher.find()) {
346+
String name = matcher.group(1);
347+
String[] args = matcher.group(2).split(" ");
348+
349+
if ("hud".equals(name)) {
350+
args[0] = "on".equals(args[0]) ? "true" : "false";
351+
} else if ("info".equals(name)) {
352+
name = "label";
353+
args[0] = "off".equals(args[0]) ? "" : args[0];
354+
}
355+
356+
if (processExtensions)
357+
deserialisedFileCommands.add(new PlaybackFileCommand(name, args));
358+
359+
comment = matcher.replaceFirst("");
360+
matcher.reset(comment);
361+
}
362+
363+
return comment;
364+
}
365+
323366
@Override
324367
protected String deserialiseFileCommandsEndline(String comment, List<PlaybackFileCommand> deserialisedFileCommands) {
325368
Matcher matcher = extract("Monitoring:(.+)", comment);

src/test/java/tasmod/playback/tasfile/builtin/AlphaFlavorTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void testSerialiseHeader() {
106106
+ "#StartPosition:" + "0.0,0.0,0.0,0.0,0.0" + "\n"
107107
+ "# #\n"
108108
+ "#StartSeed:" + 0);
109-
expected.add("#############################################################################################################\n"
110-
+ "#Comments start with \"//\" at the start of the line, comments with # will not be saved");
109+
expected.add("#############################################################################################################");
110+
expected.add("#Comments start with \"//\" at the start of the line, comments with # will not be saved");
111111

112112
assertIterableEquals(expected, actual);
113113
}

0 commit comments

Comments
 (0)