diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-14 13:08:14 -0500 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-14 13:08:14 -0500 |
commit | 27aa4095270f943ddab2a4e4d370e225766c7ff7 (patch) | |
tree | f1d71fe46072cfab38ad833be96600bd26c04cb7 /src/main/kotlin/cc | |
parent | 3470ee81c4444c5955f7899acce226dae14a3da4 (diff) | |
download | Chatting-27aa4095270f943ddab2a4e4d370e225766c7ff7.tar.gz Chatting-27aa4095270f943ddab2a4e4d370e225766c7ff7.tar.bz2 Chatting-27aa4095270f943ddab2a4e4d370e225766c7ff7.zip |
change directory of chat tabs and shortcuts
Diffstat (limited to 'src/main/kotlin/cc')
4 files changed, 85 insertions, 73 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt index d74dd6a..27f1a87 100644 --- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt +++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt @@ -67,12 +67,7 @@ object Chatting { private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'") - val modDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME) - - @Mod.EventHandler - fun onFMLPreInitialization(event: FMLPreInitializationEvent) { - if (!modDir.exists()) modDir.mkdirs() - } + val oldModDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME) @Mod.EventHandler fun onInitialization(event: FMLInitializationEvent) { diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt index f3145de..6add813 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt @@ -1,12 +1,14 @@ package cc.woverflow.chatting.chat +import cc.polyfrost.oneconfig.config.core.ConfigUtils import cc.woverflow.chatting.Chatting import com.google.gson.JsonObject import com.google.gson.JsonParser import java.io.File object ChatShortcuts { - private val shortcutsFile = File(Chatting.modDir, "chatshortcuts.json") + private val oldShortcutsFile = File(Chatting.oldModDir, "chatshortcuts.json") + private val shortcutsFile = ConfigUtils.getProfileFile("chatshortcuts.json") private val PARSER = JsonParser() private var initialized = false @@ -31,9 +33,13 @@ object ChatShortcuts { } if (!shortcutsFile.exists()) { shortcutsFile.createNewFile() - shortcutsFile.writeText( + if (oldShortcutsFile.exists()) { + shortcutsFile.writeText( + oldShortcutsFile.readText() + ) + } else { JsonObject().toString() - ) + } } else { val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject for (shortcut in jsonObj.entrySet()) { diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt index b6027a7..cb95c53 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt @@ -1,5 +1,6 @@ package cc.woverflow.chatting.chat +import cc.polyfrost.oneconfig.config.core.ConfigUtils import cc.woverflow.chatting.Chatting import cc.woverflow.chatting.gui.components.TabButton import com.google.gson.GsonBuilder @@ -26,7 +27,8 @@ object ChatTabs { } private var initialized = false - private val tabFile = File(Chatting.modDir, "chattabs.json") + private val tabFile = ConfigUtils.getProfileFile("chattabs.json") + private val oldTabFile = File(Chatting.oldModDir, "chattabs.json") fun initialize() { if (initialized) { @@ -35,78 +37,87 @@ object ChatTabs { initialized = true } if (!tabFile.exists()) { - generateNewFile() + if (oldTabFile.exists()) { + tabFile.writeText(oldTabFile.readText()) + handleFile() + } else { + generateNewFile() + } } else { - try { - val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java) - when (chatTabJson.version) { - 1 -> { - // ver 2 adds `enabled` - chatTabJson.tabs.forEach { - applyVersion2Changes(it.asJsonObject) - applyVersion3Changes(it.asJsonObject) - applyVersion4Changes(it.asJsonObject) - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) - } - 2 -> { - // ver 3 adds ignore_ - chatTabJson.tabs.forEach { - applyVersion3Changes(it.asJsonObject) - applyVersion4Changes(it.asJsonObject) - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) + handleFile() + } + tabs.forEach { + it.initialize() + } + currentTab = tabs[0] + } + + private fun handleFile() { + try { + val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java) + when (chatTabJson.version) { + 1 -> { + // ver 2 adds `enabled` + chatTabJson.tabs.forEach { + applyVersion2Changes(it.asJsonObject) + applyVersion3Changes(it.asJsonObject) + applyVersion4Changes(it.asJsonObject) + applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } - 3 -> { - // ver 4 adds color options - chatTabJson.tabs.forEach { - applyVersion4Changes(it.asJsonObject) - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) + } + 2 -> { + // ver 3 adds ignore_ + chatTabJson.tabs.forEach { + applyVersion3Changes(it.asJsonObject) + applyVersion4Changes(it.asJsonObject) + applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } - 4 -> { - // ver 5 adds lowercase - chatTabJson.tabs.forEach { - applyVersion5Changes(it.asJsonObject) - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) + } + 3 -> { + // ver 4 adds color options + chatTabJson.tabs.forEach { + applyVersion4Changes(it.asJsonObject) + applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } - 5 -> { - // ver 6 changes pm regex - chatTabJson.tabs.forEach { - applyVersion6Changes(it.asJsonObject) - } - chatTabJson.version = ChatTabsJson.VERSION - tabFile.writeText(GSON.toJson(chatTabJson)) + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) + } + 4 -> { + // ver 5 adds lowercase + chatTabJson.tabs.forEach { + applyVersion5Changes(it.asJsonObject) + applyVersion6Changes(it.asJsonObject) } + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) } - chatTabJson.tabs.forEach { - val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java) - if (chatTab.enabled) { - tabs.add(chatTab) + 5 -> { + // ver 6 changes pm regex + chatTabJson.tabs.forEach { + applyVersion6Changes(it.asJsonObject) } + chatTabJson.version = ChatTabsJson.VERSION + tabFile.writeText(GSON.toJson(chatTabJson)) } - } catch (e: Throwable) { - e.printStackTrace() - tabFile.delete() - generateNewFile() } + chatTabJson.tabs.forEach { + val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java) + if (chatTab.enabled) { + tabs.add(chatTab) + } + } + } catch (e: Throwable) { + e.printStackTrace() + tabFile.delete() + generateNewFile() } - tabs.forEach { - it.initialize() - } - currentTab = tabs[0] } private fun applyVersion2Changes(json: JsonObject) { diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index 55195ce..ab52eb9 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -20,7 +20,7 @@ object ChattingConfig : Config( Mod( Chatting.NAME, ModType.UTIL_QOL, - VigilanceMigrator(File(Chatting.modDir, Chatting.ID + ".toml").toPath().toString()) + VigilanceMigrator(File(Chatting.oldModDir, Chatting.ID + ".toml").toPath().toString()) ), "chatting.json" ) { |