From 62fd05099a4f0b1cbc88368f0f99cf38ef8c5875 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 1 May 2023 21:14:08 +0200 Subject: Using onChange and onToggle for multi config change detection --- src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') 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 onChange(vararg properties: Property, observer: Observer) { + for (property in properties) { + property.whenChanged { a, b -> observer.observeChange(a, b) } + } + } + + fun onToggle(vararg properties: Property, observer: Runnable) { + onChange(*properties) { _, _ -> observer.run() } + } } \ No newline at end of file -- cgit