Trigger:SetState now also takes doUpdate boolean

If the state the state does change and the trigger is active and
doUpdate is true, then the indicator is updated with the given data.
This commit is contained in:
2023-04-08 19:35:08 +02:00
parent 275f0c4b23
commit 22dee8b536
3 changed files with 8 additions and 7 deletions

View File

@@ -51,7 +51,7 @@ end
--- Reset the AuraTrigger to the default state
function AuraTrigger:Reset()
self.count = 0
self:SetState(self.count >= self.requiredCount)
self:SetState(self.count >= self.requiredCount, nil, false)
end
---Check if a given aura matches this AuraTrigger
@@ -73,7 +73,7 @@ function AuraTrigger:AddAura(aura)
return
end
self.count = self.count + 1
self:SetState(self.count >= self.requiredCount, {stacks=aura.applications})
self:SetState(self.count >= self.requiredCount, {stacks=aura.applications}, false)
end
---Inform the trigger about an updated aura
@@ -92,5 +92,5 @@ function AuraTrigger:RemoveAura(aura)
return
end
self.count = self.count - 1
self:SetState(self.count >= self.requiredCount)
self:SetState(self.count >= self.requiredCount, nil, false)
end

View File

@@ -49,5 +49,5 @@ end
-- status:
-- Must be a valid UnitAuraInfo
function StatusTrigger:UpdateStatus(count)
self:SetState(count >= self.requiredCount)
self:SetState(count >= self.requiredCount, nil, false)
end

View File

@@ -48,9 +48,8 @@ end
---Set the state of the trigger. Will activate the indicator if needed.
---@param data table<string,any> | nil
---@param state boolean
function Trigger:SetState(state, data)
function Trigger:SetState(state, data, doUpdate)
state = state ~= self.invert -- state xor inverted
if self.active ~= state then
if state then
self.indicator:Show(data)
@@ -58,12 +57,14 @@ function Trigger:SetState(state, data)
self.indicator:Hide()
end
self.active = state
elseif doUpdate and self.active then
self.indicator:Update(data)
end
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)
self:SetState(false, nil, false)
end