Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Provismet committed Jul 19, 2024
1 parent 1c01a13 commit 549277a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.1
loader_version=0.14.22

# Mod Properties
mod_version=0.4.0
mod_version=0.4.1
maven_group=com.provismet
archives_base_name=vmc-mc

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/provismet/vmcmc/config/ClothVMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public static Screen build (Screen parent) {
.build()
);

general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("entry.vmcmc.general.compat_identifiers"), Config.shouldUseCompatibilityIds())
.setDefaultValue(false)
.setTooltip(Text.translatable("tooltip.vmcmc.general.compat_identifiers"))
.setSaveConsumer(newValue -> Config.setCompatibilityIdMode(newValue))
.build()
);

builder.setSavingRunnable(() -> {
Config.saveJSON();
PacketSender.initPort(Config.getIP(), Config.getPort());
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/com/provismet/vmcmc/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import com.provismet.vmcmc.ClientVMC;
import com.provismet.vmcmc.vmc.PacketSender;

import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;

public class Config {
private static final String HOST = "host";
private static final String PORT = "port";
private static final String COMPAT_IDENTIFIERS_LABEL = "compatibility_identifiers";
private static final String FILEPATH = "config/vmc-mc.json";

private static boolean useCompatIds = false;
private static String host = PacketSender.LOCALHOST;
private static int port = PacketSender.DEFAULT_PORT;

Expand All @@ -35,6 +38,10 @@ public static Pair<String,Integer> readJSON () {
port = parser.nextInt();
break;

case COMPAT_IDENTIFIERS_LABEL:
useCompatIds = parser.nextBoolean();
break;

default:
break;
}
Expand All @@ -45,20 +52,21 @@ public static Pair<String,Integer> readJSON () {
catch (FileNotFoundException e) {
ClientVMC.LOGGER.warn("Config not found, creating default config.");
saveJSON();
return new Pair<String,Integer>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT);
return new Pair<>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT);
}
catch (Exception e) {
ClientVMC.LOGGER.warn("Config could not be read, using default parameters.", e);
return new Pair<String,Integer>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT);
return new Pair<>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT);
}
}

public static void saveJSON () {
try {
FileWriter writer = new FileWriter(FILEPATH);
String simpleJSON = String.format("{\n\t\"%s\": \"%s\",\n\t\"%s\": %d\n}",
String simpleJSON = String.format("{\n\t\"%s\": \"%s\",\n\t\"%s\": %d,\n\t\"%s\": %b\n}",
HOST, host,
PORT, port
PORT, port,
COMPAT_IDENTIFIERS_LABEL, useCompatIds
);
writer.write(simpleJSON);
writer.close();
Expand All @@ -68,6 +76,19 @@ public static void saveJSON () {
}
}

public static boolean shouldUseCompatibilityIds () {
return useCompatIds;
}

public static void setCompatibilityIdMode (boolean shouldUseCompat) {
useCompatIds = shouldUseCompat;
}

public static String getBlendName (Identifier blendshape) {
if (useCompatIds) return blendshape.toString().replace(':', '_');
return blendshape.toString();
}

public static String getIP () {
return host;
}
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.illposed.osc.OSCPacket;
import com.provismet.vmcmc.ClientVMC;
import com.provismet.vmcmc.config.Config;
import com.provismet.vmcmc.utility.HealthTracker;

import net.fabricmc.api.EnvType;
Expand All @@ -33,28 +34,28 @@ public class CaptureRegistry {
private static final HashMap<String, BlendStore> BLENDSTORE_REGISTRY = new HashMap<>();

public static BlendStore getBlendStore (Identifier identifier) {
return BLENDSTORE_REGISTRY.get(identifier.toString());
return BLENDSTORE_REGISTRY.get(Config.getBlendName(identifier));
}

public static boolean containsKey (String key) {
return BLEND_REGISTRY.containsKey(key) || BLENDSTORE_REGISTRY.containsKey(key) || BONE_REGISTRY.containsKey(key);
}

public static boolean containsKey (Identifier key) {
return containsKey(key.toString());
return containsKey(Config.getBlendName(key));
}

/**
* Registers a callback that generates a BlendShape. Minecraft identifiers are used to softly-enforce unique names.
*
* It is recommend, but not required, that callbacks have their output bound between 0 and 1.
* <p>
* It is recommended, but not required, that callbacks have their output bound between 0 and 1.
*
* @param identifier The ID for the BlendShape. Note: This will be converted into a string when being sent over OSC.
* @param callback A function that uses the client to output a float.
*/
public static void registerBlendShape (Identifier identifier, Function<MinecraftClient, Float> callback) {
if (containsKey(identifier)) ClientVMC.LOGGER.error("Duplicate BlendShape register attempt: " + identifier.toString());
else BLEND_REGISTRY.put(identifier.toString(), callback);
if (containsKey(identifier)) ClientVMC.LOGGER.error("Duplicate BlendShape register attempt: " + Config.getBlendName(identifier));
else BLEND_REGISTRY.put(Config.getBlendName(identifier), callback);
}

/**
Expand All @@ -72,21 +73,21 @@ public static void registerBlendShape (String path, Function<MinecraftClient, Fl
* @param blendStore The BlendStore to receive input from.
*/
public static void registerBlendStore (Identifier identifier, BlendStore blendStore) {
if (containsKey(identifier)) ClientVMC.LOGGER.error("Duplicate BlendStore register attempt: " + identifier.toString());
else BLENDSTORE_REGISTRY.put(identifier.toString(), blendStore);
if (containsKey(identifier)) ClientVMC.LOGGER.error("Duplicate BlendStore register attempt: " + Config.getBlendName(identifier));
else BLENDSTORE_REGISTRY.put(Config.getBlendName(identifier), blendStore);
}

public static void registerBlendStore (String path, BlendStore blendStore) {
registerBlendStore(ClientVMC.identifier(path), blendStore);
}

/**
* NOTE: BONES ARE CURRENTLY NON-FUNCTIONAL. USE BLENDSHAPES INSTEAD.
*
* Registers a callback that generates a Bone.
* Bones are defined as 7 floats (a 3D coordinate and a quaternion).
* {@code [x coordinate, y coordinate, z coordinate, quaternion-x, quaternion-y, quaternion-z, quaternion-w]}
*
*
* @implNote BONES ARE CURRENTLY NON-FUNCTIONAL. USE BLENDSHAPES INSTEAD.
*
* @param identifier The ID for the Bone. Note: This will be converted into a string when being sent over OSC.
* @param callback A function that uses the client to output a list of floats.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/vmcmc/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

"tooltip.vmcmc.general.ip": "Must be a valid IP address. e.g. 127.0.0.1",
"tooltip.vmcmc.general.port": "Must be a value between 1 and 65535.",
"tooltip.vmcmc.general.compat_identifiers": "Replaces colons with underscores for compatibility with certain vtubing software. Requires restart.",

"entry.vmcmc.general.ip": "IP Address",
"entry.vmcmc.general.port": "Port"
"entry.vmcmc.general.port": "Port",
"entry.vmcmc.general.compat_identifiers": "Compatibility BlendShape Names"
}

0 comments on commit 549277a

Please sign in to comment.