From 666bbc46590d915cb2869f9ab3605685c4a61351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Jaro=C5=A1?= Date: Sun, 30 Mar 2025 22:52:27 +0200 Subject: [PATCH] Refactor config initialization and enhance font safety checks --- Addon/Code/FontUtils.lua | 3 +++ Addon/Code/Options.lua | 2 +- CzechQuests.lua | 47 +++++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Addon/Code/FontUtils.lua b/Addon/Code/FontUtils.lua index 15d05a3..ea64d01 100644 --- a/Addon/Code/FontUtils.lua +++ b/Addon/Code/FontUtils.lua @@ -17,6 +17,9 @@ end addon.API.CreateCzechFont = CreateCzechFont local function UpdateCzechFont(FontString, name, size) + if not FontString then + return + end local _, currentSize, flags = FontString:GetFont() FontString:SetFont(FontPath .. name, size or currentSize, flags) end diff --git a/Addon/Code/Options.lua b/Addon/Code/Options.lua index 4673391..875ac03 100644 --- a/Addon/Code/Options.lua +++ b/Addon/Code/Options.lua @@ -125,7 +125,7 @@ local function InitTactics() local layout = Options.layout layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Taktiky")) - CreateCheckbox("TACTIC_ENABLED", "Zapnout", Update) + CreateCheckbox("TACTIC_ENABLED", "Zapnout *", Update) CreateDropdown("TACTIC_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer, Update) diff --git a/CzechQuests.lua b/CzechQuests.lua index 6caf7b5..4f657e4 100644 --- a/CzechQuests.lua +++ b/CzechQuests.lua @@ -14,38 +14,45 @@ addon.data.tactic = {} CzechQuestsAddon = {} CzechQuestsAddon.data = addon.data +local function SetDefault(key, default) + if CzechQuestsAddon_Store.config[key] == nil then + CzechQuestsAddon_Store.config[key] = default + end + return CzechQuestsAddon_Store.config[key] +end + local function InitStore() -- Init Store CzechQuestsAddon_Store = CzechQuestsAddon_Store or {} CzechQuestsAddon_Store.config = CzechQuestsAddon_Store.config or {} -- General Settings - CzechQuestsAddon_Store.config.DEBUG_MODE = CzechQuestsAddon_Store.config.DEBUG_MODE or false + CzechQuestsAddon_Store.config.DEBUG_MODE = SetDefault("DEBUG_MODE", false) -- Quest Settings - CzechQuestsAddon_Store.config.QUEST_ENABLED = CzechQuestsAddon_Store.config.QUEST_ENABLED or true - CzechQuestsAddon_Store.config.QUEST_DARK_MODE = CzechQuestsAddon_Store.config.QUEST_DARK_MODE or false - CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE = CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE or 18 - CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE or 14 - CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME = CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME or 'morpheus_cz.ttf' - CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME = CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME or 'frizquadratatt_cz.ttf' - CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA = CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA or 80 - CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING = CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING or true + CzechQuestsAddon_Store.config.QUEST_ENABLED = SetDefault("QUEST_ENABLED", true) + CzechQuestsAddon_Store.config.QUEST_DARK_MODE = SetDefault("QUEST_DARK_MODE", false) + CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE = SetDefault("QUEST_HEADER_FONT_SIZE", 18) + CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE = SetDefault("QUEST_TEXT_FONT_SIZE", 14) + CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME = SetDefault("QUEST_HEADER_FONT_NAME", 'morpheus_cz.ttf') + CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME = SetDefault("QUEST_TEXT_FONT_NAME", 'frizquadratatt_cz.ttf') + CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA = SetDefault("QUEST_TEXTURE_ALPHA", 80) + CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING = SetDefault("QUEST_TEXTURE_ALPHA_ONLY_MOVING", true) -- Speech Settings - CzechQuestsAddon_Store.config.SPEECH_ENABLED = CzechQuestsAddon_Store.config.SPEECH_ENABLED or true - CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE or 13 - CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME or 'frizquadratatt_cz.ttf' - CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH = CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH or 320 - CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING = CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING or false - CzechQuestsAddon_Store.config.SPEECH_MESSAGE_TEXTURE_ALPHA = CzechQuestsAddon_Store.config.SPEECH_MESSAGE_TEXTURE_ALPHA or 40 - CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X or 0 - CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y or 0 + CzechQuestsAddon_Store.config.SPEECH_ENABLED = SetDefault("SPEECH_ENABLED", true) + CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE = SetDefault("SPEECH_TEXT_FONT_SIZE", 13) + CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME = SetDefault("SPEECH_TEXT_FONT_NAME", 'frizquadratatt_cz.ttf') + CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH = SetDefault("SPEECH_FRAME_WIDTH", 320) + CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING = SetDefault("SPEECH_ORIGINAL_WHEN_MISSING", false) + CzechQuestsAddon_Store.config.SPEECH_MESSAGE_TEXTURE_ALPHA = SetDefault("SPEECH_MESSAGE_TEXTURE_ALPHA", 40) + CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = SetDefault("SPEECH_FRAME_POSITION_X", 0) + CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = SetDefault("SPEECH_FRAME_POSITION_Y", 0) -- Tactic Settings - CzechQuestsAddon_Store.config.TACTIC_ENABLED = CzechQuestsAddon_Store.config.TACTIC_ENABLED or true - CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE or 12 - CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME = CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME or 'frizquadratatt_cz.ttf' + CzechQuestsAddon_Store.config.TACTIC_ENABLED = SetDefault("TACTIC_ENABLED", true) + CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE = SetDefault("TACTIC_TEXT_FONT_SIZE", 12) + CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME = SetDefault("TACTIC_TEXT_FONT_NAME", 'frizquadratatt_cz.ttf') end -- Event handler frame