Refactor config initialization and enhance font safety checks
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good

This commit is contained in:
Roman Jaroš 2025-03-30 22:52:27 +02:00
parent 30e04df022
commit 666bbc4659
3 changed files with 31 additions and 21 deletions

View file

@ -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

View file

@ -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)

View file

@ -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