5.19.3
Add methods to the states/allstates table that helps with creating,
updating or remove states in an optimized way
## Advantage of using this function instead of doing a states[key] = {
... }
- If already created, update existing state, and return true if any
value was changed, this can help reduce amount of resources an aura use
- Automatically `return true` when using these functions and any change
was made
## Examples
```Lua
function(states, event, ...)
if event == "PLAYER_TARGET_CHANGED" then
if UnitExists("target") then
-- if state exists it's updated, not replaced
-- show & changed fields can be skipped
states:Update("", {
name = UnitName("target"),
duration = 5,
expirationTime = GetTime() + 5,
progressType = "timed",
autoHide = true
})
else
-- wipe
states:RemoveAll()
end
end
-- no need to return true
end
```
with clones
```Lua
function(states, event, ...)
local currentEssence = UnitPower("player", Enum.PowerType.Essence)
local maxEssence = UnitPowerMax("player", Enum.PowerType.Essence)
for i = 1, 6 do
if i > maxEssence then
states:Remove(i) -- wipe allstates[6]
else
local value = currentEssence >= i and 1 or 0
local newState = {
progressType = "static",
value = value,
total = 1
}
states:Update(i, newState)
end
end
-- no need to return true
end
```
This commit is contained in:
@@ -18,6 +18,8 @@ local SendChatMessage, UnitInBattleground, UnitInRaid, UnitInParty, GetTime
|
||||
local CreateFrame, IsShiftKeyDown, GetScreenWidth, GetScreenHeight, GetCursorPosition, UpdateAddOnCPUUsage, GetFrameCPUUsage, debugprofilestop
|
||||
= CreateFrame, IsShiftKeyDown, GetScreenWidth, GetScreenHeight, GetCursorPosition, UpdateAddOnCPUUsage, GetFrameCPUUsage, debugprofilestop
|
||||
local debugstack = debugstack
|
||||
local GetNumTalentTabs, GetNumTalents = GetNumTalentTabs, GetNumTalents
|
||||
local MAX_NUM_TALENTS = MAX_NUM_TALENTS or 40
|
||||
|
||||
local ADDON_NAME = "WeakAuras"
|
||||
local WeakAuras = WeakAuras
|
||||
@@ -4036,7 +4038,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
|
||||
|
||||
@@ -4365,7 +4369,7 @@ function Private.UpdatedTriggerState(id)
|
||||
|
||||
local changed = false;
|
||||
for triggernum = 1, triggerState[id].numTriggers do
|
||||
triggerState[id][triggernum] = triggerState[id][triggernum] or {};
|
||||
triggerState[id][triggernum] = triggerState[id][triggernum] or setmetatable({}, Private.allstatesMetatable)
|
||||
|
||||
local anyStateShown = false;
|
||||
|
||||
@@ -4456,7 +4460,6 @@ function Private.UpdatedTriggerState(id)
|
||||
end
|
||||
|
||||
for triggernum = 1, triggerState[id].numTriggers do
|
||||
triggerState[id][triggernum] = triggerState[id][triggernum] or {};
|
||||
for cloneId, state in pairs(triggerState[id][triggernum]) do
|
||||
if (not state.show) then
|
||||
triggerState[id][triggernum][cloneId] = nil;
|
||||
@@ -5392,7 +5395,7 @@ function Private.AnchorFrame(data, region, parent, force)
|
||||
local anchorParent = GetAnchorFrame(data, region, parent);
|
||||
if not anchorParent then return end
|
||||
if (data.anchorFrameParent or data.anchorFrameParent == nil
|
||||
or data.anchorFrameType == "SCREEN" or data.anchorFrameType == "UIPARENT" or data.anchorFrameType == "MOUSE") then
|
||||
or data.anchorFrameType == "SCREEN" or data.anchorFrameType == "UIPARENT" or data.anchorFrameType == "MOUSE") then
|
||||
local ok = pcall(region.SetParent, region, anchorParent);
|
||||
if not ok then
|
||||
Private.GetErrorHandlerId(data.id, L["Anchoring"])
|
||||
|
||||
Reference in New Issue
Block a user