diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index c72cd96ac2..d861471b6d 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -4267,7 +4267,7 @@ function GenericTrigger.GetOverlayInfo(data, triggernum) count = variables.additionalProgress; end else - local allStates = {}; + local allStates = setmetatable({}, Private.allstatesMetatable) Private.ActivateAuraEnvironment(data.id); RunTriggerFunc(allStates, events[data.id][triggernum], data.id, triggernum, "OPTIONS"); Private.ActivateAuraEnvironment(nil); diff --git a/WeakAuras/TSUHelpers.lua b/WeakAuras/TSUHelpers.lua new file mode 100644 index 0000000000..cb9578eea6 --- /dev/null +++ b/WeakAuras/TSUHelpers.lua @@ -0,0 +1,85 @@ +if not WeakAuras.IsLibsOK() then return end +---@type string +local AddonName = ... +---@class Private +local Private = select(2, ...) + +---@alias key string | integer +---@alias states table + +---@type fun(state: state) +local function fixMissingFields(state) + if type(state) ~= "table" then return end + -- set show + if state.show == nil then + state.show = true + end +end + +---@type fun(states: states, key: key): boolean +local remove = function(states, key) + local changed = false + local state = states[key] + if state then + state.show = false + state.changed = true + changed = true + end + return changed +end + +---@type fun(states: states): boolean +local removeAll = function(states) + local changed = false + for _, state in pairs(states) do + state.show = false + state.changed = true + changed = true + end + return changed +end + +---@type fun(states: states, newState: state, key: key): boolean +local update = function(states, newState, key) + local changed = false + local state = states[key] + if state then + fixMissingFields(newState) + for k, v in pairs(newState) do + if state[k] ~= v then + state[k] = v + changed = true + end + end + if changed then + state.changed = true + end + end + return changed +end + +---@type fun(states: states, newState: state, key: key): boolean +local create = function(states, newState, key) + states[key] = newState + states[key].changed = true + fixMissingFields(states[key]) + return true +end + +---@type fun(states: states, newState: state, key: key?): boolean +local createOrUpdate = function(states, newState, key) + key = key or "" + if states[key] then + return update(states, newState, key) + else + return create(states, newState, key) + end +end + +Private.allstatesMetatable = { + __index = { + Update = createOrUpdate, + Remove = remove, + RemoveAll = removeAll + } +} diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 50914d6c3f..8e85ebb4ba 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -4404,7 +4404,9 @@ function WeakAuras.GetTriggerStateForTrigger(id, triggernum) if (triggernum == -1) then return Private.GetGlobalConditionState(); end - triggerState[id][triggernum] = triggerState[id][triggernum] or {} + if triggerState[id][triggernum] == nil then + triggerState[id][triggernum] = setmetatable({}, Private.allstatesMetatable) + end return triggerState[id][triggernum]; end diff --git a/WeakAuras/WeakAuras.toc b/WeakAuras/WeakAuras.toc index 0c845132bd..baa86da0bf 100644 --- a/WeakAuras/WeakAuras.toc +++ b/WeakAuras/WeakAuras.toc @@ -59,6 +59,7 @@ GenericTrigger.lua BossMods.lua # Helper Systems +TSUHelpers.lua AuraWarnings.lua AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua diff --git a/WeakAuras/WeakAuras_Cata.toc b/WeakAuras/WeakAuras_Cata.toc index 3506b61504..bd7a4a216d 100644 --- a/WeakAuras/WeakAuras_Cata.toc +++ b/WeakAuras/WeakAuras_Cata.toc @@ -59,6 +59,7 @@ GenericTrigger.lua BossMods.lua # Helper Systems +TSUHelpers.lua AuraWarnings.lua AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua diff --git a/WeakAuras/WeakAuras_Vanilla.toc b/WeakAuras/WeakAuras_Vanilla.toc index 650a80b761..3a51e30e5c 100644 --- a/WeakAuras/WeakAuras_Vanilla.toc +++ b/WeakAuras/WeakAuras_Vanilla.toc @@ -51,6 +51,7 @@ GenericTrigger.lua BossMods.lua # Helper Systems +TSUHelpers.lua AuraWarnings.lua AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua