Skip to content

Commit

Permalink
[PlaybackSerialiser] Various fixes and improvements
Browse files Browse the repository at this point in the history
- [VirtualInput] Fixed VirtualCameraAngle#updateFromState being able to create subticks with null as pitch and yaw
- Fixed flavor registry not creating clones of the flavors when getting a list of flavors
- Fixed tests not deleting PlaybackSerialiserTest2.mctas after execution
- Fixed tests
  • Loading branch information
ScribbleTAS committed Jun 23, 2024
1 parent 9ce00b3 commit 543489f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static BigArrayList<TickContainer> loadFromFile(File file, SerialiserFlav
public static SerialiserFlavorBase searchForFlavor(List<String> lines, List<SerialiserFlavorBase> flavorList) {
for (SerialiserFlavorBase flavor : flavorList) {
if (flavor.deserialiseFlavorName(lines)) {
return flavor;
return flavor.clone();
}
}
throw new PlaybackLoadException("Couldn't find a flavorname in the file while loading it");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

public abstract class SerialiserFlavorBase {

private long currentLine = 0;

/**
* The current tick that is being serialised or deserialised
*/
Expand All @@ -39,6 +41,7 @@ public abstract class SerialiserFlavorBase {

protected TickContainer previousTickContainer = null;


public abstract String flavorName();

protected String headerStart() {
Expand Down Expand Up @@ -397,12 +400,12 @@ protected void deserialiseMetadata(List<String> headerLines) {
*/
public BigArrayList<TickContainer> deserialise(BigArrayList<String> lines, long startPos) {
BigArrayList<TickContainer> out = new BigArrayList<>();

for (long i = startPos; i < lines.size(); i++) {
List<String> container = new ArrayList<>();
// Extract the tick and set the index
i = extractContainer(container, lines, i);
currentTick = i;
currentLine = i;
currentTick++;
// Extract container
deserialiseContainer(out, container);
}
Expand Down Expand Up @@ -711,7 +714,7 @@ protected VirtualCameraAngle deserialiseCameraAngle(List<String> cameraAngleStri
Float previousYaw = previousTickContainer == null ? null : previousTickContainer.getCameraAngle().getYaw();

for (String line : cameraAngleStrings) {
Matcher matcher = extract("\\|(.+?);(.+)", line);
Matcher matcher = extract("(.+?);(.+)", line);

if (matcher.find()) {
String cameraPitchString = matcher.group(1);
Expand Down Expand Up @@ -926,5 +929,5 @@ protected <T> void pruneListEnd(List<T> list){
}

@Override
protected abstract SerialiserFlavorBase clone();
public abstract SerialiserFlavorBase clone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected List<String> serialiseCameraAngle(VirtualCameraAngle cameraAngle) {
}

@Override
protected SerialiserFlavorBase clone() {
public SerialiserFlavorBase clone() {
return new Beta1Flavor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public void updateFromEvent(float pitchDelta, float yawDelta, boolean updateSubt
}

public void updateFromState(float pitch, float yaw) {
createSubtick(true);
if(this.pitch!=null && this.yaw != null) {
createSubtick(true);
}
this.pitch = MathHelper.clamp(pitch, -90F, 90F);
this.yaw = yaw;
}
Expand Down
30 changes: 19 additions & 11 deletions src/test/java/tasmod/playback/tasfile/PlaybackSerialiserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String flavorName() {


@Override
protected SerialiserFlavorBase clone() {
public SerialiserFlavorBase clone() {
return new TestFlavor();
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public String[] getFileCommandNames() {
}
}

File file = new File("src/test/resources/serialiser/PlaybackSerialiserTest.mctas");
File file;

private static TestFlavor testFlavor = new TestFlavor();
private static TestMetadatada testMetadata = new TestMetadatada();
Expand All @@ -126,6 +126,7 @@ static void register() {
void afterEach() {
testFileCommand.inline.clear();
testFileCommand.endline.clear();
file.delete();
}

@AfterAll
Expand All @@ -139,6 +140,8 @@ static void unregister() {
void testSerialiser() {
BigArrayList<TickContainer> expected = new BigArrayList<>();

file = new File("src/test/resources/serialiser/PlaybackSerialiserTest.mctas");

testMetadata.testValue = "testing";
TASmodRegistry.PLAYBACK_FILE_COMMAND.setEnabled("tasmod_testFileExtension", true);
// Tick 1
Expand Down Expand Up @@ -193,8 +196,6 @@ void testSerialiser() {
assertEquals("testing", testMetadata.actual);
} catch (PlaybackLoadException | IOException e) {
fail(e);
} finally {
file.delete();
}
}

Expand All @@ -214,9 +215,9 @@ void testDeserialiser() throws PlaybackLoadException, IOException {
lines.add("\t1|W,T;t|| // $testKey(test);$endlineKey();");
lines.add("2|W;w|-101;0,1,1|1;1");
lines.add("3|;|-101;0,~1,~1|~1;~1");
lines.add("\t1|;|-101;|;0,~1,~1|~1;~1");
lines.add("\t1|;|-101;0,~1,~1|~1;~1");

File file = new File("src/test/resources/serialiser/PlaybackSerialiserTest2.mctas");
file = new File("src/test/resources/serialiser/PlaybackSerialiserTest2.mctas");
try {
FileUtils.writeLines(file, lines);
} catch (IOException e) {
Expand Down Expand Up @@ -256,10 +257,9 @@ void testDeserialiser() throws PlaybackLoadException, IOException {
mouse3.updateFromEvent(VirtualKey.MOUSEMOVED, false, 0, 3, 3);

VirtualCameraAngle cameraAngle3 = new VirtualCameraAngle();
cameraAngle3.set(2f, 2f);
cameraAngle3.updateFromEvent(3f, 3f);
cameraAngle3.updateFromState(2f, 2f);

expected.add(new TickContainer(null, mouse3, cameraAngle3));
expected.add(new TickContainer(new VirtualKeyboard(), mouse3, cameraAngle3));

assertBigArrayList(expected, actual);

Expand All @@ -269,18 +269,26 @@ void testDeserialiser() throws PlaybackLoadException, IOException {
PlaybackFileCommandContainer fccontainer = new PlaybackFileCommandContainer();
fccontainer.add("testKey", new PlaybackFileCommand("testKey", "test"));

PlaybackFileCommandContainer fccontainerempty = new PlaybackFileCommandContainer();
fccontainerempty.put("testKey", null);

fclist.add(fccontainer);
fclist.add(fccontainerempty);
fclist.add(fccontainerempty);
assertIterableEquals(fclist, testFileCommand.inline);

List<PlaybackFileCommandContainer> fclistEnd = new ArrayList<>();
PlaybackFileCommandContainer fccontainerEnd = new PlaybackFileCommandContainer();
fccontainerEnd.add("endlineKey", null);
fccontainerEnd.add("endlineKey", new PlaybackFileCommand("endlineKey"));

PlaybackFileCommandContainer fccontainerEndEmpty = new PlaybackFileCommandContainer();
fccontainerEndEmpty.put("endlineKey", null);

fclistEnd.add(fccontainerEnd);
fclistEnd.add(fccontainerEndEmpty);
fclistEnd.add(fccontainerEndEmpty);
assertIterableEquals(fclistEnd, testFileCommand.endline);

file.delete();
}

private <T extends Serializable> void assertBigArrayList(BigArrayList<T> expected, BigArrayList<T> actual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ private <T extends Serializable> ArrayList<T> convertBigArrayListToArrayList(Big
}

@Override
protected SerialiserFlavorBase clone() {
public SerialiserFlavorBase clone() {
return new SerialiserFlavorBaseTest();
}

Expand Down
14 changes: 0 additions & 14 deletions src/test/resources/serialiser/PlaybackSerialiserTest2.mctas

This file was deleted.

0 comments on commit 543489f

Please sign in to comment.