From 8be0732930159c76a62f07ce25ec40bd27227ad0 Mon Sep 17 00:00:00 2001 From: omicron Date: Thu, 25 Jun 2026 21:58:04 +0200 Subject: [PATCH] Replace Trigger:SetState by Trigger:SetStateAndData Update the use of the old API in most triggers except AuraTrigger. This means the code isn't in a working state at this commit. --- src/types/triggers/multitrigger.lua | 11 ++++------- src/types/triggers/statustrigger.lua | 2 +- src/types/triggers/trigger.lua | 22 ++++++++++++++++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/types/triggers/multitrigger.lua b/src/types/triggers/multitrigger.lua index f065bb7..ac38768 100644 --- a/src/types/triggers/multitrigger.lua +++ b/src/types/triggers/multitrigger.lua @@ -92,8 +92,7 @@ function MultiTrigger:OnChildActivate(idx, trigger, data) table.sort(activeChildren) -- The highest priority active trigger has changed if activeChild ~= activeChildren[1] then - self:SetData(data) - self:SetState(true, true) + self:SetStateAndData(true, data) end end @@ -117,11 +116,9 @@ function MultiTrigger:OnChildDeactivate(idx, trigger, data) local newActiveChild = activeChildren[1] if activeChild ~= newActiveChild then if activeChildren[1] ~= nil then - self:SetData(childrenData[newActiveChild]) - self:SetState(true, true) + self:SetStateAndData(true, childrenData[newActiveChild]) else - self:SetData({}) - self:SetState(false, false) + self:SetStateAndData(false, {}) end end end @@ -139,5 +136,5 @@ end -- Reset the trigger to the default state. If this changes the activation of the -- trigger then the target will be notified. function MultiTrigger:Reset() - self:SetState(false) + self:SetStateAndData(false, {}) end diff --git a/src/types/triggers/statustrigger.lua b/src/types/triggers/statustrigger.lua index c28ab32..a8e07e7 100644 --- a/src/types/triggers/statustrigger.lua +++ b/src/types/triggers/statustrigger.lua @@ -58,5 +58,5 @@ end -- status: -- Must be a valid UnitAuraInfo function StatusTrigger:UpdateStatus(count) - self:SetState(count >= self.requiredCount, false) + self:SetStateAndData(count >= self.requiredCount, nil) end diff --git a/src/types/triggers/trigger.lua b/src/types/triggers/trigger.lua index dfc306b..9209bb1 100644 --- a/src/types/triggers/trigger.lua +++ b/src/types/triggers/trigger.lua @@ -47,7 +47,9 @@ function Trigger:Init(invert, defaultData) end ---Save new data from the datasource into the trigger. This method will make ----sure the default data is always present +---sure the default data is always present. This method will not ensure the +---target gets notified of new state or new data. Subclasses of Trigger should +---use Trigger:SetStateAndData instead. ---@param data table function Trigger:SetData(data) if self.defaultData then @@ -69,9 +71,21 @@ function Trigger:SetTarget(target) end end ----Set the state of the trigger. Will activate the indicator if needed. +---Set the data and state of the trigger. Will update the trigger as needed. +--- +--- If the state changes this function will call Show or Hide on the indicator. +--- If the state remains the same and the data is not nil, it will call Update +--- on the indicator. +--- ---@param state boolean -function Trigger:SetState(state, doUpdate) +---@param data table|nil +function Trigger:SetStateAndData(state, data) + local doUpdate = false + if data then + doUpdate = true + self:SetData(data) + end + state = state ~= self.invert -- state xor inverted if self.active ~= state then if state then @@ -88,5 +102,5 @@ end -- Reset the trigger to the default state. If this changes the activation of the -- trigger then the target will be notified. function Trigger:Reset() - self:SetState(false, false) + self:SetStateAndData(false, nil) end