diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 17:07:48 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 17:07:48 +0200 |
commit | 526a5f1da2354d328be10c4d6d2f58b3b73e0d20 (patch) | |
tree | 1e911f85783395436db570a465bd78a8e6f7fc39 | |
parent | bb9dcef4b53d201cf4bcac3bf88d2042a1ce226c (diff) | |
download | CITResewn-526a5f1da2354d328be10c4d6d2f58b3b73e0d20.tar.gz CITResewn-526a5f1da2354d328be10c4d6d2f58b3b73e0d20.tar.bz2 CITResewn-526a5f1da2354d328be10c4d6d2f58b3b73e0d20.zip |
Documentation (44/44, 0/35)
15 files changed, 340 insertions, 22 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java index 56ac01f..886185c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java @@ -1,13 +1,37 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; import java.util.function.Supplier; +/** + * Wrapper to facilitate metadata, registry and creation of condition class types. + * @see #ENTRYPOINT + * @see CITRegistry + */ public class CITConditionContainer<T extends CITCondition> { + /** + * Entrypoint for container singletons, usually kept as a static final field in the condition type's class. + */ public static final String ENTRYPOINT = "citresewn:condition"; + + /** + * Associated condition's class. + */ public final Class<T> condition; + + /** + * Method reference to the condition's constructor or any other supplier of new condition instances. + */ public final Supplier<T> createCondition; + + /** + * Possible names in property groups for the associated condition type.<br> + * Condition names are declared in groups with a mod id prefix to avoid conflicts with other 3rd party + * properties(formatted as "modid:alias").<br> + * If a modid is not declared, defaults to "citresewn" which is handled by CIT Resewn: Defaults. + */ public final String[] aliases; public CITConditionContainer(Class<T> condition, Supplier<T> createCondition, String... aliases) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java index 240f197..dec7098 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java @@ -1,8 +1,18 @@ package shcm.shsupercm.fabric.citresewn.api; +/** + * @see #dispose() + */ @FunctionalInterface public interface CITDisposable { + /** + * Entrypoint for any disposing method that is not covered by CIT Resewn automatically. + * @see #dispose() + */ String ENTRYPOINT = "citresewn:dispose"; + /** + * Invoked just before reloading CITs. Use to clean up and changes CIT loading made. + */ void dispose(); } 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 ada5147..a3d78ae 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java @@ -2,9 +2,24 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +/** + * @see #globalProperty(String, PropertyValue) + */ @FunctionalInterface public interface CITGlobalProperties { + /** + * Entrypoint for handlers of global properties. + * @see #globalProperty(String, PropertyValue) + */ String ENTRYPOINT = "citresewn:global_property"; + /** + * 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() + * @param key name of the property key stripped of its modid + * @param value the value it's been set to + */ void globalProperty(String key, PropertyValue value) throws Exception; } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java index 5aa727d..b49b4a6 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java @@ -3,17 +3,43 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; import shcm.shsupercm.fabric.citresewn.cit.CIT; import shcm.shsupercm.fabric.citresewn.cit.CITType; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import java.util.List; import java.util.function.Supplier; +/** + * Wrapper to facilitate metadata, registry and creation of CIT types. + * @see #ENTRYPOINT + * @see CITRegistry + */ public abstract class CITTypeContainer<T extends CITType> implements CITDisposable { - public static final String ENTRYPOINT = "citresewn:type"; + /** + * Entrypoint for container singletons, usually kept as a static final field in the type's class. + */ + public static final String ENTRYPOINT = "citresewn:type"; + + /** + * Associated type's class. + */ public final Class<T> type; + + /** + * Method reference to the type's constructor or any other supplier of new CIT type instances. + */ public final Supplier<T> createType; + + /** + * Identifier for this type to be used in the "type=" property.<br> + * When used in property groups the type's modid must be added to avoid conflicts with other + * 3rd party types(formatted as "modid:id"). + */ public final String id; + /** + * True when the container should not have any CITs loaded. + */ protected boolean empty = true; public CITTypeContainer(Class<T> type, Supplier<T> createType, String id) { @@ -22,8 +48,16 @@ public abstract class CITTypeContainer<T extends CITType> implements CITDisposab this.id = id; } + /** + * Loads and keeps a copy of loaded CITs of this container's type. + * @param parsedCITs all loaded CITs of this container's type ordered by weight>path + */ protected abstract void load(List<CIT<T>> parsedCITs); + /** + * Loads and keeps a copy of loaded CITs of this container's type. + * @param parsedCITs all loaded CITs of this container's type ordered by weight>path + */ @SuppressWarnings("unchecked") public final void loadUntyped(List<?> parsedCITs) { if (!parsedCITs.isEmpty()) @@ -31,11 +65,22 @@ public abstract class CITTypeContainer<T extends CITType> implements CITDisposab load((List<CIT<T>>) parsedCITs); } + /** + * Unloads CITs from this container.<br> + * Override dispose() to add more logic. + * @see CITDisposable#dispose() + */ public final void unload() { dispose(); empty = true; } + /** + * @see #empty + * @see CITResewnConfig#enabled + * @see ActiveCITs#isActive() + * @return whether this container's associated type should work or not + */ public boolean active() { return !empty && CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive(); } 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 57d34c3..5270d20 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -8,34 +8,69 @@ import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import shcm.shsupercm.fabric.citresewn.pack.GlobalProperties; import shcm.shsupercm.fabric.citresewn.pack.PackParser; +import shcm.shsupercm.fabric.citresewn.mixin.ModelLoaderMixin; import java.util.*; -public class ActiveCITs implements CITDisposable { private ActiveCITs() {} +/** + * Holds and manages the currently loaded CITs. + * @see #getActive() + * @see ModelLoaderMixin + */ +public class ActiveCITs { private ActiveCITs() {} + /** + * @see #load(ResourceManager, Profiler) + * @see #getActive() + * @see #isActive() + */ private static ActiveCITs active = null; + /** + * @see #isActive() + * @return the current active CITs manager or null if none are loaded + */ public static ActiveCITs getActive() { return active; } - + + /** + * @see #getActive() + * @return whether there are active; loaded CITs + */ public static boolean isActive() { return active != null; } + /** + * Currently effective global properties merged from all loaded packs. + */ public final GlobalProperties globalProperties = new GlobalProperties(); + /** + * All loaded CITs ordered by their type's class and their weight. + */ public final Map<Class<? extends CITType>, List<CIT<?>>> cits = new IdentityHashMap<>(); - public static ActiveCITs load(ResourceManager resourceManager, Profiler profiler) { + /** + * Attempts to load/activate CITs from packs in the given resource manager, disposing of any previously loaded CITs if present. + * @see ModelLoaderMixin + * @see PackParser#loadGlobalProperties(ResourceManager, GlobalProperties) + * @see GlobalProperties#callHandlers() + * @see PackParser#parseCITs(ResourceManager) + * @param resourceManager manager containing resourcepacks with possible CITs + * @param profiler loading profiler that was pushed once into "citresewn:reloading_cits" and would pop after + */ + public static void load(ResourceManager resourceManager, Profiler profiler) { profiler.push("citresewn:disposing"); + disposeAll(); if (active != null) { - active.dispose(); + //todo send reset calls to global properties with null value active = null; } if (!CITResewnConfig.INSTANCE.enabled) { profiler.pop(); - return null; + return; } ActiveCITs active = new ActiveCITs(); @@ -60,12 +95,14 @@ public class ActiveCITs implements CITDisposable { private ActiveCITs() {} if (!cits.isEmpty()) ActiveCITs.active = active; - - return ActiveCITs.active; } - @Override - public void dispose() { + /** + * 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(); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java index 62f1da1..989318f 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java @@ -6,11 +6,22 @@ import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +/** + * Common condition parser for booleans. + */ public abstract class BooleanCondition extends CITCondition { + /** + * Parsed boolean. + */ protected boolean value; + /** + * Converts the given context to a boolean to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the boolean value associated with the given context + */ protected boolean getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java index 081c2d8..5bc9354 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java @@ -6,7 +6,13 @@ import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +/** + * Common condition type with no parsing for constant true/false testing output. + */ public class ConstantCondition extends CITCondition { + /** + * What testing contexts will always result in. + */ public final boolean value; public ConstantCondition(boolean value) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java index 0f392d4..44bb906 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java @@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import static java.lang.Double.*; +/** + * Common condition parser for doubles with optional support for ranges, negatives and percentages. + */ public abstract class DoubleCondition extends CITCondition { + /** + * Whether this condition should accept given ranges/negatives/percentages. + */ protected final boolean supportsRanges, supportsNegatives, supportsPercentages; + /** + * If ranges are accepted, parsed minimum/maximum double. If not, minimum is the parsed value. + */ protected double min, max; + + /** + * Whether the parsed value is a range/percentage. + */ protected boolean range = false, percentage = false; protected DoubleCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) { @@ -20,12 +33,22 @@ public abstract class DoubleCondition extends CITCondition { this.supportsPercentages = supportsPercentages; } + /** + * Converts the given context to a double to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the double value associated with the given context + */ protected double getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } + /** + * Converts the given context to a max double to be used when percentages are enabled. + * @param context context to retrieve the max value from + * @return the max double value associated with the given context + */ protected double getPercentageTotalValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java index 56f5fb7..ed69fed 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java @@ -8,14 +8,33 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import java.util.function.Supplier; +/** + * Common condition parser for enum values. + * @see EnumCondition.Aliased + */ public abstract class EnumCondition<T extends Enum<? extends EnumCondition.Aliased>> extends CITCondition { + /** + * Fetches the all of the enum's parsable values. + */ protected final Supplier<T[]> values; + + /** + * Should letter casing be ignored when parsing the enum value. (default true) + */ protected final boolean ignoreCase; + /** + * Parsed enum value. + */ protected T value; + /** + * Converts the given context to an enum value to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the enum value associated with the given context + */ protected T getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } protected EnumCondition(Supplier<T[]> values, boolean ignoreCase) { @@ -44,7 +63,13 @@ public abstract class EnumCondition<T extends Enum<? extends EnumCondition.Alias return getValue(context) == this.value; } + /** + * Gives implementing enums the ability to have multiple aliased names for parsing. + */ public interface Aliased { + /** + * @return all possible names for this enum value + */ default String[] getAliases() { return new String[] { ((Enum<?>) this).name() }; } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java index afc3954..aadaa76 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java @@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import static java.lang.Float.*; +/** + * Common condition parser for floats with optional support for ranges, negatives and percentages. + */ public abstract class FloatCondition extends CITCondition { + /** + * Whether this condition should accept given ranges/negatives/percentages. + */ protected final boolean supportsRanges, supportsNegatives, supportsPercentages; + /** + * If ranges are accepted, parsed minimum/maximum float. If not, minimum is the parsed value. + */ protected float min, max; + + /** + * Whether the parsed value is a range/percentage. + */ protected boolean range = false, percentage = false; protected FloatCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) { @@ -20,12 +33,22 @@ public abstract class FloatCondition extends CITCondition { this.supportsPercentages = supportsPercentages; } + /** + * Converts the given context to a float to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the float value associated with the given context + */ protected float getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } + /** + * Converts the given context to a max float to be used when percentages are enabled. + * @param context context to retrieve the max value from + * @return the max float value associated with the given context + */ protected float getPercentageTotalValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java index 0df5330..4d04b76 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java @@ -8,11 +8,22 @@ import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +/** + * Common condition parser for identifiers. + */ public abstract class IdentifierCondition extends CITCondition { + /** + * Parsed identifier. + */ protected Identifier value; + /** + * Converts the given context to an identifier to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the identifier value associated with the given context + */ protected Identifier getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java index 13c87c6..80937f5 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java @@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import static java.lang.Integer.*; +/** + * Common condition parser for integers with optional support for ranges, negatives and percentages. + */ public abstract class IntegerCondition extends CITCondition { + /** + * Whether this condition should accept given ranges/negatives/percentages. + */ protected final boolean supportsRanges, supportsNegatives, supportsPercentages; + /** + * If ranges are accepted, parsed minimum/maximum integers. If not, minimum is the parsed value. + */ protected int min, max; + + /** + * Whether the parsed value is a range/percentage. + */ protected boolean range = false, percentage = false; protected IntegerCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) { @@ -20,12 +33,22 @@ public abstract class IntegerCondition extends CITCondition { this.supportsPercentages = supportsPercentages; } + /** + * Converts the given context to an integer to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the integer value associated with the given context + */ protected int getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } + /** + * Converts the given context to a max integer to be used when percentages are enabled. + * @param context context to retrieve the max value from + * @return the max integer value associated with the given context + */ protected int getPercentageTotalValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java index 3b9a264..e264b27 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java @@ -12,14 +12,39 @@ import java.util.List; import java.util.function.Supplier; import java.util.regex.Pattern; +/** + * Common condition parser for multiple values separated by any regex expression. + */ public abstract class ListCondition<T extends CITCondition> extends CITCondition { - private static final Pattern PATTERN_WHITESPACE = Pattern.compile("\\p{Zs}+"); + /** + * Regex pattern for any amount of whitespace. + */ + public static final Pattern PATTERN_WHITESPACE = Pattern.compile("\\p{Zs}+"); + /** + * Enum class type associated with this condition. + */ private final Class<T> conditionType; + + /** + * Determines how testing the conditions should work(either in OR checks or AND checks). + * @see ListCondition.Type + */ protected final Type listType; + + /** + * Regex pattern to use to separate given input into conditions. + */ protected final Pattern delimiter; + + /** + * Constructor for new parsed conditions. + */ protected final Supplier<T> conditionSupplier; + /** + * Parsed conditions. + */ protected T[] conditions; protected ListCondition(Class<T> conditionType, Type listType, Pattern delimiter, Supplier<T> conditionSupplier) { @@ -52,7 +77,13 @@ public abstract class ListCondition<T extends CITCondition> extends CITCondition return listType.test(conditions, context); } + /** + * Provides OR and AND gates for all of the list's conditions. + */ public enum Type { + /** + * Testing passes if any of the conditions pass and fails otherwise. + */ OR { @Override public boolean test(CITCondition[] conditions, CITContext context) { @@ -63,6 +94,9 @@ public abstract class ListCondition<T extends CITCondition> extends CITCondition return false; } }, + /** + * Testing passes if all of the conditions pass and fails otherwise. + */ AND { @Override public boolean test(CITCondition[] conditions, CITContext context) { @@ -74,6 +108,9 @@ public abstract class ListCondition<T extends CITCondition> extends CITCondition } }; + /** + * Tests the given context against all of the conditions. + */ public abstract boolean test(CITCondition[] conditions, CITContext context); } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java index 97f58b5..da68bd8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java @@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import static java.lang.Long.*; +/** + * Common condition parser for longs with optional support for ranges, negatives and percentages. + */ public abstract class LongCondition extends CITCondition { + /** + * Whether this condition should accept given ranges/negatives/percentages. + */ protected final boolean supportsRanges, supportsNegatives, supportsPercentages; + /** + * If ranges are accepted, parsed minimum/maximum longs. If not, minimum is the parsed value. + */ protected long min, max; + + /** + * Whether the parsed value is a range/percentage. + */ protected boolean range = false, percentage = false; protected LongCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) { @@ -20,12 +33,22 @@ public abstract class LongCondition extends CITCondition { this.supportsPercentages = supportsPercentages; } + /** + * Converts the given context to a long to compare the parsed value to. + * @param context context to retrieve the compared value from + * @return the long value associated with the given context + */ protected long getValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } + /** + * Converts the given context to a max long to be used when percentages are enabled. + * @param context context to retrieve the max value from + * @return the max llong value associated with the given context + */ protected long getPercentageTotalValue(CITContext context) { - throw new AssertionError(); + throw new AssertionError("Not implemented by this condition"); } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java index 2e887d6..a53e019 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java @@ -8,6 +8,11 @@ import shcm.shsupercm.fabric.citresewn.cit.CITContext; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +/** + * Internal condition used to determine the priority CITs get tested in.<br> + * Weights default to 0 and higher weights get chosen over lower weights.<br> + * When two conflicting CITs have the same weight, their path in the resourcepack is used as a tie breaker. + */ public class WeightCondition extends IntegerCondition { @Entrypoint(CITConditionContainer.ENTRYPOINT) public static final CITConditionContainer<WeightCondition> CONTAINER = new CITConditionContainer<>(WeightCondition.class, WeightCondition::new, |