Skip to content

Commit

Permalink
Fix Anchorer Run On integration
Browse files Browse the repository at this point in the history
Since growers run anchorers, growOn must contain the anchorOn state
keys. Thus define that for our built-in anchorers and provide a custom
anchorOn option.

Fixes: #4503
  • Loading branch information
InfusOnWoW committed Jun 25, 2023
1 parent 9f1067e commit 6225b88
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 21 deletions.
79 changes: 58 additions & 21 deletions WeakAuras/RegionTypes/DynamicGroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ local anchorers = {
tinsert(frames[Private.personalRessourceDisplayFrame], regionData)
end
end
end
end, {unit = true }
end,
["UNITFRAME"] = function(data)
return function(frames, activeRegions)
Expand All @@ -406,16 +406,26 @@ local anchorers = {
end
end
end
end
end, {unit = true }
end,
["CUSTOM"] = function(data)
local anchorStr = data.customAnchorPerUnit or ""
local anchorFunc = WeakAuras.LoadFunction("return " .. anchorStr) or noop

local anchorOn = nil
local events = WeakAuras.split(data.anchorOn or "")
if #events > 0 then
anchorOn = {}
for _, event in ipairs(events) do
anchorOn[event] = true
end
end

return function(frames, activeRegions)
Private.ActivateAuraEnvironment(data.id)
xpcall(anchorFunc, Private.GetErrorHandlerUid(data.uid, L["Custom Anchor"]), frames, activeRegions)
Private.ActivateAuraEnvironment()
end
end, anchorOn
end
}

Expand Down Expand Up @@ -505,7 +515,10 @@ local growers = {
local limit = data.useLimit and data.limit or math.huge
local startX, startY = 0, 0
local coeff = staggerCoefficient(data.align, data.stagger)
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand All @@ -525,15 +538,18 @@ local growers = {
end
end
end
end
end, anchorOn
end,
RIGHT = function(data)
local stagger = data.stagger or 0
local space = data.space or 0
local limit = data.useLimit and data.limit or math.huge
local startX, startY = 0, 0
local coeff = 1 - staggerCoefficient(data.align, stagger)
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand All @@ -553,15 +569,18 @@ local growers = {
end
end
end
end
end, anchorOn
end,
UP = function(data)
local stagger = data.stagger or 0
local space = data.space or 0
local limit = data.useLimit and data.limit or math.huge
local startX, startY = 0, 0
local coeff = 1 - staggerCoefficient(data.align, stagger)
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand All @@ -581,15 +600,18 @@ local growers = {
end
end
end
end
end, anchorOn
end,
DOWN = function(data)
local stagger = data.stagger or 0
local space = data.space or 0
local limit = data.useLimit and data.limit or math.huge
local startX, startY = 0, 0
local coeff = staggerCoefficient(data.align, stagger)
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand All @@ -609,14 +631,17 @@ local growers = {
end
end
end
end
end, anchorOn
end,
HORIZONTAL = function(data)
local stagger = data.stagger or 0
local space = data.space or 0
local limit = data.useLimit and data.limit or math.huge
local midX, midY = 0, 0
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
local FirstIndex = centeredIndexerStart[data.centerType]
local NextIndex = centeredIndexerNext[data.centerType]
return function(newPositions, activeRegions)
Expand Down Expand Up @@ -647,14 +672,17 @@ local growers = {
i = NextIndex(i, numVisible)
end
end
end
end, anchorOn
end,
VERTICAL = function(data)
local stagger = -(data.stagger or 0)
local space = data.space or 0
local limit = data.useLimit and data.limit or math.huge
local midX, midY = 0, 0
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
local FirstIndex = centeredIndexerStart[data.centerType]
local NextIndex = centeredIndexerNext[data.centerType]
return function(newPositions, activeRegions)
Expand Down Expand Up @@ -683,7 +711,7 @@ local growers = {
i = NextIndex(i, numVisible)
end
end
end
end, anchorOn
end,
CIRCLE = function(data)
local oX, oY = 0, 0
Expand All @@ -693,7 +721,10 @@ local growers = {
local limit = data.useLimit and data.limit or math.huge
local sAngle = (data.rotation or 0) * math.pi / 180
local arc = (data.fullCircle and 360 or data.arcLength or 0) * math.pi / 180
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand Down Expand Up @@ -731,7 +762,7 @@ local growers = {
end
end
end
end
end, anchorOn
end,
COUNTERCIRCLE = function(data)
local oX, oY = 0, 0
Expand All @@ -741,7 +772,10 @@ local growers = {
local limit = data.useLimit and data.limit or math.huge
local sAngle = (data.rotation or 0) * math.pi / 180
local arc = (data.fullCircle and 360 or data.arcLength or 0) * math.pi / 180
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand Down Expand Up @@ -779,7 +813,7 @@ local growers = {
end
end
end
end
end, anchorOn
end,
GRID = function(data)
local gridType = data.gridType
Expand Down Expand Up @@ -828,7 +862,10 @@ local growers = {
if not rowFirst then
primary, secondary = secondary, primary
end
local anchorPerUnitFunc = data.useAnchorPerUnit and createAnchorPerUnitFunc(data)
local anchorPerUnitFunc, anchorOn
if data.useAnchorPerUnit then
anchorPerUnitFunc, anchorOn = createAnchorPerUnitFunc(data)
end
return function(newPositions, activeRegions)
local frames = {}
if anchorPerUnitFunc then
Expand Down Expand Up @@ -918,7 +955,7 @@ local growers = {
end
end
end
end
end, anchorOn
end,
CUSTOM = function(data)
local growStr = data.customGrow or ""
Expand Down
19 changes: 19 additions & 0 deletions WeakAurasOptions/RegionOptions/DynamicGroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ local function createOptions(id, data)
hidden = function() return data.grow == "CUSTOM" end,
disabled = function() return not data.useAnchorPerUnit end
},
anchorOn = {
type = "input",
width = WeakAuras.doubleWidth,
name = L["Run on..."],
desc = L["You can add a comma-separated list of state values here that (when changed) WeakAuras should also run the Anchor Code on.\n\nWeakAuras will always run custom anchor code if you include 'changed' in this list, or when a region is added, removed, or re-ordered."],
order = 1.61,
get = function()
return data.anchorOn or ""
end,
hidden = function()
return not(data.grow ~= "CUSTOM" and data.useAnchorPerUnit and data.anchorPerUnit == "CUSTOM")
end,
set = function(info, v)
data.anchorOn = v
WeakAuras.Add(data)
WeakAuras.ClearAndUpdateOptions(data.id)
OptionsPrivate.ResetMoverSizer()
end
},
-- custom grow option added below
align = {
type = "select",
Expand Down

0 comments on commit 6225b88

Please sign in to comment.