Skip to content

fixes #5817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2025
Merged

fixes #5817

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 59 additions & 11 deletions WeakAuras/TSUHelpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,52 @@ local removeAll = function(states)
return changed
end

local function recurseUpdate(t1, t2)
local skipKeys = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't quite understand the point of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes the bug with

function(states, event, updatedTriggerNumber, state)
    if event == "TRIGGER" and state then
        states:Update("", state[""])
    end
end

copying state[""].trigger into states[""].trigger which resulted in WeakAurasOptions replacing the custom trigger view with a copy of the view of an other trigger, cf https://discord.com/channels/172440238717665280/598903823800467496/1360233139452121088

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
return changed
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
Expand All @@ -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
Expand All @@ -97,7 +143,9 @@ end
Private.allstatesMetatable = {
__index = {
Update = createOrUpdate,
Replace = createOrReplace,
Remove = remove,
RemoveAll = removeAll
RemoveAll = removeAll,
Get = get
}
}
13 changes: 13 additions & 0 deletions WeakAuras/Types_Vanilla.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
}
}

Expand Down