From 4d14662068998fc5287a781f7919787491da00d0 Mon Sep 17 00:00:00 2001 From: Buds Date: Mon, 14 Aug 2023 20:22:18 +0200 Subject: [PATCH] add migration, fix cast trigger, bug fixes --- WeakAuras/Modernize.lua | 65 ++++++++++++++++++++++++++++++++ WeakAuras/Prototypes.lua | 18 ++++----- WeakAuras/WeakAuras.lua | 2 +- WeakAurasOptions/LoadOptions.lua | 2 +- 4 files changed, 76 insertions(+), 11 deletions(-) diff --git a/WeakAuras/Modernize.lua b/WeakAuras/Modernize.lua index d45f4802b3..d068679041 100644 --- a/WeakAuras/Modernize.lua +++ b/WeakAuras/Modernize.lua @@ -1734,5 +1734,70 @@ function Private.Modernize(data) end end + if data.internalVersion < 67 then + local function migrateToTable(tab, field) + local value = tab[field] + if value ~= nil and type(value) ~= "table" then + tab[field] = { value } + end + end + do + local trigger_migration = {} + for triggerName, proto in pairs(Private.event_prototypes) do + for _, field in ipairs(proto.args) do + if field.multiEntry then + trigger_migration[triggerName] = trigger_migration[triggerName] or {} + tinsert(trigger_migration[triggerName], field.name) + if field.type == "number" then + tinsert(trigger_migration[triggerName], field.name.."_operator") + end + end + end + end + for _, triggerData in ipairs(data.triggers) do + local t = triggerData.trigger + local fieldsToMigrate = trigger_migration[t.event] + if fieldsToMigrate then + for _, field in ipairs(fieldsToMigrate) do + migrateToTable(t, field) + end + end + -- cast trigger move data from 'spell' & 'spellId' to 'spellIds' & 'spellNames' + if t.event == "Cast" and t.type == "unit" then + if t.spellId then + if t.useExactSpellId then + t.use_spellIds = t.use_spellId + t.spellIds = t.spellIds or {} + tinsert(t.spellIds, t.spellId) + else + t.use_spellNames = t.use_spellId + t.spellNames = t.spellNames or {} + tinsert(t.spellNames, t.spellId) + end + end + if t.use_spell and t.spell then + t.use_spellNames = true + t.spellNames = t.spellNames or {} + tinsert(t.spellNames, t.spell) + end + t.use_spellId = nil + t.spellId = nil + t.use_spell = nil + t.spell = nil + end + end + end + do + for _, field in ipairs(Private.load_prototype.args) do + if field.multiEntry then + migrateToTable(data.load, field.name) + if field.type == "number" then + migrateToTable(data.load, field.name.."_operator") + end + end + end + end + end + data.internalVersion = max(data.internalVersion or 0, WeakAuras.InternalVersion()) end diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 567b857849..86bbdb9039 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -4948,7 +4948,7 @@ Private.event_prototypes = { type = "spell", init = "arg", showExactOption = true, - test = "Private.ExecEnv.CompareSpellIds(spellName, %s, %s)", + test = "Private.ExecEnv.CompareSpellIds(spellName, %q, %s)", } }, nameFunc = function(trigger) @@ -5009,7 +5009,7 @@ Private.event_prototypes = { type = "spell", init = "arg", showExactOption = true, - test = "Private.ExecEnv.CompareSpellIds(spellName, %s, %s)", + test = "Private.ExecEnv.CompareSpellIds(spellName, %q, %s)", }, { name = "direction", @@ -8205,7 +8205,7 @@ Private.event_prototypes = { display = L["Name(s)"], type = "spell", enable = function(trigger) return not trigger.use_inverse end, - test = "Private.ExecEnv.CompareSpellIds(spellId, %s, false)", + test = "Private.ExecEnv.CompareSpellIds(spellId, %q, false)", multiEntry = { operator = "or", }, @@ -8216,28 +8216,28 @@ Private.event_prototypes = { display = L["Exact Spell ID(s)"], type = "spell", enable = function(trigger) return not trigger.use_inverse end, - test = "Private.ExecEnv.CompareSpellIds(spellId, %s, true)", + test = "Private.ExecEnv.CompareSpellIds(spellId, %q, true)", multiEntry = { operator = "or", }, }, - { -- TODO migrate into spellIds + { name = "spellId", display = L["Spell ID"], conditionType = "number", store = true, + test = "true", hidden = true }, - --[[ TODO migrate into spellNames { name = "spell", - display = L["Legacy Spellname"], + display = L["Spellname"], type = "string", - enable = function(trigger) return not trigger.use_inverse end, conditionType = "string", store = true, + test = "true", + hidden = true }, - ]] { name = "castType", display = L["Cast Type"], diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index afe1729721..3e039283ac 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -1,7 +1,7 @@ --- @type string, Private local AddonName, Private = ... -local internalVersion = 66 +local internalVersion = 67 -- Lua APIs local insert = table.insert diff --git a/WeakAurasOptions/LoadOptions.lua b/WeakAurasOptions/LoadOptions.lua index 4e107c85b8..cd56d15161 100644 --- a/WeakAurasOptions/LoadOptions.lua +++ b/WeakAurasOptions/LoadOptions.lua @@ -664,7 +664,7 @@ function OptionsPrivate.ConstructOptions(prototype, data, startorder, triggernum order = order + 1; options[name..suffix] = { type = "input", - width = (arg.showExactOption and (WeakAuras.doubleWidth - WeakAuras.halfWidth) or WeakAuras.normalWidth) - (arg.showExactOption and 0.2 or 0), + width = (arg.showExactOption and WeakAuras.doubleWidth or WeakAuras.normalWidth) - (arg.showExactOption and 0.2 or 0), name = arg.display, order = order, hidden = hidden,