aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-06-12 18:01:37 +0200
committerGitHub <noreply@github.com>2024-06-12 18:01:37 +0200
commit488c0e3de136943604e21bee4f49969bd3121895 (patch)
treeba4e3d11a78dabc7169e033120ec697f1fc3c72d /src
parent584f7cd9597aeda0eb44c7d65387d255c592f94c (diff)
downloadskyhanni-488c0e3de136943604e21bee4f49969bd3121895.tar.gz
skyhanni-488c0e3de136943604e21bee4f49969bd3121895.tar.bz2
skyhanni-488c0e3de136943604e21bee4f49969bd3121895.zip
Use EnumMap and fields for config (#2033)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt35
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinBlockFire.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityEnderman.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityFireball.java2
7 files changed, 31 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index dde349f04..687b085f2 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -129,13 +129,13 @@ class SkyHanniMod {
val version: String
get() = Loader.instance().indexedModList[MODID]!!.version
- @JvmStatic
- val feature: Features get() = configManager.features
- val sackData: SackData get() = configManager.sackData
- val friendsData: FriendsJson get() = configManager.friendsData
- val knownFeaturesData: KnownFeaturesJson get() = configManager.knownFeaturesData
- val jacobContestsData: JacobContestsJson get() = configManager.jacobContestData
- val visualWordsData: VisualWordsJson get() = configManager.visualWordsData
+ @JvmField
+ var feature: Features = Features()
+ lateinit var sackData: SackData
+ lateinit var friendsData: FriendsJson
+ lateinit var knownFeaturesData: KnownFeaturesJson
+ lateinit var jacobContestsData: JacobContestsJson
+ lateinit var visualWordsData: VisualWordsJson
lateinit var repo: RepoManager
lateinit var configManager: ConfigManager
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 6be199cb7..db70f7e89 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -36,7 +36,10 @@ import java.io.OutputStreamWriter
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.StandardCopyOption
+import java.util.EnumMap
import kotlin.concurrent.fixedRateTimer
+import kotlin.reflect.KMutableProperty0
+import kotlin.reflect.KMutableProperty1
private fun GsonBuilder.registerIfBeta(create: TypeAdapterFactory): GsonBuilder {
return if (LorenzUtils.isBetaVersion()) {
@@ -54,20 +57,20 @@ class ConfigManager {
var configDirectory = File("config/skyhanni")
}
- val features get() = jsonHolder[ConfigFileType.FEATURES] as Features
- val sackData get() = jsonHolder[ConfigFileType.SACKS] as SackData
- val friendsData get() = jsonHolder[ConfigFileType.FRIENDS] as FriendsJson
- val knownFeaturesData get() = jsonHolder[ConfigFileType.KNOWN_FEATURES] as KnownFeaturesJson
- val jacobContestData get() = jsonHolder[ConfigFileType.JACOB_CONTESTS] as JacobContestsJson
- val visualWordsData get() = jsonHolder[ConfigFileType.VISUAL_WORDS] as VisualWordsJson
-
private val logger = LorenzLogger("config_manager")
- private val jsonHolder = mutableMapOf<ConfigFileType, Any>()
+ private val jsonHolder: Map<ConfigFileType, Any> = EnumMap(ConfigFileType::class.java)
lateinit var processor: MoulConfigProcessor<Features>
private var disableSaving = false
+ private fun setConfigHolder(type: ConfigFileType, value: Any) {
+ require(value.javaClass == type.clazz)
+ @Suppress("UNCHECKED_CAST")
+ (type.property as KMutableProperty0<Any>).set(value)
+ (jsonHolder as MutableMap<ConfigFileType, Any>)[type] = value
+ }
+
fun firstLoad() {
if (jsonHolder.isNotEmpty()) {
logger.log("Loading config despite config being already loaded?")
@@ -76,7 +79,7 @@ class ConfigManager {
for (fileType in ConfigFileType.entries) {
- jsonHolder[fileType] = firstLoadFile(fileType.file, fileType, fileType.clazz.newInstance())
+ setConfigHolder(fileType, firstLoadFile(fileType.file, fileType, fileType.clazz.newInstance()))
}
// TODO use SecondPassedEvent
@@ -265,13 +268,13 @@ class ConfigManager {
}
}
-enum class ConfigFileType(val fileName: String, val clazz: Class<*>) {
- FEATURES("config", Features::class.java),
- SACKS("sacks", SackData::class.java),
- FRIENDS("friends", FriendsJson::class.java),
- KNOWN_FEATURES("known_features", KnownFeaturesJson::class.java),
- JACOB_CONTESTS("jacob_contests", JacobContestsJson::class.java),
- VISUAL_WORDS("visual_words", VisualWordsJson::class.java),
+enum class ConfigFileType(val fileName: String, val clazz: Class<*>, val property: KMutableProperty0<*>) {
+ FEATURES("config", Features::class.java, SkyHanniMod::feature),
+ SACKS("sacks", SackData::class.java, SkyHanniMod::sackData),
+ FRIENDS("friends", FriendsJson::class.java, SkyHanniMod::friendsData),
+ KNOWN_FEATURES("known_features", KnownFeaturesJson::class.java, SkyHanniMod::knownFeaturesData),
+ JACOB_CONTESTS("jacob_contests", JacobContestsJson::class.java, SkyHanniMod::jacobContestsData),
+ VISUAL_WORDS("visual_words", VisualWordsJson::class.java, SkyHanniMod::visualWordsData),
;
val file by lazy { File(ConfigManager.configDirectory, "$fileName.json") }
diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java
index 26b0a1e7d..140fbf007 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java
@@ -91,7 +91,7 @@ public class Position {
}
public float getEffectiveScale() {
- return Math.max(Math.min(getScale() * SkyHanniMod.getFeature().gui.globalScale, 10F), 0.1F);
+ return Math.max(Math.min(getScale() * SkyHanniMod.feature.gui.globalScale, 10F), 0.1F);
}
public float getScale() {
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinBlockFire.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinBlockFire.java
index 4c0f0e3f1..1447411e2 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinBlockFire.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinBlockFire.java
@@ -13,7 +13,7 @@ public class MixinBlockFire {
@Redirect(method = "randomDisplayTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;DDDDDD[I)V"))
private void onLivingUpdate(World world, EnumParticleTypes particleType, double x, double y, double z, double xOffset, double yOffset, double zOffset, int[] parameters) {
- if (!SkyHanniMod.getFeature().misc.particleHiders.hideFireBlockParticles) {
+ if (!SkyHanniMod.feature.misc.particleHiders.hideFireBlockParticles) {
world.spawnParticle(particleType, x, y, z, xOffset, yOffset, zOffset, parameters);
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java
index b9f98662c..652cad931 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java
@@ -13,7 +13,7 @@ public class MixinEntityBlaze {
@Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;DDDDDD[I)V"))
private void onLivingUpdate(World world, EnumParticleTypes particleType, double x, double y, double z, double xOffset, double yOffset, double zOffset, int[] parameters) {
- if (!SkyHanniMod.getFeature().misc.particleHiders.hideBlazeParticles) {
+ if (!SkyHanniMod.feature.misc.particleHiders.hideBlazeParticles) {
world.spawnParticle(particleType, x, y, z, xOffset, yOffset, zOffset, parameters);
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityEnderman.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityEnderman.java
index 1a2485aa6..8b02e1c02 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityEnderman.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityEnderman.java
@@ -13,7 +13,7 @@ public class MixinEntityEnderman {
@Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;DDDDDD[I)V"))
private void onLivingUpdate(World world, EnumParticleTypes particleType, double x, double y, double z, double xOffset, double yOffset, double zOffset, int[] parameters) {
- if (!SkyHanniMod.getFeature().misc.particleHiders.hideEndermanParticles) {
+ if (!SkyHanniMod.feature.misc.particleHiders.hideEndermanParticles) {
world.spawnParticle(particleType, x, y, z, xOffset, yOffset, zOffset, parameters);
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityFireball.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityFireball.java
index b6e701f6c..979bc0075 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityFireball.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityFireball.java
@@ -13,7 +13,7 @@ public class MixinEntityFireball {
@Redirect(method = "onUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;DDDDDD[I)V"))
private void onLivingUpdate(World world, EnumParticleTypes particleType, double x, double y, double z, double xOffset, double yOffset, double zOffset, int[] parameters) {
- if (!SkyHanniMod.getFeature().misc.particleHiders.hideFireballParticles) {
+ if (!SkyHanniMod.feature.misc.particleHiders.hideFireballParticles) {
world.spawnParticle(particleType, x, y, z, xOffset, yOffset, zOffset, parameters);
}
}