diff options
author | syeyoung <cyong06@naver.com> | 2020-12-27 00:11:20 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2020-12-27 00:11:20 +0900 |
commit | 1a9e56df1b9fba821b2c7019a3f47694d765e74f (patch) | |
tree | 0bdb8f43e771e6a004d12d344e8e59490fabf407 /src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java | |
parent | 21abe2f9ea26f17f6d332ca7bf3f4b0f044aa77a (diff) | |
download | Skyblock-Dungeons-Guide-1a9e56df1b9fba821b2c7019a3f47694d765e74f.tar.gz Skyblock-Dungeons-Guide-1a9e56df1b9fba821b2c7019a3f47694d765e74f.tar.bz2 Skyblock-Dungeons-Guide-1a9e56df1b9fba821b2c7019a3f47694d765e74f.zip |
massive overhaul
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java new file mode 100644 index 00000000..4964ee5f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java @@ -0,0 +1,64 @@ +package kr.syeyoung.dungeonsguide.features; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import kr.syeyoung.dungeonsguide.config.types.TypeConverter; +import kr.syeyoung.dungeonsguide.config.types.TypeConverterRegistry; +import lombok.Getter; +import lombok.Setter; + +import java.util.*; + +public abstract class AbstractFeature { + @Getter + private final String category; + @Getter + private final String name; + + @Getter + private final String description; + + @Getter + private final String key; + + protected Map<String, FeatureParameter> parameters = new HashMap<String, FeatureParameter>(); + + protected AbstractFeature(String category, String name, String description, String key) { + this.category = category; + this.name = name; + this.description = description; + this.key = key; + } + + @Getter + @Setter + private boolean enabled = false; + + public void drawWorld(float partialTicks) {} + public void drawScreen(float partialTicks) {} + + public List<FeatureParameter> getParameters() { return new ArrayList<FeatureParameter>(parameters.values()); } + + + + public void loadConfig(JsonObject jsonObject) { // gets key, calls it + enabled = jsonObject.get("$enabled").getAsBoolean(); + for (Map.Entry<String, FeatureParameter> parameterEntry : parameters.entrySet()) { + JsonElement element = jsonObject.get(parameterEntry.getKey()); + if (element == null) continue; + TypeConverter typeConverter = TypeConverterRegistry.getTypeConverter(parameterEntry.getValue().getValue_type()); + parameterEntry.getValue().setValue(typeConverter.deserialize(element)); + } + } + + public JsonObject saveConfig() { + JsonObject object = new JsonObject(); + for (Map.Entry<String, FeatureParameter> parameterEntry : parameters.entrySet()) { + TypeConverter typeConverter = TypeConverterRegistry.getTypeConverter(parameterEntry.getValue().getValue_type()); + JsonElement obj = typeConverter.serialize(parameterEntry.getValue().getValue()); + object.add(parameterEntry.getKey(), obj); + } + object.addProperty("$enabled", isEnabled()); + return object; + } +} |