diff --git a/WeakAuras/TSUHelpers.lua b/WeakAuras/TSUHelpers.lua index 974f809cf6..eba891a0b8 100644 --- a/WeakAuras/TSUHelpers.lua +++ b/WeakAuras/TSUHelpers.lua @@ -43,17 +43,39 @@ local removeAll = function(states) return changed end -local function recurseUpdate(t1, t2) +local skipKeys = { + trigger = true, + triggernum = true +} + +local function recurseReplaceOrUpdate(t1, t2, isRoot, replace) local changed = false - for k, v in pairs(t2) do - if type(v) == "table" and type(t1[k]) == "table" then - if recurseUpdate(t1[k], v) then + if replace then + -- Remove keys in t1 that are not in t2 + for k in pairs(t1) do + if t2[k] == nil then + t1[k] = nil changed = true end + end + end + for k, v in pairs(t2) do + if isRoot and skipKeys[k] then + -- skip this key else - if t1[k] ~= v then - t1[k] = v - changed = true + if type(v) == "table" then + if type(t1[k]) ~= "table" then + t1[k] = {} + changed = true + end + if recurseReplaceOrUpdate(t1[k], v, false, replace) then + changed = true + end + else + if t1[k] ~= v then + t1[k] = v + changed = true + end end end end @@ -61,12 +83,12 @@ local function recurseUpdate(t1, t2) end ---@type fun(states: states, key: key, newState: state): boolean -local update = function(states, key, newState) +local replaceOrUpdate = function(states, key, newState, replace) local changed = false local state = states[key] if state then fixMissingFields(newState) - changed = recurseUpdate(state, newState) + changed = recurseReplaceOrUpdate(state, newState, true, replace) if changed then state.changed = true states.__changed = true @@ -88,7 +110,31 @@ end local createOrUpdate = function(states, key, newState) key = key or "" if states[key] then - return update(states, key, newState) + return replaceOrUpdate(states, key, newState, false) + else + return create(states, key, newState) + end +end + +---@type fun(states: states, key: key, field: any?): any +---return a state for a key, or a field of a state for a key/field +local get = function(states, key, field) + key = key or "" + local state = states[key] + if state then + if field == nil then + return state + end + return state[field] or nil + end + return nil +end + +---@type fun(states: states, key: key?, newState: state): boolean +local createOrReplace = function(states, key, newState) + key = key or "" + if states[key] then + return replaceOrUpdate(states, key, newState, true) else return create(states, key, newState) end @@ -97,7 +143,9 @@ end Private.allstatesMetatable = { __index = { Update = createOrUpdate, + Replace = createOrReplace, Remove = remove, - RemoveAll = removeAll + RemoveAll = removeAll, + Get = get } } diff --git a/WeakAuras/Types_Vanilla.lua b/WeakAuras/Types_Vanilla.lua index e2ff066cd2..0eaaadd165 100644 --- a/WeakAuras/Types_Vanilla.lua +++ b/WeakAuras/Types_Vanilla.lua @@ -114,6 +114,19 @@ function Private.InitializeEncounterAndZoneLists() { L["Sapphiron"], 1119 }, { L["Kel'Thuzad"], 1114 } } + }, + { + L["Scarlet Enclave"], + { + { L["Balnazzar"], 3185 }, + { L["Beatrix"], 3187 }, + { L["Solistrasza"], 3186 }, + { L["Mason"], 3197 }, + { L["Beastmaster"], 3196 }, + { L["Reborn Council"], 3188 }, + { L["Lillian Voss"], 3190 }, + { L["Caldoran"], 3189 }, + } } }