Add Trigger.CreateFromConfig function to help initialize new triggers

This commit is contained in:
2023-04-09 20:26:39 +02:00
parent 0436f8a0e0
commit 3a1cc35a1e
5 changed files with 55 additions and 24 deletions

View File

@@ -29,12 +29,6 @@ local SquareIndicator = types.SquareIndicator
---@class SquareIndicator
local BorderIndicator = types.BorderIndicator
---@class AuraTrigger
local AuraTrigger = types.AuraTrigger
---@class StatusTrigger
local StatusTrigger = types.StatusTrigger
---@class UnitFrame
local UnitFrame = types.CreateClass("UnitFrame")
types.UnitFrame = UnitFrame
@@ -97,27 +91,15 @@ function UnitFrame:Init(unit, config)
end
function UnitFrame:CreateTriggers(triggers)
for _, trigger in ipairs(triggers) do
local kind = trigger.kind
local indicator = self:CreateIndicator(trigger.indicator)
if kind == "AuraTrigger" then
local at = AuraTrigger:new(
trigger.spellId,
trigger.own,
trigger.requiredCount,
trigger.invert
)
at:SetTarget(indicator)
self.auras:AddTrigger(at)
elseif kind == "StatusTrigger" then
local st = StatusTrigger:new(trigger.status, trigger.requiredCount, trigger.invert)
st:SetTarget(indicator)
self.auras:AddTrigger(st)
end
for _, config in ipairs(triggers) do
local indicator = self:CreateIndicator(config.indicator)
---@type Trigger
local triggerType = types[config.kind]
local trigger = triggerType.CreateFromConfig(self, config)
trigger:SetTarget(indicator)
end
end
function UnitFrame:CreateIndicator(indicator)
local kind = indicator.kind
if kind == "SquareIndicator" then