diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 17:42:04 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 17:42:04 +0200 |
commit | 2356c6bb055079ef03cfd26e9d505ab9cea3960d (patch) | |
tree | 4649c1ee2779b4997d1d386222e523d82786f45f | |
parent | 526a5f1da2354d328be10c4d6d2f58b3b73e0d20 (diff) | |
download | CITResewn-2356c6bb055079ef03cfd26e9d505ab9cea3960d.tar.gz CITResewn-2356c6bb055079ef03cfd26e9d505ab9cea3960d.tar.bz2 CITResewn-2356c6bb055079ef03cfd26e9d505ab9cea3960d.zip |
Modified global properties api a bit
4 files changed, 27 insertions, 36 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java index a59e96c..0bd29e7 100644 --- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java @@ -23,6 +23,7 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import shcm.shsupercm.util.logic.Loops; +import javax.annotation.Nullable; import java.lang.ref.WeakReference; import java.util.*; import java.util.function.Consumer; @@ -152,21 +153,21 @@ public class TypeEnchantment extends CITType { } @Override - public void globalProperty(String key, PropertyValue value) throws Exception { + public void globalProperty(String key, @Nullable PropertyValue value) throws Exception { switch (key) { case "useGlint" -> { - globalUseGlint = Boolean.parseBoolean(value.value()); + globalUseGlint = value == null ? true : Boolean.parseBoolean(value.value()); if (!globalUseGlint && !"false".equalsIgnoreCase(value.value())) throw new Exception("Could not parse boolean"); } case "cap" -> { - globalCap = Integer.parseInt(value.value()); + globalCap = value == null ? Integer.MAX_VALUE : Integer.parseInt(value.value()); } case "method" -> { - globalMergeMethod = MergeMethodIntensity.MergeMethod.parse(value.value()); + globalMergeMethod = value == null ? MergeMethodIntensity.MergeMethod.AVERAGE : MergeMethodIntensity.MergeMethod.parse(value.value()); } case "fade" -> { - globalFade = Float.parseFloat(value.value()); + globalFade = value == null ? 0.5f : Float.parseFloat(value.value()); } } } @@ -182,11 +183,6 @@ public class TypeEnchantment extends CITType { loaded.clear(); loadedLayered.clear(); - - globalUseGlint = true; - globalCap = Integer.MAX_VALUE; - globalMergeMethod = MergeMethodIntensity.MergeMethod.AVERAGE; - globalFade = 0.5f; } public void apply() { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java index a3d78ae..05495af 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java @@ -2,6 +2,8 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +import javax.annotation.Nullable; + /** * @see #globalProperty(String, PropertyValue) */ @@ -16,10 +18,9 @@ public interface CITGlobalProperties { /** * Invoked before CIT parsing for any global property name associated with the handler's modid.<br> * May be called multiple times for a key to overwrite its global property with higher-priority resourcepacks.<br> - * Handlers should take care to reset back any changes global properties make by listening to CIT disposal. - * @see CITDisposable#dispose() + * When unloading resourcepacks(usually before reloading), all keys that were invoked in the previous load will get called again with a null value to allow for disposal. * @param key name of the property key stripped of its modid - * @param value the value it's been set to + * @param value the value it's been set to or null if resetting */ - void globalProperty(String key, PropertyValue value) throws Exception; + void globalProperty(String key, @Nullable PropertyValue value) throws Exception; } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java index 5270d20..82f341f 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -62,9 +62,16 @@ public class ActiveCITs { private ActiveCITs() {} */ public static void load(ResourceManager resourceManager, Profiler profiler) { profiler.push("citresewn:disposing"); - disposeAll(); + for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) + disposable.dispose(); + + for (CITTypeContainer<? extends CITType> typeContainer : CITRegistry.TYPES.values()) + typeContainer.unload(); + if (active != null) { - //todo send reset calls to global properties with null value + active.globalProperties.properties.replaceAll((key, value) -> Set.of()); + active.globalProperties.callHandlers(); + active = null; } @@ -96,17 +103,4 @@ public class ActiveCITs { private ActiveCITs() {} if (!cits.isEmpty()) ActiveCITs.active = active; } - - /** - * Cleans up any registered disposable element. - * @see CITDisposable - * @see CITTypeContainer - */ - public static void disposeAll() { - for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) - disposable.dispose(); - - for (CITTypeContainer<? extends CITType> typeContainer : CITRegistry.TYPES.values()) - typeContainer.unload(); - } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java index c16242f..3e93b07 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java @@ -19,6 +19,7 @@ import java.util.Set; /** * Property group representation of the global cit.properties file. + * @see CITGlobalProperties * @see PackParser#loadGlobalProperties(ResourceManager, GlobalProperties) */ public class GlobalProperties extends PropertyGroup { @@ -59,13 +60,12 @@ public class GlobalProperties extends PropertyGroup { for (PropertyValue value : entry.getValue()) lastValue = value; - if (lastValue != null) - try { - container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue); - } catch (Exception e) { - CITResewn.logErrorLoading("Errored while parsing global properties: Line " + lastValue.position() + " of " + lastValue.propertiesIdentifier() + " in " + lastValue.packName()); - e.printStackTrace(); - } + try { + container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue); + } catch (Exception e) { + CITResewn.logErrorLoading(lastValue == null ? "Errored while disposing global properties" : "Errored while parsing global properties: Line " + lastValue.position() + " of " + lastValue.propertiesIdentifier() + " in " + lastValue.packName()); + e.printStackTrace(); + } } } } |