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

Refactor PlaybackSerialiser #203

Merged
merged 79 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
36c2126
[Commands/SaveTAS] Added clickable link for opening tasfile directory
ScribbleTAS Apr 14, 2024
04c8466
[PlaybackSerialiser] Added basic layout
ScribbleTAS Apr 19, 2024
cb132b3
[PlaybackSerialiser] Added serialisation methods to FlavorBase
ScribbleTAS Apr 20, 2024
91f1ab7
[PlaybackSerialiser] Created 'BetaFlavor'
ScribbleTAS May 1, 2024
4b14988
[PlaybackSerialiser] Added flavor registry
ScribbleTAS May 5, 2024
a1959aa
[Common] Added AbstractRegistry
ScribbleTAS May 7, 2024
ae3c1dc
Cleaned up TASmodClient
ScribbleTAS May 8, 2024
e09a4d6
[PlaybackSerialiser] Added serialise functionality
ScribbleTAS May 9, 2024
91af4a2
[PlaybackSerialiser] Switched flavor to pass by reference
ScribbleTAS May 10, 2024
6a7e042
[PlaybackSerialiser] Added tests for PlaybackFlavorBase
ScribbleTAS May 10, 2024
30fcb3d
[PlaybackSerialiser] Adding start of deserialisation
ScribbleTAS May 11, 2024
e82cdbd
[PlaybackSerialiser] Added metadata deserialisation
ScribbleTAS May 11, 2024
0601e69
[PlaybackSerialiser] Added tests for deserialising metadata
ScribbleTAS May 12, 2024
e0968e2
[PlaybackSerialiser] Refined metadata deserialisation
ScribbleTAS May 12, 2024
69de29d
[PlaybackSerialiser] Added extract tick
ScribbleTAS May 14, 2024
b436e0e
[PlaybackSerialiser] Fixed bugs and tests in deserialisation
ScribbleTAS May 15, 2024
7879fe1
[PlaybackSerialiser] Added splitting inputs
ScribbleTAS May 16, 2024
6bdccd9
[PlaybackSerialiser] Added keyboard deserialisation
ScribbleTAS May 17, 2024
5fe6ae6
[PlaybackSerialiser] Added tests for splitting inputs
ScribbleTAS May 18, 2024
a506767
[PlaybackSerialiser] Added mouse deserialisation
ScribbleTAS May 20, 2024
7de41ca
[PlaybackSerialiser] Add camera angle deserialisation
ScribbleTAS May 20, 2024
cc618ce
[PlaybackSerialiser] Added tests for mouse, camera, numeric and float
ScribbleTAS May 21, 2024
3a33f3b
[PlaybackSerialiser] Split container deserialisation into comments an…
ScribbleTAS May 22, 2024
f1fc94e
[PlaybackSerialiser] Added test for splittingContainer
ScribbleTAS May 23, 2024
86b7c4a
[PlaybackSerialiser] Start rewriting playbackserialiser
ScribbleTAS May 25, 2024
a3c4faf
[PlaybackSerialiser] Finished PlaybackSerialiser, started adding tests
ScribbleTAS May 25, 2024
16e7b4a
[PlaybackSerialiser] Renamed PlaybackFlavorBase to SerialiserFlavorBase
ScribbleTAS May 26, 2024
cd305cf
[PlaybackSerialiser] Added PlaybackExtensions
ScribbleTAS May 26, 2024
4a46f2a
[PlaybackSerialiser] Added PlaybackExtensions to registry
ScribbleTAS May 26, 2024
2c3d99e
[PlaybackSerialiser] Fixed tests
ScribbleTAS May 29, 2024
cf01afd
[PlaybackSerialiser] Renamed Extensions to FileCommands
ScribbleTAS Jun 2, 2024
451ad0d
[PlaybackSerialiser] Added serialising inline and endline comments
ScribbleTAS Jun 4, 2024
d11b157
[PlaybackSerialiser] Added serialising FileCommandExtensions
ScribbleTAS Jun 6, 2024
7e90b2e
[PlaybackSerialiser] Trying to figure out how to store PlaybackFileCo…
ScribbleTAS Jun 7, 2024
bda3d7f
[PlaybackSerialiser] Trying to figure out how to store PlaybackFileCo…
ScribbleTAS Jun 7, 2024
d935813
[PlaybackSerialiser] Moved parts of filecommand handling to the registry
ScribbleTAS Jun 8, 2024
0060d3f
[PlaybackSerialiser] Added FileCommand deserialisation
ScribbleTAS Jun 8, 2024
1f4f363
[PlaybackSerialiser] Added improved FileCommand deserialisation
ScribbleTAS Jun 9, 2024
8a847c9
[PlaybackSerialiser] Fixed tests for deserialising container
ScribbleTAS Jun 10, 2024
1643d51
[PlaybackSerialiser] Added test for serialising inline comments
ScribbleTAS Jun 12, 2024
df287a5
[PlaybackSerialiser] Added tests for serialisingComments
ScribbleTAS Jun 13, 2024
06b77fc
[PlaybackSerialiser] Fixed PlaybackFileCommandContainer not being abl…
ScribbleTAS Jun 13, 2024
d2fdf9f
[PlaybackSerialiser] Added support for relative coord input (#184)
ScribbleTAS Jun 14, 2024
ccfd759
[PlaybackSerialiser] Rewrite modules, added tests
ScribbleTAS Jun 14, 2024
82ed56d
[PlaybackSerialiser] Added tests for failing to extract container
ScribbleTAS Jun 15, 2024
144b45f
[PlaybackSerialiser] Added PlaybackSerialiser tests
ScribbleTAS Jun 19, 2024
62d85db
[PlaybackSerialiser] Fixed "equals" in TickContainer
ScribbleTAS Jun 19, 2024
d18ecd1
[PlaybackSerialiser] Fixed tests
ScribbleTAS Jun 20, 2024
9ce00b3
[PlaybackSerialiser] Testing relative TASfile inputs
ScribbleTAS Jun 21, 2024
543489f
[PlaybackSerialiser] Various fixes and improvements
ScribbleTAS Jun 23, 2024
e29d52b
[PlaybackSerialiser] Added tests for serialiser errors
ScribbleTAS Jun 23, 2024
f805a28
[PlaybackSerialiser] Added linecount to PlaybackLoadException
ScribbleTAS Jun 25, 2024
1219a22
[PlaybackSerialiser] Rewrite DesyncMonitor as file command extension
ScribbleTAS Jun 25, 2024
947a29c
[PlaybackSerialiser] Added PlaybackFileCommandLine for better readabi…
ScribbleTAS Jun 27, 2024
2da7c94
[PlaybackSerialiser] Added options and label FileCommands
ScribbleTAS Jun 27, 2024
a2fdbb5
[PlaybackSerialiser] Added implementation to Beta1Flavor
ScribbleTAS Jun 28, 2024
efe2dfa
[PlaybackSerialiser] Hook up commands to the new serialiser
ScribbleTAS Jun 29, 2024
ca4d5aa
[PlaybackSerialiser] Added PlaybackSaveException
ScribbleTAS Jun 29, 2024
5b8a22c
[PlaybackController] Removed deprecated fields
ScribbleTAS Jun 30, 2024
be1dcc1
[MCTCommon/Keybinds] Fixed custom isKeyDownFunc not being used
ScribbleTAS Jun 30, 2024
3f92474
[PlaybackController] Fixed TASfile not being applied to the controller
ScribbleTAS Jun 30, 2024
e6f89b0
[PlaybackController] Fixed metadata getting cleared onLoad
ScribbleTAS Jun 30, 2024
86c5c52
[PlaybackSerialiser] Fixed FileCommmands#onRecord() not being called
ScribbleTAS Jul 1, 2024
f137d43
[PlaybackSerialiser] Fixed DesyncMonitorFileCommand not being loaded
ScribbleTAS Jul 2, 2024
a66ef9c
[MCTCommon] Further abstracted registries
ScribbleTAS Jul 2, 2024
f610827
[PlaybackSerialiser] Added stopIndex to serialiser
ScribbleTAS Jul 3, 2024
bb8cfca
[Events] Split EvenServer and EventClient into more sub events
ScribbleTAS Jul 3, 2024
4d06957
[Savestates] Added serialiser to client savestates
ScribbleTAS Jul 3, 2024
e0c0cfd
[PlaybackSerialiser] Added better styling for metadata
ScribbleTAS Jul 8, 2024
ab5f91d
Add .gitattributes file
ScribbleTAS Jul 8, 2024
d3a11d8
[PlaybackSerialiser] Reduced clutter
ScribbleTAS Jul 8, 2024
bd2e0f0
[PlaybackSerialiser] Renames PlaybackSerialiser2 to PlaybackSerialiser
ScribbleTAS Jul 9, 2024
102a8a8
[PlaybackSerialiser] Starting with CommandFileCommand
ScribbleTAS Jul 9, 2024
d1e806e
[PlaybackSerialiser] Finished CommandFileCommand
ScribbleTAS Jul 9, 2024
8af3ffb
[PlaybackSerialiser] Store enabled filecommands in the config
ScribbleTAS Jul 10, 2024
6a8979a
[PlaybackSerialiser] Fixed NPE in FileCommandsRegistry config
ScribbleTAS Jul 10, 2024
966bb45
[PlaybackSerialiser] Changed PlaybackMetadataExtension to abstract class
ScribbleTAS Jul 10, 2024
4d12a49
Formatted files, fixed fc_label and fc_hud not resetting properly
ScribbleTAS Jul 11, 2024
c7a4493
[PlaybackSerialiser] Changed TASFile to TASfile for better consistency
ScribbleTAS Jul 11, 2024
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.java diff=java
*.md diff=markdown
127 changes: 76 additions & 51 deletions src/main/java/com/minecrafttas/mctcommon/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,76 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.InvalidPropertiesFormatException;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Properties;

import com.minecrafttas.mctcommon.Configuration.ConfigOptions;
import com.minecrafttas.mctcommon.registry.AbstractRegistry;
import com.minecrafttas.mctcommon.registry.Registerable;

/**
* A <i>very</i> simple configuration class
*
* @author Scribble
*
*/

public class Configuration {
public class Configuration extends AbstractRegistry<ConfigOptions> {

private File file;

private Properties properties;

private String comment;

public Configuration(String comment, File configFile) {
super("Configuration", new LinkedHashMap<>());

file = configFile;
this.comment = comment;
}

protected final List<ConfigOptions> configRegistry = new ArrayList<>();

@Override
public void register(ConfigOptions registryObject) {
if(registryObject == null) {
return;
}

if(configRegistry.contains(registryObject)) {
return;
}
ScribbleTAS marked this conversation as resolved.
Show resolved Hide resolved

configRegistry.add(registryObject);
}

@Override
public void unregister(ConfigOptions registryObject) {
if (registryObject == null) {
return;
}

if (!configRegistry.contains(registryObject)) {
return;
}

if(file.exists()) {
properties = load();
configRegistry.remove(registryObject);
}

public void load() {
if (file.exists()) {
properties = loadInner();
}
if(properties == null || !file.exists()) {
if (properties == null || !file.exists()) {
properties = generateDefault();
save();
}
}
ScribbleTAS marked this conversation as resolved.
Show resolved Hide resolved
}

public Properties load() {
private Properties loadInner() {
FileInputStream fis;
Properties newProp = new Properties();
try {
Expand All @@ -57,11 +93,11 @@ public Properties load() {
}
return newProp;
}

public void save() {
save(file);
}

public void save(File file) {
try {
FileOutputStream fos = new FileOutputStream(file);
Expand All @@ -71,73 +107,62 @@ public void save(File file) {
e.printStackTrace();
}
}

public Properties generateDefault() {
Properties newProperties = new Properties();
newProperties.putAll(ConfigOptions.getDefaultValues());
configRegistry.forEach((configOption)->{
newProperties.put(configOption.getConfigKey(), configOption.getDefaultValue());
});
return newProperties;
}

public String get(ConfigOptions configOption) {
return properties.getProperty(configOption.configKey);
return properties.getProperty(configOption.getConfigKey(), configOption.getDefaultValue());
}

public int getInt(ConfigOptions configOption) {
return Integer.parseInt(get(configOption));
}

public boolean getBoolean(ConfigOptions configOption) {
return Boolean.parseBoolean(get(configOption));
}

public boolean has(ConfigOptions configOption) {
return properties.contains(configOption.configKey);
return properties.contains(configOption.getConfigKey());
}

public void set(ConfigOptions configOption, String value) {
properties.setProperty(configOption.configKey, value);
if(properties == null) {
throw new NullPointerException("Config needs to be loaded first, before trying to set a value");
}
properties.setProperty(configOption.getConfigKey(), value);
save();
}

public void set(ConfigOptions configOption, int value) {
String val = Integer.toString(value);
set(configOption, val);
}

public void set(ConfigOptions configOption, boolean value) {
String val = Boolean.toString(value);
set(configOption, val);
}

public void reset(ConfigOptions configOption) {
set(configOption, configOption.defaultValue);
set(configOption, configOption.getDefaultValue());
}

public void delete(ConfigOptions configOption) {
properties.remove(configOption);
save();
}

public static enum ConfigOptions{
FileToOpen("fileToOpen", ""),
ServerConnection("serverConnection", "");

private String configKey;
private String defaultValue;

private ConfigOptions(String configKey, String defaultValue) {
this.configKey = configKey;
this.defaultValue = defaultValue;
}

public static Map<String, String> getDefaultValues() {
Map<String, String> out = new HashMap<>();
for (ConfigOptions configthing : values()) {
if(configthing.defaultValue!=null) {
out.put(configthing.configKey, configthing.defaultValue);
}
}
return out;
}

public interface ConfigOptions extends Registerable {

public String getDefaultValue();

public String getConfigKey();
}
}
23 changes: 13 additions & 10 deletions src/main/java/com/minecrafttas/mctcommon/KeybindManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class KeybindManager implements EventClientGameLoop {

public static class Keybind {

private KeyBinding keyBinding;
private String category;
private Runnable onKeyDown;
private IsKeyDownFunc isKeyDownFunc;
public final KeyBinding vanillaKeyBinding;
private final String category;
private final Runnable onKeyDown;
private final IsKeyDownFunc isKeyDownFunc;

/**
* Initialize keybind
Expand All @@ -49,12 +49,16 @@ public Keybind(String name, String category, int defaultKey, Runnable onKeyDown)
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown, IsKeyDownFunc func) {
this.keyBinding = new KeyBinding(name, defaultKey, category);
this.vanillaKeyBinding = new KeyBinding(name, defaultKey, category);
this.category = category;
this.onKeyDown = onKeyDown;
this.isKeyDownFunc = func;
}

@Override
public String toString() {
return this.vanillaKeyBinding.getKeyDescription();
}
}

private List<Keybind> keybindings;
Expand All @@ -77,7 +81,7 @@ public KeybindManager(IsKeyDownFunc defaultFunction) {
public void onRunClientGameLoop(Minecraft mc) {
for (Keybind keybind : this.keybindings){
IsKeyDownFunc keyDown = keybind.isKeyDownFunc != null ? keybind.isKeyDownFunc : defaultFunction;
if(keyDown.isKeyDown(keybind.keyBinding)){
if(keyDown.isKeyDown(keybind.vanillaKeyBinding)){
keybind.onKeyDown.run();
}
}
Expand All @@ -89,9 +93,9 @@ public void onRunClientGameLoop(Minecraft mc) {
*
* @param keybind Keybind to register
*/
public KeyBinding registerKeybind(Keybind keybind) {
public void registerKeybind(Keybind keybind) {
this.keybindings.add(keybind);
KeyBinding keyBinding = keybind.keyBinding;
KeyBinding keyBinding = keybind.vanillaKeyBinding;

// add category
GameSettings options = Minecraft.getMinecraft().gameSettings;
Expand All @@ -100,9 +104,8 @@ public KeyBinding registerKeybind(Keybind keybind) {

// add keybinding
options.keyBindings = ArrayUtils.add(options.keyBindings, keyBinding);
return keyBinding;
}

@FunctionalInterface
public static interface IsKeyDownFunc {

Expand Down
23 changes: 15 additions & 8 deletions src/main/java/com/minecrafttas/mctcommon/LanguageManager.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package com.minecrafttas.mctcommon;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;

import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.gson.Gson;

import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Pattern;

public class LanguageManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.minecrafttas.mctcommon.events;

import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase;
import com.minecrafttas.mctcommon.server.Client;
import com.minecrafttas.mctcommon.networking.Client;
import com.mojang.authlib.GameProfile;

import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.minecrafttas.mctcommon.events;

import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase;
import com.minecrafttas.mctcommon.server.Client;
import com.minecrafttas.mctcommon.networking.Client;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.minecrafttas.mctcommon.server;
package com.minecrafttas.mctcommon.networking;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.UUID;

import com.minecrafttas.mctcommon.server.interfaces.PacketID;
import com.minecrafttas.mctcommon.networking.interfaces.PacketID;

/**
* Helper method for creating byte buffers which get pooled from a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.minecrafttas.mctcommon.server;
package com.minecrafttas.mctcommon.networking;

import static com.minecrafttas.mctcommon.MCTCommon.Client;
import static com.minecrafttas.mctcommon.MCTCommon.LOGGER;
import static com.minecrafttas.mctcommon.MCTCommon.Server;
import static com.minecrafttas.mctcommon.server.SecureList.BUFFER_SIZE;
import static com.minecrafttas.mctcommon.networking.SecureList.BUFFER_SIZE;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand All @@ -22,10 +22,10 @@
import com.minecrafttas.mctcommon.events.EventClient.EventDisconnectClient;
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
import com.minecrafttas.mctcommon.events.EventServer.EventClientCompleteAuthentication;
import com.minecrafttas.mctcommon.server.exception.InvalidPacketException;
import com.minecrafttas.mctcommon.server.exception.PacketNotImplementedException;
import com.minecrafttas.mctcommon.server.exception.WrongSideException;
import com.minecrafttas.mctcommon.server.interfaces.PacketID;
import com.minecrafttas.mctcommon.networking.exception.InvalidPacketException;
import com.minecrafttas.mctcommon.networking.exception.PacketNotImplementedException;
import com.minecrafttas.mctcommon.networking.exception.WrongSideException;
import com.minecrafttas.mctcommon.networking.interfaces.PacketID;

/**
* A custom asynchronous client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.minecrafttas.mctcommon.server;
package com.minecrafttas.mctcommon.networking;

import java.nio.ByteBuffer;

import com.minecrafttas.mctcommon.server.exception.PacketNotImplementedException;
import com.minecrafttas.mctcommon.networking.exception.PacketNotImplementedException;

@FunctionalInterface
public interface CompactPacketHandler {
Expand Down
Loading