Skip to content

Commit

Permalink
[PlaybackController] Added playback metadata registry
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Mar 25, 2024
1 parent f28cc1f commit d11b2ac
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public static void register(EventBase eventListener) {
}
}

/**
* Registers multiple objects to be an event listener. The objects must implement an event extending {@link EventBase}
* @param eventListeners The event listeners to register
*/
public static void register(EventBase... eventListeners) {
for(EventBase eventListener : eventListeners) {
register(eventListener);
Expand Down Expand Up @@ -122,6 +126,16 @@ public static void unregister(EventBase eventListener) {
}
}
}

/**
* Unregisters multiple objects from being an event listener.
* @param eventListener The event listeners to unregister
*/
public static void unregister(EventBase... eventListeners) {
for(EventBase eventListener : eventListeners) {
unregister(eventListener);
}
}

/**
* Fires an event without parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void unregister(PacketHandlerBase handler) {
if (REGISTRY.contains(handler)) {
REGISTRY.remove(handler);
} else {
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but is was not registered!", handler.getClass().getName());
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but it was not registered!", handler.getClass().getName());
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
import com.minecrafttas.tasmod.TASmod;
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar;
import com.minecrafttas.tasmod.handlers.InterpolationHandler;
import com.minecrafttas.tasmod.monitoring.DesyncMonitoring;
import com.minecrafttas.tasmod.playback.ControlByteHandler;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.util.TrajectoriesCalculator;
import com.mojang.realmsclient.gui.ChatFormatting;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.math.Vec3d;

/**
* The info hud is a hud that is always being rendered ontop of the screen, it can show some stuff such as coordinates, etc.,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.minecrafttas.tasmod.playback;
package com.minecrafttas.tasmod.playback.metadata;

import java.util.LinkedHashMap;
import java.util.Properties;
Expand All @@ -16,5 +16,6 @@ public PlaybackMetadata() {
this.metadata = new LinkedHashMap<>();
}


public void setValue(String category, String key, String value) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.minecrafttas.tasmod.playback.metadata;

import java.util.ArrayList;

import com.minecrafttas.mctcommon.MCTCommon;

public class PlaybackMetadataRegistry {

private static final ArrayList<PlaybackMetadataExtension> METADATA_EXTENSION = new ArrayList<>();

public static void register(PlaybackMetadataExtension extension) {
if(extension==null) {
throw new NullPointerException("Tried to register a playback extension with value null");
}

if(containsClass(extension)) {
MCTCommon.LOGGER.warn("Trying to register the playback extension {}, but another instance of this class is already registered!", extension.getClass().getName());
return;
}

if (!METADATA_EXTENSION.contains(extension)) {
METADATA_EXTENSION.add(extension);
} else {
MCTCommon.LOGGER.warn("Trying to register the playback extension {}, but it is already registered!", extension.getClass().getName());
}
}

public static void unregister(PlaybackMetadataExtension extension) {
if(extension==null) {
throw new NullPointerException("Tried to unregister an extension with value null");
}
if (METADATA_EXTENSION.contains(extension)) {
METADATA_EXTENSION.remove(extension);
} else {
MCTCommon.LOGGER.warn("Trying to unregister the playback extension {}, but it was not registered!", extension.getClass().getName());
}
}

public static PlaybackMetadata handleOnLoad() {
return null; //TODO implement
}

public static void handleOnStore(PlaybackMetadata metadata) {
//TODO
}

private static boolean containsClass(PlaybackMetadataExtension newExtension) {
for(PlaybackMetadataExtension extension : METADATA_EXTENSION) {
if(extension.getClass().equals(newExtension.getClass())) {
return true;
}
}
return false;
}

public static interface PlaybackMetadataExtension {
public PlaybackMetadata onStore();

public void onLoad(PlaybackMetadata metadata);
}
}

0 comments on commit d11b2ac

Please sign in to comment.