From 527580c5c6362594909c83213f7d6838790a3ef6 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Sat, 23 Mar 2024 04:14:06 +1100 Subject: Feature: Shwords saves to new file (#1234) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/misc/visualwords/ModifyVisualWords.kt | 15 ++++++++++++++- .../skyhanni/features/misc/visualwords/VisualWordGui.kt | 12 +++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt index 9198438aa..55d9b7202 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/ModifyVisualWords.kt @@ -1,10 +1,13 @@ package at.hannibal2.skyhanni.features.misc.visualwords import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigFileType import at.hannibal2.skyhanni.config.enums.OutsideSbFeature +import at.hannibal2.skyhanni.events.HypixelJoinEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted import at.hannibal2.skyhanni.utils.TimeLimitedCache +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.minutes object ModifyVisualWords { @@ -21,7 +24,7 @@ object ModifyVisualWords { if (!LorenzUtils.inSkyBlock && !OutsideSbFeature.MODIFY_VISUAL_WORDS.isSelected()) return originalText if (modifiedWords.isEmpty()) { - modifiedWords = SkyHanniMod.feature.storage.modifiedWords + modifiedWords.addAll(SkyHanniMod.visualWordsData.modifiedWords) } val cachedResult = textCache.getOrNull(originalText) @@ -49,4 +52,14 @@ object ModifyVisualWords { textCache.put(originalText, modifiedText) return modifiedText } + + @SubscribeEvent + fun onHypixelJoin(event: HypixelJoinEvent) { + val oldModifiedWords = SkyHanniMod.feature.storage.modifiedWords + if (oldModifiedWords.isNotEmpty()) { + SkyHanniMod.visualWordsData.modifiedWords = oldModifiedWords + SkyHanniMod.feature.storage.modifiedWords = emptyList() + SkyHanniMod.configManager.saveConfig(ConfigFileType.VISUAL_WORDS, "Migrate visual words") + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt index 387a3e222..e41803ffb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/visualwords/VisualWordGui.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.misc.visualwords import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigFileType import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils.chat @@ -231,7 +232,7 @@ open class VisualWordGui : GuiScreen() { } if (modifiedWords.size < 1) { - modifiedWords = SkyHanniMod.feature.storage.modifiedWords + modifiedWords = ModifyVisualWords.modifiedWords } if (toRemove != null) { @@ -444,7 +445,7 @@ open class VisualWordGui : GuiScreen() { currentText = "" currentIndex = modifiedWords.size - 1 saveChanges() - pageScroll = -(SkyHanniMod.feature.storage.modifiedWords.size * 30 - 100) + pageScroll = -(modifiedWords.size * 30 - 100) scrollScreen() } currentlyEditing = !currentlyEditing @@ -465,7 +466,7 @@ open class VisualWordGui : GuiScreen() { if (!currentlyEditing) { if (keyCode == Keyboard.KEY_DOWN || keyCode == Keyboard.KEY_S) { if (KeyboardManager.isModifierKeyDown()) { - pageScroll = -(SkyHanniMod.feature.storage.modifiedWords.size * 30 - 100) + pageScroll = -(modifiedWords.size * 30 - 100) } else { pageScroll -= 30 } @@ -549,14 +550,15 @@ open class VisualWordGui : GuiScreen() { pageScroll = 0 } - pageScroll = MathHelper.clamp_int(pageScroll, -(SkyHanniMod.feature.storage.modifiedWords.size * 30 - 100), 0) + pageScroll = MathHelper.clamp_int(pageScroll, -(modifiedWords.size * 30 - 100), 0) lastMouseScroll = 0 } private fun saveChanges() { ModifyVisualWords.modifiedWords = modifiedWords ModifyVisualWords.textCache.clear() - SkyHanniMod.feature.storage.modifiedWords = modifiedWords + SkyHanniMod.visualWordsData.modifiedWords = modifiedWords + SkyHanniMod.configManager.saveConfig(ConfigFileType.VISUAL_WORDS, "Updated visual words") } private fun tryImportFromSBE() { -- cgit