Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flavor] Add Alpha flavor #221

Merged
merged 16 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package com.minecrafttas.mctcommon.registry;

/**
* Interface for declaring that a class can be registered by a class of type {@link AbstractRegistry}
*
* @author Scribble
*/
public interface Registerable {

/**
* @return The name of the extension that is registered
*/
public String getExtensionName();
}
2 changes: 1 addition & 1 deletion src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
import com.minecrafttas.tasmod.commands.CommandTickrate;
import com.minecrafttas.tasmod.commands.TabCompletionUtils;
import com.minecrafttas.tasmod.playback.PlaybackControllerServer;
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.registries.TASmodPackets;
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer;
import com.minecrafttas.tasmod.savestates.storage.SavestateMotionStorage;
15 changes: 9 additions & 6 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
@@ -25,12 +25,13 @@
import com.minecrafttas.tasmod.handlers.LoadingScreenHandler;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.filecommands.integrated.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.integrated.LabelFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.integrated.OptionsFileCommandExtension;
import com.minecrafttas.tasmod.playback.metadata.integrated.CreditsMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.tasfile.flavor.integrated.Beta1Flavor;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.LabelFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.OptionsFileCommandExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.CreditsMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.tasfile.flavor.builtin.AlphaFlavor;
import com.minecrafttas.tasmod.playback.tasfile.flavor.builtin.Beta1Flavor;
import com.minecrafttas.tasmod.registries.TASmodAPIRegistry;
import com.minecrafttas.tasmod.registries.TASmodConfig;
import com.minecrafttas.tasmod.registries.TASmodKeybinds;
@@ -312,9 +313,11 @@ private void registerPlaybackMetadata(Minecraft mc) {
}

public static Beta1Flavor betaFlavor = new Beta1Flavor();
public static AlphaFlavor alphaFlavor = new AlphaFlavor();

private void registerSerialiserFlavors(Minecraft mc) {
TASmodAPIRegistry.SERIALISER_FLAVOR.register(betaFlavor);
TASmodAPIRegistry.SERIALISER_FLAVOR.register(alphaFlavor);
}

public static DesyncMonitorFileCommandExtension desyncMonitorFileCommandExtension;
2 changes: 1 addition & 1 deletion src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.filecommands.integrated.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.mojang.realmsclient.gui.ChatFormatting;

import net.minecraft.client.Minecraft;
Original file line number Diff line number Diff line change
@@ -580,7 +580,7 @@ public void setPlayUntil(int until) {
// ==============================================================

/**
* Storage class which stores the keyboard, mouse and subticks of a given tick.
* Storage class which stores the keyboard, mouse, subticks and comments of a given tick.
*
* @author Scribble
*
@@ -628,7 +628,13 @@ public VirtualCameraAngle getCameraAngle() {
return cameraAngle;
}

/**
* @return The comment container of this controller. If {@link #comments} is null, returns an empty container.
*/
public CommentContainer getComments() {
if (comments == null) {
return new CommentContainer();
}
return comments;
}

@@ -647,6 +653,11 @@ public boolean equals(Object other) {
}
}

