aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-01 21:14:08 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-01 21:14:08 +0200
commit62fd05099a4f0b1cbc88368f0f99cf38ef8c5875 (patch)
tree6ff07c884a423fc72ebcd6bd40f91901b3540faa /src/main/java/at/hannibal2/skyhanni/utils
parent7149f4ef911349637c3a06362588cf2398c34ed7 (diff)
downloadSkyHanni-62fd05099a4f0b1cbc88368f0f99cf38ef8c5875.tar.gz
SkyHanni-62fd05099a4f0b1cbc88368f0f99cf38ef8c5875.tar.bz2
SkyHanni-62fd05099a4f0b1cbc88368f0f99cf38ef8c5875.zip
Using onChange and onToggle for multi config change detection
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 71ad9edf2..60062ed3c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -7,6 +7,8 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonData
import at.hannibal2.skyhanni.test.TestBingo
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.toDashlessUUID
+import io.github.moulberry.moulconfig.observer.Observer
+import io.github.moulberry.moulconfig.observer.Property
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import net.minecraft.client.Minecraft
@@ -245,4 +247,15 @@ object LorenzUtils {
fun isShiftKeyDown() = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)
fun isControlKeyDown() = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)
+
+ // MoulConfig is in Java, I don't want to downgrade this logic
+ fun <T> onChange(vararg properties: Property<out T>, observer: Observer<T>) {
+ for (property in properties) {
+ property.whenChanged { a, b -> observer.observeChange(a, b) }
+ }
+ }
+
+ fun <T> onToggle(vararg properties: Property<out T>, observer: Runnable) {
+ onChange(*properties) { _, _ -> observer.run() }
+ }
} \ No newline at end of file