From 27b12a2521bf9f3576814d600589f1e31e0975d8 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 3 Nov 2023 19:08:15 +0100 Subject: fixed check if an existing word already exists with color codes, added support for malformed sbe config and code cleanup. --- .../features/misc/visualwords/VisualWordGui.kt | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/main/java/at') 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 4e845a313..97aae1260 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 @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.misc.visualwords import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.LorenzUtils.chat import at.hannibal2.skyhanni.utils.StringUtils.convertToFormatted @@ -85,7 +86,7 @@ open class VisualWordGui : GuiScreen() { if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x - 30, y - 10, 60, 20)) 0x50828282 else 0x50303030 drawRect(x - 30, y - 10, x + 30, y + 10, colour) - if (shouldDrawImport){ + if (shouldDrawImport) { val importX = guiLeft + sizeX - 45 val importY = guiTop + sizeY - 10 GuiRenderUtils.drawStringCentered("§aImport from SBE", importX, importY) @@ -365,12 +366,12 @@ open class VisualWordGui : GuiScreen() { } currentlyEditing = !currentlyEditing } - if (shouldDrawImport){ + if (shouldDrawImport) { val importX = guiLeft + sizeX - 45 val importY = guiTop + sizeY - 10 if (GuiRenderUtils.isPointInRect(mouseX, mouseY, importX - 45, importY - 10, 90, 20)) { SoundUtils.playClickSound() - tryImport() + tryImportFromSBE() } } } @@ -479,19 +480,18 @@ open class VisualWordGui : GuiScreen() { SkyHanniMod.feature.storage.modifiedWords = modifiedWords } - private fun tryImport() { - if (drawImport) { - val json = ConfigManager.gson.fromJson( - FileReader(sbeConfigPath), - JsonObject::class.java - ) + private fun tryImportFromSBE() { + if (!drawImport) return + try { + val json = ConfigManager.gson.fromJson(FileReader(sbeConfigPath), JsonObject::class.java) var importedWords = 0 var skippedWords = 0 val lists = json["custom"].asJsonObject["visualWords"].asJsonArray + val pattern = "(?.*)@-(?.*)@:-(?false|true)".toPattern() loop@ for (line in lists) { - "(?.*)@-(?.*)@:-(?false|true)".toPattern().matchMatcher(line.asString) { - val from = group("from") - val to = group("to") + pattern.matchMatcher(line.asString) { + val from = group("from").replace("&", "&&") + val to = group("to").replace("&", "&&") val state = group("state").toBoolean() if (modifiedWords.any { it.phrase == from }) { @@ -499,7 +499,7 @@ open class VisualWordGui : GuiScreen() { continue@loop } - modifiedWords.add(VisualWord(from.replace("&", "&&"), to.replace("&", "&&"), state, false)) + modifiedWords.add(VisualWord(from, to, state, false)) importedWords++ } } @@ -508,8 +508,11 @@ open class VisualWordGui : GuiScreen() { SkyHanniMod.feature.storage.visualWordsImported = true drawImport = false } + } catch (t: Throwable) { + ErrorManager.logError(t, "Failed to load visual words from SBE") } } + private fun drawUnmodifiedString(str: String, x: Float, y: Float) { GuiRenderUtils.drawString("§§$str", x, y) } -- cgit