/**
* Storage class for storing {@link CommentContainer#inlineComments inline} and {@link CommentContainer#endlineComments endline} comments
*
* @author Scribble
*/
public static class CommentContainer implements Serializable {

/**
@@ -835,6 +846,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
if (mc.world != null)
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + "Loading failed, something went very wrong"));
LOGGER.catching(e);
return;
}

if (mc.world != null)
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public static abstract class PlaybackFileCommandExtension implements Registerabl
protected final Path tempDir;

public PlaybackFileCommandExtension() {
this(null);
this((Path) null);
}

/**
@@ -69,13 +69,18 @@ public PlaybackFileCommandExtension() {
* @param tempFolderName The name of the temp folder
*/
public PlaybackFileCommandExtension(String tempFolderName) {
if (tempFolderName == null) {
this(TASmodClient.tasfiledirectory.resolve("temp").resolve(tempFolderName));
}

public PlaybackFileCommandExtension(Path tempDirectory) {
if (tempDirectory == null) {
tempDir = null;
return;
}
this.tempDir = TASmodClient.tasfiledirectory.resolve("temp").resolve(tempFolderName);

tempDir = tempDirectory;
try {
AbstractDataFile.createDirectory(tempDir);
AbstractDataFile.createDirectory(tempDirectory);
} catch (IOException e) {
e.printStackTrace();
}
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@
public class PlaybackFileCommandsRegistry extends AbstractRegistry<PlaybackFileCommandExtension> implements EventPlaybackClient.EventRecordTick, EventPlaybackClient.EventPlaybackTick, EventPlaybackClient.EventRecordClear {

private List<PlaybackFileCommandExtension> enabledExtensions = new ArrayList<>();

private Configuration config = null;

public PlaybackFileCommandsRegistry() {
super("FILECOMMAND_REGISTRY", new LinkedHashMap<>());
}
@@ -38,16 +38,16 @@ public void unregister(PlaybackFileCommandExtension extension) {
public boolean setEnabled(String extensionName, boolean enabled) {
return setEnabled(extensionName, enabled, true);
}

public boolean setEnabled(String extensionName, boolean enabled, boolean saveToConfig) {
PlaybackFileCommandExtension extension = REGISTRY.get(extensionName);
if(extension == null) {
if (extension == null) {
return false;
}
extension.setEnabled(enabled);
enabledExtensions = getEnabled();
if(saveToConfig) {

if (saveToConfig) {
saveConfig();
}
return true;
@@ -59,16 +59,20 @@ private void disableAll() {
});
}

public void setEnabled(String... extensionNames) {
setEnabled(Arrays.asList(extensionNames));
}

public void setEnabled(List<String> extensionNames) {
setEnabled(extensionNames, false);
}

public void setEnabled(List<String> extensionNames, boolean saveToConfig) {
disableAll();
for (String name : extensionNames) {
setEnabled(name, true, false);
}
if(saveToConfig)
if (saveToConfig)
saveConfig();
}

@@ -83,24 +87,24 @@ public List<PlaybackFileCommandExtension> getEnabled() {

return out;
}
public List<PlaybackFileCommandExtension> getAll(){

public List<PlaybackFileCommandExtension> getAll() {
return new ArrayList<>(REGISTRY.values());
}

@Override
public void onRecordTick(long index, TickContainer container) {
enabledExtensions.forEach(extension -> {
if(extension.isEnabled()) {
if (extension.isEnabled()) {
extension.onRecord(index, container);
}
});
}

@Override
public void onPlaybackTick(long index, TickContainer container) {
enabledExtensions.forEach(extension -> {
if(extension.isEnabled()) {
if (extension.isEnabled()) {
extension.onPlayback(index, container);
}
});
@@ -109,8 +113,8 @@ public void onPlaybackTick(long index, TickContainer container) {
public PlaybackFileCommandContainer handleOnSerialiseInline(long currentTick, TickContainer container) {
PlaybackFileCommandContainer out = new PlaybackFileCommandContainer();
for (PlaybackFileCommandExtension extension : enabledExtensions) {
PlaybackFileCommandContainer extensionContainer=extension.onSerialiseInlineComment(currentTick, container);
if(extensionContainer!=null) {
PlaybackFileCommandContainer extensionContainer = extension.onSerialiseInlineComment(currentTick, container);
if (extensionContainer != null) {
out.putAll(extensionContainer);
}
}
@@ -120,8 +124,8 @@ public PlaybackFileCommandContainer handleOnSerialiseInline(long currentTick, Ti
public PlaybackFileCommandContainer handleOnSerialiseEndline(long currentTick, TickContainer container) {
PlaybackFileCommandContainer out = new PlaybackFileCommandContainer();
for (PlaybackFileCommandExtension extension : enabledExtensions) {
PlaybackFileCommandContainer extensionContainer=extension.onSerialiseEndlineComment(currentTick, container);
if(extensionContainer!=null) {
PlaybackFileCommandContainer extensionContainer = extension.onSerialiseEndlineComment(currentTick, container);
if (extensionContainer != null) {
out.putAll(extensionContainer);
}
}
@@ -155,22 +159,22 @@ public void setConfig(Configuration config) {
this.config = config;
loadConfig();
}

private void loadConfig() {
if (config == null) {
return;
}
String enabled = config.get(TASmodConfig.EnabledFileCommands);
setEnabled(Arrays.asList(enabled.split(", ")));
}

private void saveConfig() {
if (config == null) {
return;
}
List<String> nameList = new ArrayList<>();
enabledExtensions.forEach(element ->{
List<String> nameList = new ArrayList<>();

enabledExtensions.forEach(element -> {
nameList.add(element.getExtensionName());
});
config.set(TASmodConfig.EnabledFileCommands, String.join(", ", nameList));
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.minecrafttas.tasmod.playback.filecommands.integrated;
package com.minecrafttas.tasmod.playback.filecommands.builtin;

import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Path;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.List;
@@ -40,12 +41,22 @@ public class DesyncMonitorFileCommandExtension extends PlaybackFileCommandExtens
private MonitorContainer currentValues;

public DesyncMonitorFileCommandExtension() {
super("monitoring");
this("monitoring");
}

public DesyncMonitorFileCommandExtension(String tempDirName) {
super(tempDirName);
this.monitorContainer = new BigArrayList<MonitorContainer>(tempDir.toString());
// Is enabled by default
enabled = true;
}

public DesyncMonitorFileCommandExtension(Path tempDir) {
super(tempDir);
this.monitorContainer = new BigArrayList<>(tempDir.toString());
enabled = true;
}

@Override
public String getExtensionName() {
return "tasmod_desyncMonitor@v1";
@@ -124,7 +135,7 @@ public void onPlayback(long tick, TickContainer tickContainer) {
private MonitorContainer loadFromFile(long tick, String[] args) throws PlaybackLoadException {

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

double x = 0;
double y = 0;
@@ -349,9 +360,9 @@ public void onClear() {
} catch (IOException e) {
e.printStackTrace();
}
monitorContainer = new BigArrayList<MonitorContainer>(tempDir.toString());
monitorContainer = new BigArrayList<MonitorContainer>();
lastStatus = TextFormatting.GRAY + "Empty";
lastPos = "";
lastMotion = "";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minecrafttas.tasmod.playback.filecommands.integrated;
package com.minecrafttas.tasmod.playback.filecommands.builtin;

import java.io.IOException;
import java.nio.file.Path;

import com.dselent.bigarraylist.BigArrayList;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
@@ -16,7 +17,17 @@ public class LabelFileCommandExtension extends PlaybackFileCommandExtension {
BigArrayList<PlaybackFileCommandContainer> label = new BigArrayList<>();

public LabelFileCommandExtension() {
super("label");
this("label");
}

public LabelFileCommandExtension(String tempDirName) {
super(tempDirName);
this.label = new BigArrayList<>(tempDir.toString());
enabled = true;
}

public LabelFileCommandExtension(Path tempDir) {
super(tempDir);
this.label = new BigArrayList<>(tempDir.toString());
enabled = true;
}
@@ -31,6 +42,15 @@ public String[] getFileCommandNames() {
return new String[] { "label" };
}

@Override
public PlaybackFileCommandContainer onSerialiseInlineComment(long tick, TickContainer tickContainer) {
PlaybackFileCommandContainer fileCommandContainer = new PlaybackFileCommandContainer();
if (label.size() != 0 && label.get(tick).get("label") != null) {
fileCommandContainer = label.get(tick);
}
return fileCommandContainer;
}

@Override
public void onDeserialiseInlineComment(long tick, TickContainer container, PlaybackFileCommandContainer fileCommandContainer) {
if (fileCommandContainer.containsKey("label")) {
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minecrafttas.tasmod.playback.filecommands.integrated;
package com.minecrafttas.tasmod.playback.filecommands.builtin;

import java.io.IOException;
import java.nio.file.Path;

import com.dselent.bigarraylist.BigArrayList;
import com.minecrafttas.tasmod.TASmod;
@@ -18,11 +19,21 @@ public class OptionsFileCommandExtension extends PlaybackFileCommandExtension {
BigArrayList<PlaybackFileCommandContainer> hud;

public OptionsFileCommandExtension() {
super("hud");
this("hud");
}

public OptionsFileCommandExtension(String tempDirName) {
super(tempDirName);
hud = new BigArrayList<>(tempDir.toString());
enabled = true;
}

public OptionsFileCommandExtension(Path tempDir) {
super(tempDir);
this.hud = new BigArrayList<>(tempDir.toString());
enabled = true;
}

@Override
public String getExtensionName() {
return "tasmod_options@v1";
@@ -33,6 +44,15 @@ public String[] getFileCommandNames() {
return new String[] { "hud" };
}

@Override
public PlaybackFileCommandContainer onSerialiseInlineComment(long tick, TickContainer tickContainer) {
PlaybackFileCommandContainer fileCommandContainer = new PlaybackFileCommandContainer();
if (hud.size() != 0 && hud.get(tick).get("hud") != null) {
fileCommandContainer = hud.get(tick);
}
return fileCommandContainer;
}

@Override
public void onDeserialiseInlineComment(long tick, TickContainer container, PlaybackFileCommandContainer fileCommandContainer) {
if (fileCommandContainer.containsKey("hud")) {
@@ -58,6 +78,11 @@ public void onPlayback(long tick, TickContainer tickContainer) {
for (PlaybackFileCommand command : line) {
String[] args = command.getArgs();
if (args.length == 1) {
/*
* Ok this may seem dumb, but Boolean.parseBoolean returns false,
* even if something other then true or false was passed...
* If someone finds something less idiotic please tell me...
*/
switch (args[0]) {
case "true":
shouldRenderHud = true;
Original file line number Diff line number Diff line change
@@ -23,12 +23,12 @@ public PlaybackMetadata(PlaybackMetadataExtension extension) {
this(extension.getExtensionName());
}

private PlaybackMetadata(String extensionName) {
public PlaybackMetadata(String extensionName) {
this.extensionName = extensionName;
this.data = new LinkedHashMap<String, String>();
}

private PlaybackMetadata(String extensionName, LinkedHashMap<String, String> data) {
public PlaybackMetadata(String extensionName, LinkedHashMap<String, String> data) {
this.extensionName = extensionName;
this.data = data;
}
@@ -37,10 +37,18 @@ public void setValue(String key, String value) {
data.put(key, value);
}

public void setValue(Object key, String value) {
setValue(key.toString(), value);
}

public String getValue(String key) {
return data.get(key);
}

public String getValue(Object key) {
return getValue(key.toString());
}

@Override
public String toString() {
String out = "";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.minecrafttas.tasmod.playback.metadata.integrated;
package com.minecrafttas.tasmod.playback.metadata.builtin;

import static com.minecrafttas.tasmod.TASmod.LOGGER;

@@ -25,24 +25,24 @@ public class CreditsMetadataExtension extends PlaybackMetadataExtension implemen
/**
* The title/category of the TAS (e.g. KillSquid - Any% Glitched)
*/
private String title = "Insert TAS category here";
protected String title = "Insert TAS category here";
/**
* The author(s) of the TAS (e.g. Scribble, Pancake)
*/
private String authors = "Insert author here";
protected String authors = "Insert author here";
/**
* How long the TAS is going to take (e.g. 00:01.0 or 20ticks)
*/
private String playtime = "00:00.0";
protected String playtime = "00:00.0";
/**
* How often a savestate was loaded as a measurement of effort (e.g. 200)
*/
private int rerecords = 0;
protected int rerecords = 0;

/**
* If the credits where already printed in this instance
*/
private boolean creditsPrinted = false;
protected boolean creditsPrinted = false;

@Override
public String getExtensionName() {
@@ -54,29 +54,51 @@ public void onCreate() {
// Unused atm
}

public enum CreditFields {
Title("Title"),
Author("Author"),
PlayTime("Playing Time"),
Rerecords("Rerecords");

private final String name;

private CreditFields(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}

@Override
public PlaybackMetadata onStore() {
PlaybackMetadata metadata = new PlaybackMetadata(this);
metadata.setValue("Title", title);
metadata.setValue("Author", authors);
metadata.setValue("Playing Time", playtime);
metadata.setValue("Rerecords", Integer.toString(rerecords));
metadata.setValue(CreditFields.Title, title);
metadata.setValue(CreditFields.Author, authors);
metadata.setValue(CreditFields.PlayTime, playtime);
metadata.setValue(CreditFields.Rerecords, Integer.toString(rerecords));
return metadata;
}

@Override
public void onLoad(PlaybackMetadata metadata) {
title = metadata.getValue("Title");
authors = metadata.getValue("Author");
playtime = metadata.getValue("Playing Time");
title = getOrDefault(metadata.getValue(CreditFields.Title), title);
authors = getOrDefault(metadata.getValue(CreditFields.Author), authors);
playtime = getOrDefault(metadata.getValue(CreditFields.PlayTime), playtime);
try {
rerecords = Integer.parseInt(metadata.getValue("Rerecords"));
rerecords = Integer.parseInt(getOrDefault(metadata.getValue(CreditFields.Rerecords), Integer.toString(rerecords)));
} catch (NumberFormatException e) {
rerecords = 0;
throw new PlaybackLoadException(e);
}
}

protected String getOrDefault(String value, String defaultVal) {
return value != null ? value : defaultVal;
}

@Override
public void onClear() {
title = "Insert TAS category here";
@@ -101,7 +123,7 @@ public void onPlaybackJoinedWorld(TASstate state) {
}
}

private void printMessage(String msg, TextFormatting format) {
protected void printMessage(String msg, TextFormatting format) {
String formatString = "";
if (format != null)
formatString = format.toString();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.minecrafttas.tasmod.playback.metadata.integrated;
package com.minecrafttas.tasmod.playback.metadata.builtin;

import static com.minecrafttas.tasmod.TASmod.LOGGER;

@@ -36,15 +36,15 @@ public class StartpositionMetadataExtension extends PlaybackMetadataExtension im
/**
* The startposition of the playback
*/
StartPosition startPosition = null;
protected StartPosition startPosition = null;

public static class StartPosition {

final double x;
final double y;
final double z;
final float pitch;
final float yaw;
public final double x;
public final double y;
public final double z;
public final float pitch;
public final float yaw;

public StartPosition(double x, double y, double z, float pitch, float yaw) {
this.x = x;
@@ -70,6 +70,25 @@ public void onCreate() {
// Unused atm
}

public enum StartPositionFields {
X("x"),
Y("y"),
Z("z"),
Pitch("pitch"),
Yaw("yaw");

private final String name;

private StartPositionFields(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}

@Override
public PlaybackMetadata onStore() {
PlaybackMetadata metadata = new PlaybackMetadata(this);
@@ -78,25 +97,29 @@ public PlaybackMetadata onStore() {
if (this.startPosition != null) {
startPositionToStore = startPosition;
}
metadata.setValue("x", Double.toString(startPositionToStore.x));
metadata.setValue("y", Double.toString(startPositionToStore.y));
metadata.setValue("z", Double.toString(startPositionToStore.z));
metadata.setValue("pitch", Float.toString(startPositionToStore.pitch));
metadata.setValue("yaw", Float.toString(startPositionToStore.yaw));
metadata.setValue(StartPositionFields.X, Double.toString(startPositionToStore.x));
metadata.setValue(StartPositionFields.Y, Double.toString(startPositionToStore.y));
metadata.setValue(StartPositionFields.Z, Double.toString(startPositionToStore.z));
metadata.setValue(StartPositionFields.Pitch, Float.toString(startPositionToStore.pitch));
metadata.setValue(StartPositionFields.Yaw, Float.toString(startPositionToStore.yaw));
return metadata;
}

@Override
public void onLoad(PlaybackMetadata metadata) {
double x = getDouble("x", metadata);
double y = getDouble("y", metadata);
double z = getDouble("z", metadata);
float pitch = getFloat("pitch", metadata);
float yaw = getFloat("yaw", metadata);
double x = getDouble(StartPositionFields.X, metadata);
double y = getDouble(StartPositionFields.Y, metadata);
double z = getDouble(StartPositionFields.Z, metadata);
float pitch = getFloat(StartPositionFields.Pitch, metadata);
float yaw = getFloat(StartPositionFields.Yaw, metadata);

this.startPosition = new StartPosition(x, y, z, pitch, yaw);
}

private double getDouble(Object key, PlaybackMetadata metadata) {
return getDouble(key.toString(), metadata);
}

private double getDouble(String key, PlaybackMetadata metadata) {
String out = metadata.getValue(key);
if (out != null) {
@@ -110,6 +133,10 @@ private double getDouble(String key, PlaybackMetadata metadata) {
}
}

private float getFloat(Object key, PlaybackMetadata metadata) {
return getFloat(key.toString(), metadata);
}

private float getFloat(String key, PlaybackMetadata metadata) {
String out = metadata.getValue(key);
if (out != null) {
@@ -158,7 +185,7 @@ public void updateStartPosition() {
if (player != null)
startPosition = new StartPosition(player.posX, player.posY, player.posZ, player.rotationPitch, player.rotationYaw);
else
LOGGER.warn("Start position not set, the player was null! This will make problems when storing inputs!");
LOGGER.warn("Start position not set, the player was null! This will create problems when storing inputs!");

}

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

flavor.setProcessExtensions(processExtensions);
@@ -234,7 +234,7 @@ public static BigArrayList<TickContainer> loadFromFile(Path file, SerialiserFlav
*/
public static SerialiserFlavorBase searchForFlavor(List<String> lines, List<SerialiserFlavorBase> flavorList) {
for (SerialiserFlavorBase flavor : flavorList) {
if (flavor.deserialiseFlavorName(lines)) {
if (flavor.checkFlavorName(lines)) {
return flavor.clone();
}
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
import com.dselent.bigarraylist.BigArrayList;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
import com.minecrafttas.tasmod.playback.filecommands.integrated.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.util.FileThread;
import com.minecrafttas.tasmod.util.LoggerMarkers;
import com.minecrafttas.tasmod.virtual.VirtualCameraAngle;

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.minecrafttas.tasmod.playback.tasfile.flavor.integrated;
package com.minecrafttas.tasmod.playback.tasfile.flavor.builtin;

import com.minecrafttas.tasmod.playback.tasfile.flavor.SerialiserFlavorBase;

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadataRegistry;
import com.minecrafttas.tasmod.playback.tasfile.flavor.SerialiserFlavorBase;
import com.minecrafttas.tasmod.playback.tasfile.flavor.SerialiserFlavorRegistry;
import com.minecrafttas.tasmod.playback.tasfile.flavor.integrated.Beta1Flavor;
import com.minecrafttas.tasmod.playback.tasfile.flavor.builtin.Beta1Flavor;

public class TASmodAPIRegistry {
/**
Original file line number Diff line number Diff line change
@@ -773,9 +773,10 @@ void testSplitContainer() {

List<String> actualComments = new ArrayList<>();
List<String> actualTick = new ArrayList<>();
List<List<PlaybackFileCommand>> actualInlineFileCommands = new ArrayList<>();
splitContainer(lines, actualComments, actualTick);

splitContainer(lines, actualComments, actualTick, actualInlineFileCommands);
List<List<PlaybackFileCommand>> actualInlineFileCommands = new ArrayList<>();
deserialiseMultipleInlineComments(actualComments, actualInlineFileCommands);

List<String> expectedComments = new ArrayList<>();
List<String> expectedTicks = new ArrayList<>();
220 changes: 220 additions & 0 deletions src/test/java/tasmod/playback/tasfile/builtin/AlphaFlavorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package tasmod.playback.tasfile.builtin;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand.PlaybackFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.LabelFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.OptionsFileCommandExtension;
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadata;
import com.minecrafttas.tasmod.playback.metadata.builtin.CreditsMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.CreditsMetadataExtension.CreditFields;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension.StartPosition;
import com.minecrafttas.tasmod.playback.tasfile.flavor.builtin.AlphaFlavor;
import com.minecrafttas.tasmod.registries.TASmodAPIRegistry;

public class AlphaFlavorTest extends AlphaFlavor {

CreditsMetadataExtensionTest creditsMetadataExtension;
StartpositionMetadataExtensionTest startpositionMetadataExtension;

private class CreditsMetadataExtensionTest extends CreditsMetadataExtension {
public String getTitle() {
return title;
}

public String getAuthors() {
return authors;
}

public String getPlayTime() {
return playtime;
}

public int getRerecords() {
return rerecords;
}
}

private class StartpositionMetadataExtensionTest extends StartpositionMetadataExtension {
public StartPosition getStartPosition() {
return startPosition;
}
}

@AfterEach
void afterEach() {
TASmodAPIRegistry.PLAYBACK_FILE_COMMAND.clear();
TASmodAPIRegistry.PLAYBACK_METADATA.clear();
TASmodAPIRegistry.SERIALISER_FLAVOR.clear();

this.currentTick = 0;
this.currentSubtick = 0;
this.previousTickContainer = null;
}

@BeforeEach
void beforeEach() {
creditsMetadataExtension = new CreditsMetadataExtensionTest();
startpositionMetadataExtension = new StartpositionMetadataExtensionTest();

PlaybackMetadata creditsMetadata = new PlaybackMetadata(creditsMetadataExtension);
creditsMetadata.setValue(CreditFields.Author, "Scribal");
creditsMetadataExtension.onLoad(creditsMetadata);

Path temp = Paths.get("src/test/resources/temp");

TASmodAPIRegistry.PLAYBACK_FILE_COMMAND.register(new LabelFileCommandExtension(temp), new DesyncMonitorFileCommandExtension(temp), new OptionsFileCommandExtension(temp));

TASmodAPIRegistry.PLAYBACK_METADATA.register(creditsMetadataExtension, startpositionMetadataExtension);
}

@Test
void testSerialiseHeader() {
List<String> actual = serialiseHeader();
List<String> expected = new ArrayList<>();

expected.add("################################################# TASFile ###################################################\n"
+ "# Version:1 #\n"
+ "# This file was generated using the Minecraft TASMod #\n"
+ "# #\n"
+ "# Any errors while reading this file will be printed out in the console and the chat #\n"
+ "# #");
expected.add("#------------------------------------------------ Header ---------------------------------------------------#\n"
+ "#Author:" + "Scribal" + "\n"
+ "# #\n"
+ "#Title:" + "Insert TAS category here" + "\n"
+ "# #\n"
+ "#Playing Time:" + "00:00.0" + "\n"
+ "# #\n"
+ "#Rerecords:" + 0 + "\n"
+ "# #\n"
+ "#----------------------------------------------- Settings --------------------------------------------------#\n"
+ "#StartPosition:" + "0.0,0.0,0.0,0.0,0.0" + "\n"
+ "# #\n"
+ "#StartSeed:" + 0);
expected.add("#############################################################################################################");
expected.add("#Comments start with \"//\" at the start of the line, comments with # will not be saved");

assertIterableEquals(expected, actual);
}

@Test
void testCheckFlavorName() {
List<String> data = new ArrayList<>();
data.add("################################################# TASFile ###################################################\n"
+ "# Version:1 #\n"
+ "# This file was generated using the Minecraft TASMod #\n"
+ "# #\n"
+ "# Any errors while reading this file will be printed out in the console and the chat #\n"
+ "# #");
data.add("#------------------------------------------------ Header ---------------------------------------------------#\n"
+ "#Author:" + "Scribal" + "\n"
+ "# #\n"
+ "#Title:" + "Insert TAS category here" + "\n"
+ "# #\n"
+ "#Playing Time:" + "00:00.0" + "\n"
+ "# #\n"
+ "#Rerecords:" + 0 + "\n"
+ "# #\n"
+ "#----------------------------------------------- Settings --------------------------------------------------#\n"
+ "#StartPosition:" + "0.0,0.0,0.0,0.0,0.0" + "\n"
+ "# #\n"
+ "#StartSeed:" + 0);
data.add("#############################################################################################################\n"
+ "#Comments start with \"//\" at the start of the line, comments with # will not be saved");

assertTrue(checkFlavorName(data));
}

@Test
void testCheckFlavorNameFalse() {
List<String> data = new ArrayList<>();
data.add("################################################# TASFile ###################################################\n"
+ "# Version:2 #\n"
+ "# This file was generated using the Minecraft TASMod #\n"
+ "# #\n"
+ "# Any errors while reading this file will be printed out in the console and the chat #\n"
+ "# #");
data.add("#------------------------------------------------ Header ---------------------------------------------------#\n"
+ "#Author:" + "Scribal" + "\n"
+ "# #\n"
+ "#Title:" + "Insert TAS category here" + "\n"
+ "# #\n"
+ "#Playing Time:" + "00:00.0" + "\n"
+ "# #\n"
+ "#Rerecords:" + 0 + "\n"
+ "# #\n"
+ "#----------------------------------------------- Settings --------------------------------------------------#\n"
+ "#StartPosition:" + "0.0,0.0,0.0,0.0,0.0" + "\n"
+ "# #\n"
+ "#StartSeed:" + 0);
data.add("#############################################################################################################\n"
+ "#Comments start with \"//\" at the start of the line, comments with # will not be saved");

assertFalse(checkFlavorName(data));
}

@Test
void testDeserialiseMetadata() {
List<String> data = new ArrayList<>();
data.add("################################################# TASFile ###################################################");
data.add("# Version:1 #");
data.add("# This file was generated using the Minecraft TASMod #");
data.add("# #");
data.add("# Any errors while reading this file will be printed out in the console and the chat #");
data.add("# #");
data.add("#------------------------------------------------ Header ---------------------------------------------------#");
data.add("#Author:" + "Scribble");
data.add("# #");
data.add("#Title:" + "Beef");
data.add("# #");
data.add("#Playing Time:" + "00:01.0");
data.add("# #");
data.add("#Rerecords:" + 20);
data.add("# #");
data.add("#----------------------------------------------- Settings --------------------------------------------------#");
data.add("#StartPosition:" + "1.0,2.0,3.0,4.0,5.0");
data.add("# #");
data.add("#StartSeed:" + 0);
data.add("#############################################################################################################");
data.add("#Comments start with \"//\" at the start of the line, comments with # will not be saved");

deserialiseMetadata(data);

assertEquals("Scribble", creditsMetadataExtension.getAuthors());
assertEquals("Beef", creditsMetadataExtension.getTitle());
assertEquals("00:01.0", creditsMetadataExtension.getPlayTime());
assertEquals(20, creditsMetadataExtension.getRerecords());

StartPosition pos = startpositionMetadataExtension.getStartPosition();
assertEquals(1.0D, pos.x);
assertEquals(2.0D, pos.y);
assertEquals(3.0D, pos.z);
assertEquals(4.0F, pos.pitch);
assertEquals(5.0F, pos.yaw);
}

@Test
void testDeserialiseFileCommandNames() {
deserialiseFileCommandNames(new ArrayList<>());

List<PlaybackFileCommandExtension> fcList = TASmodAPIRegistry.PLAYBACK_FILE_COMMAND.getEnabled();
assertTrue(fcList.get(0) instanceof LabelFileCommandExtension);
assertTrue(fcList.get(1) instanceof DesyncMonitorFileCommandExtension);
assertTrue(fcList.get(2) instanceof OptionsFileCommandExtension);
}
}