Remove String skeleton config & fix null exception with SkeletonConfig

This commit is contained in:
ButterscotchVanilla committed 2021-12-15 23:00:08 -05:00
1 parent c9740651ba
commit 77fa27a698
5 files changed
+89 -117

No files matched your search

@@ -20,11 +20,6 @@ public abstract class HumanSkeleton {
@ThreadSafe
public abstract void resetSkeletonConfig(SkeletonConfigValue config);
@ThreadSafe
public void resetSkeletonConfig(String config) {
resetSkeletonConfig(SkeletonConfigValue.getByStringValue(config));
}
@ThreadSafe
public void resetAllSkeletonConfigs() {
for (SkeletonConfigValue config : SkeletonConfigValue.values) {
@@ -92,7 +92,7 @@ public class SkeletonConfig {
}
public Float setConfig(SkeletonConfigValue config, Float newValue) {
Float origVal = configs.put(config, newValue);
Float origVal = newValue != null ? configs.put(config, newValue) : configs.remove(config);
// Re-compute the affected offsets
if (autoUpdateOffsets && config.affectedOffsets != null) {
@@ -117,15 +117,24 @@ public class SkeletonConfig {
}
public float getConfig(SkeletonConfigValue config) {
return configs.getOrDefault(config, config.defaultValue);
if (config == null) {
return 0f;
}
// IMPORTANT!! This null check is necessary, getOrDefault seems to randomly decide to return null at times, so this is a secondary check
Float val = configs.getOrDefault(config, config.defaultValue);
return val != null ? val : config.defaultValue;
}
public float getConfig(String config) {
if (config == null) {
return 0f;
}
return getConfig(SkeletonConfigValue.getByStringValue(config));
}
public Boolean setToggle(SkeletonConfigToggle config, Boolean newValue) {
Boolean origVal = toggles.put(config, newValue);
Boolean origVal = newValue != null ? toggles.put(config, newValue) : toggles.remove(config);
if (callback != null) {
try {
@@ -143,10 +152,20 @@ public class SkeletonConfig {
}
public boolean getToggle(SkeletonConfigToggle config) {
return toggles.getOrDefault(config, config.defaultValue);
if (config == null) {
return false;
}
// IMPORTANT!! This null check is necessary, getOrDefault seems to randomly decide to return null at times, so this is a secondary check
Boolean val = toggles.getOrDefault(config, config.defaultValue);
return val != null ? val : config.defaultValue;
}
public boolean getToggle(String config) {
if (config == null) {
return false;
}
return getToggle(SkeletonConfigToggle.getByStringValue(config));
}
@@ -170,6 +189,11 @@ public class SkeletonConfig {
}
protected void setNodeOffset(SkeletonNodeOffset nodeOffset, Vector3f offset) {
if (offset == null) {
setNodeOffset(nodeOffset, 0f, 0f, 0f);
return;
}
setNodeOffset(nodeOffset, offset.x, offset.y, offset.z);
}
@@ -5,23 +5,24 @@ import java.util.Map;
public enum SkeletonConfigValue {
HEAD("Head", "headShift", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HEAD }),
NECK("Neck", "neckLength", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.NECK }),
TORSO("Torso", "torsoLength", 0.7f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST }),
CHEST("Chest", "chestDistance", 0.35f, new SkeletonNodeOffset[] { SkeletonNodeOffset.CHEST, SkeletonNodeOffset.WAIST }),
WAIST("Waist", "waistDistance", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST, SkeletonNodeOffset.HIP }),
HIP_OFFSET("Hip offset", "hipOffset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HIP_TRACKER }),
HIPS_WIDTH("Hips width", "hipsWidth", 0.3f, new SkeletonNodeOffset[] { SkeletonNodeOffset.LEFT_HIP, SkeletonNodeOffset.RIGHT_HIP }),
LEGS_LENGTH("Legs length", "legsLength", 0.84f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE }),
KNEE_HEIGHT("Knee height", "kneeHeight", 0.42f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE, SkeletonNodeOffset.ANKLE }),
FOOT_LENGTH("Foot length", "footLength", 0.05f, new SkeletonNodeOffset[] { SkeletonNodeOffset.FOOT }),
FOOT_OFFSET("Foot offset", "footOffset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.ANKLE }),
HEAD("Head", "headShift", "Head shift", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HEAD }),
NECK("Neck", "neckLength", "Neck length", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.NECK }),
TORSO("Torso", "torsoLength", "Torso length", 0.7f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST }),
CHEST("Chest", "chestDistance", "Chest distance", 0.35f, new SkeletonNodeOffset[] { SkeletonNodeOffset.CHEST, SkeletonNodeOffset.WAIST }),
WAIST("Waist", "waistDistance", "Waist distance", 0.1f, new SkeletonNodeOffset[] { SkeletonNodeOffset.WAIST, SkeletonNodeOffset.HIP }),
HIP_OFFSET("Hip offset", "hipOffset", "Hip offset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.HIP_TRACKER }),
HIPS_WIDTH("Hips width", "hipsWidth", "Hips width", 0.3f, new SkeletonNodeOffset[] { SkeletonNodeOffset.LEFT_HIP, SkeletonNodeOffset.RIGHT_HIP }),
LEGS_LENGTH("Legs length", "legsLength", "Legs length", 0.84f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE }),
KNEE_HEIGHT("Knee height", "kneeHeight", "Knee height", 0.42f, new SkeletonNodeOffset[] { SkeletonNodeOffset.KNEE, SkeletonNodeOffset.ANKLE }),
FOOT_LENGTH("Foot length", "footLength", "Foot length", 0.05f, new SkeletonNodeOffset[] { SkeletonNodeOffset.FOOT }),
FOOT_OFFSET("Foot offset", "footOffset", "Foot offset", 0.0f, new SkeletonNodeOffset[] { SkeletonNodeOffset.ANKLE }),
;
private static final String CONFIG_PREFIX = "body.";
public final String stringVal;
public final String configKey;
public final String label;
public final float defaultValue;
@@ -30,9 +31,10 @@ public enum SkeletonConfigValue {
public static final SkeletonConfigValue[] values = values();
private static final Map<String, SkeletonConfigValue> byStringVal = new HashMap<>();
private SkeletonConfigValue(String stringVal, String configKey, float defaultValue, SkeletonNodeOffset[] affectedOffsets) {
private SkeletonConfigValue(String stringVal, String configKey, String label, float defaultValue, SkeletonNodeOffset[] affectedOffsets) {
this.stringVal = stringVal;
this.configKey = CONFIG_PREFIX + configKey;
this.label = label;
this.defaultValue = defaultValue;