diff --git a/Modules/Config.lua b/Modules/Config.lua index 71dcdfe..aa84c77 100644 --- a/Modules/Config.lua +++ b/Modules/Config.lua @@ -2,6 +2,57 @@ local addonname, shared = ... ---@cast shared HeimdallShared ---@cast addonname string +---@param str string +---@return table +local function StringToMap(str, deliminer) + if not str then return {} end + local map = {} + local parts = { strsplit(deliminer, str) } + for _, line in ipairs(parts) do + line = strtrim(line) + if line ~= "" then + map[line] = true + end + end + return map +end + +---@param str string +---@return string[] +local function StringToArray(str, deliminer) + if not str then return {} end + local ret = {} + local array = { strsplit(deliminer, str) } + for i, line in ipairs(array) do + line = strtrim(line) + if line ~= "" then + ret[i] = line + end + end + return ret +end + +---@param map table +---@param deliminer string +---@return string +local function MapKeyToString(map, deliminer) + local str = "" + for k, _ in pairs(map) do + str = str .. k .. deliminer + end + return str +end +---@param map table +---@param deliminer string +---@return string +local function MapValueToString(map, deliminer) + local str = "" + for _, v in pairs(map) do + str = str .. tostring(v) .. deliminer + end + return str +end + ---@class GridFrame:Frame ---@field name string ---@field columns number @@ -96,8 +147,8 @@ GridFrame = { for _, child in pairs(children) do if child.gridData then child:SetPos() - else - print("Child has no grid data", child) + -- else + -- print("Child has no grid data", child) end end end, @@ -577,81 +628,13 @@ function shared.Config.Init() local ignored = CreateBasicBigEditBox("HeimdallWhoerConfigIgnored", whoerConfigFrame.frame, "Ignored", - table.concat(Heimdall_Data.config.who.ignored or {}, "\n"), + MapKeyToString(Heimdall_Data.config.who.ignored or {}, "\n"), function(self) - --Heimdall_Data.config.who.ignored = self:GetText() + local ignored = StringToMap(self:GetText(), "\n") + Heimdall_Data.config.who.ignored = ignored end) whoerConfigFrame:Add(ignored, 6, 6) end - - --local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function(state) - -- Heimdall_Data.config.spotter.everyone = state - --end) - --spotterEveryoneButton:PutRight(spotterEnableButton) - --spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone) - - --local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function(state) - -- Heimdall_Data.config.spotter.hostile = state - --end) - --spotterHostileButton:PutBelow(spotterEnableButton) - --spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile) - - --local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function(state) - -- Heimdall_Data.config.spotter.alliance = state - --end) - --spotterAllianceButton:PutRight(spotterHostileButton) - --spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance) - - --local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function(state) - -- Heimdall_Data.config.spotter.stinky = state - --end) - --spotterStinkyButton:PutBelow(spotterHostileButton) - --spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky) - - --local spotterThrottleBox = CreateBasicSmallEditBox("HeimdallSpotterThrottle", spotterConfigFrame, "Throttle Time", - -- function(text) - -- Heimdall_Data.config.spotter.throttleTime = tonumber(text) - -- end) - --spotterThrottleBox:PutRight(spotterStinkyButton) - - -- ---@type table - -- local spotterEnableButton = CreateFrame("Button", "HeimdallSpotterEnable", configFrame, "UIPanelButtonTemplate") - -- spotterEnableButton:SetText("Enable Spotter") - -- spotterEnableButton:SetSize(100, 30) - -- spotterEnableButton:SetPoint("TOPLEFT", configFrame, "TOPLEFT", 10, -40) - -- spotterEnableButton:SetScript("OnClick", function() - -- print("Button was clicked!") - -- end) - -- - -- -- Create a text element - -- local text = configFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlight") - -- text:SetText("This is some text in the frame.") - -- text:SetPoint("TOPLEFT", configFrame, "TOPLEFT", 10, -80) - -- - -- -- Create a small edit box - -- local smallEditBox = CreateFrame("EditBox", nil, configFrame) - -- smallEditBox:SetSize(200, 20) - -- smallEditBox:SetPoint("TOPLEFT", configFrame, "TOPLEFT", 10, -110) - -- smallEditBox:SetAutoFocus(false) - -- smallEditBox:SetFontObject("GameFontNormal") - -- smallEditBox:SetScript("OnEnterPressed", function() - -- print("Entered text: " .. smallEditBox:GetText()) - -- end) - -- - -- -- Create a large edit box - -- local largeEditBox = CreateFrame("EditBox", nil, configFrame) - -- largeEditBox:SetSize(280, 100) - -- largeEditBox:SetPoint("TOP", configFrame, "TOP", 0, -150) - -- largeEditBox:SetAutoFocus(false) - -- largeEditBox:SetFontObject("GameFontNormal") - -- largeEditBox:SetMultiLine(true) - -- largeEditBox:EnableMouse(true) - -- largeEditBox:SetMaxLetters(0) - -- largeEditBox:SetScript("OnEscapePressed", function() - -- largeEditBox:ClearFocus() - -- end) - - --configFrame:Hide() print("Heimdall - Config loaded") end