Add Trigger.CreateFromConfig function to help initialize new triggers
This commit is contained in:
@@ -27,6 +27,23 @@ local Trigger = types.Trigger
|
||||
local AuraTrigger = types.CreateClass("AuraTrigger", Trigger)
|
||||
types.AuraTrigger = AuraTrigger
|
||||
|
||||
|
||||
---Creates a new AuraTrigger from a config description and attaches it to the
|
||||
---correct data source
|
||||
---@param unit UnitFrame
|
||||
---@param config table
|
||||
---@return AuraTrigger
|
||||
function AuraTrigger.CreateFromConfig(unit, config)
|
||||
local trigger = AuraTrigger:new(
|
||||
config.spellId,
|
||||
config.own,
|
||||
config.requiredCount,
|
||||
config.invert
|
||||
)
|
||||
unit.auras:AddTrigger(trigger)
|
||||
return trigger
|
||||
end
|
||||
|
||||
---@return AuraTrigger
|
||||
function AuraTrigger.new(cls, ...)
|
||||
--- I really dislike duplicating this everywhere but it makes
|
||||
|
@@ -30,6 +30,20 @@ local Trigger = types.Trigger
|
||||
local MultiTrigger = types.CreateClass("MultiTrigger", Trigger)
|
||||
types.MultiTrigger = MultiTrigger
|
||||
|
||||
---Creates a new MultiTrigger from a config description
|
||||
---@param unit UnitFrame
|
||||
---@param config table
|
||||
---@return MultiTrigger
|
||||
function MultiTrigger.CreateFromConfig(unit, config)
|
||||
local trigger = MultiTrigger:new(config.invert)
|
||||
for _, childConfig in ipairs(config.children) do
|
||||
local childType = types[childConfig.kind]
|
||||
local child = childType.CreateFromConfig(unit, childConfig)
|
||||
trigger:AddTrigger(child)
|
||||
end
|
||||
return trigger
|
||||
end
|
||||
|
||||
--- Initialize a new Trigger object
|
||||
---@param invert boolean|nil
|
||||
function MultiTrigger:Init(invert)
|
||||
|
@@ -25,6 +25,16 @@ local Trigger = types.Trigger
|
||||
local StatusTrigger = types.CreateClass("StatusTrigger", Trigger)
|
||||
types.StatusTrigger = StatusTrigger
|
||||
|
||||
---Creates a new StatusTrigger from a config description
|
||||
---@param unit UnitFrame
|
||||
---@param config table
|
||||
function StatusTrigger.CreateFromConfig(unit, config)
|
||||
local trigger = StatusTrigger:new(config.status, config.requiredCount,
|
||||
config.invert)
|
||||
unit.auras:AddTrigger(trigger)
|
||||
return trigger
|
||||
end
|
||||
|
||||
---@return StatusTrigger
|
||||
function StatusTrigger.new(cls, ...)
|
||||
--- I really dislike duplicating this everywhere but it makes
|
||||
|
@@ -26,6 +26,14 @@ local types = omi.GetModule("types")
|
||||
local Trigger = types.CreateClass("Trigger")
|
||||
types.Trigger = Trigger
|
||||
|
||||
|
||||
---@param unit UnitFrame
|
||||
---@param config table
|
||||
---@return Trigger
|
||||
function Trigger.CreateFromConfig(unit, config)
|
||||
error("Must override")
|
||||
end
|
||||
|
||||
--- Initialize a new Trigger object
|
||||
---@param invert boolean|nil
|
||||
function Trigger:Init(invert)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user