From 2bf95356dc48eda77860b2cb60c79d895d3fae7f Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 27 Jun 2023 13:32:06 +0200 Subject: [PATCH] review comments --- objects/LuaScriptState.luascriptstate | 2 +- src/core/Global.ttslua | 53 +++++++++++++-------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/objects/LuaScriptState.luascriptstate b/objects/LuaScriptState.luascriptstate index 8070d96c..63cc8fba 100644 --- a/objects/LuaScriptState.luascriptstate +++ b/objects/LuaScriptState.luascriptstate @@ -1 +1 @@ -{"acknowledgedUpgradeVersions":[],"optionPanel":{"cardLanguage":3,"playAreaSnapTags":true,"showAttachmentHelper":false,"showChaosBagManager":false,"showCleanUpHelper":false,"showCustomPlaymatImages":false,"showCYOA":false,"showDisplacementTool":false,"showDrawButton":false,"showHandHelper":[],"showSearchAssistant":[],"showTitleSplash":true,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}} +{"acknowledgedUpgradeVersions":[],"optionPanel":{"cardLanguage":"English","playAreaSnapTags":true,"showAttachmentHelper":false,"showChaosBagManager":false,"showCleanUpHelper":false,"showCustomPlaymatImages":false,"showCYOA":false,"showDisplacementTool":false,"showDrawButton":false,"showHandHelper":[],"showSearchAssistant":[],"showTitleSplash":true,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}} diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index b01b478f..a1393669 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -46,25 +46,14 @@ local SOURCE_REPO = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/ local library, requestObj, modMeta, notificationVisible local acknowledgedUpgradeVersions = {} --- language selection -local LANGUAGE_CODES = { - "zh_CN", -- 简体中文 - "zh_TW", -- 繁體中文 - "de", -- Deutsch - "en", -- English - "es", -- Español - "fr", -- Français - "it" -- Italiano -} - -local LANGUAGE_NAMES = { - "简体中文", - "繁體中文", - "Deutsch", - "English", - "Español", - "Français", - "Italiano" +local LANGUAGES = { + { code = "zh_CN", name = "简体中文" }, + { code = "zh_TW", name = "繁體中文" }, + { code = "de", name = "Deutsch" }, + { code = "en", name = "English" }, + { code = "es", name = "Español" }, + { code = "fr", name = "Français" }, + { code = "it", name = "Italiano" } } --------------------------------------------------------- @@ -861,19 +850,29 @@ end -- called by the language selection dropdown function languageSelected(_, selectedIndex, id) - optionPanel[id] = tonumber(selectedIndex) + optionPanel[id] = LANGUAGES[tonumber(selectedIndex) + 1].name +end + +function returnLanguageId(name) + for index, tbl in ipairs(LANGUAGES) do + for key, value in pairs(tbl) do + if key == "name" and value == name then + return index + end + end + end end -- sets the option panel to the correct state (corresponding to 'optionPanel') function updateOptionPanelState() - for id, enabled in pairs(optionPanel) do - if (type(enabled) == "boolean" and enabled) - or (type(enabled) == "string" and enabled) - or (type(enabled) == "table" and #enabled ~= 0) then + for id, optionValue in pairs(optionPanel) do + if id == "cardLanguage" and type(optionValue) == "string" then + local dropdownId = returnLanguageId(optionValue) - 1 + UI.setAttribute(id, "value", dropdownId) + elseif (type(optionValue) == "boolean" and optionValue) + or (type(optionValue) == "string" and optionValue) + or (type(optionValue) == "table" and #optionValue ~= 0) then UI.setAttribute(id, "isOn", true) - -- hard-coded updating of the language selection dropdown - elseif id == "cardLanguage" and type(enabled) == "number" then - UI.setAttribute(id, "value", enabled) else UI.setAttribute(id, "isOn", "False") end