Skip to content

Commit

Permalink
[Flavor] Add AlphaFlavor and finished header serialisation
Browse files Browse the repository at this point in the history
- [Metadata] Added enum options to CreditsMetadataExtension and StartpositionMetadataExtension for easier retrieval of values
  • Loading branch information
ScribbleTAS committed Dec 13, 2024
1 parent e4551be commit aaaf65f
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 125 deletions.
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();
}
3 changes: 3 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -303,9 +304,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 = new DesyncMonitorFileCommandExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,41 @@ 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 = metadata.getValue(CreditFields.Title);
authors = metadata.getValue(CreditFields.Author);
playtime = metadata.getValue(CreditFields.PlayTime);
try {
rerecords = Integer.parseInt(metadata.getValue("Rerecords"));
rerecords = Integer.parseInt(metadata.getValue(CreditFields.Rerecords));
} catch (NumberFormatException e) {
rerecords = 0;
throw new PlaybackLoadException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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!");

}

Expand Down
Loading

0 comments on commit aaaf65f

Please sign in to comment.