From 8cc8d5ea6229b60c54a67e80eb2e0b28e1244a1b Mon Sep 17 00:00:00 2001 From: NoM0Re Date: Tue, 28 Jan 2025 10:36:41 +0100 Subject: [PATCH] from retail --- WeakAuras/RegionTypes/Text.lua | 8 +++-- WeakAuras/SubRegionTypes/SubText.lua | 6 ++-- WeakAuras/Types.lua | 51 +++++++++++++++++++++++++--- WeakAuras/WeakAuras.lua | 18 ++++++++-- 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/WeakAuras/RegionTypes/Text.lua b/WeakAuras/RegionTypes/Text.lua index ff48bfc..80af857 100644 --- a/WeakAuras/RegionTypes/Text.lua +++ b/WeakAuras/RegionTypes/Text.lua @@ -186,7 +186,7 @@ local function modify(parent, region, data) containsCustomText = true end - local formatters + local formatters, everyFrameFormatters do local getter = function(key, default) local fullKey = "displayText_format_" .. key @@ -218,7 +218,7 @@ local function modify(parent, region, data) end end - formatters = Private.CreateFormatters(texts, getter, false, data) + formatters, everyFrameFormatters = Private.CreateFormatters(texts, getter, false, data) end local customTextFunc = nil @@ -251,7 +251,9 @@ local function modify(parent, region, data) end local FrameTick - if Private.ContainsPlaceHolders(self.displayText, "p") then + if Private.ContainsPlaceHolders(self.displayText, "p") + or Private.AnyEveryFrameFormatters(self.displayText, everyFrameFormatters) + then FrameTick = UpdateText end diff --git a/WeakAuras/SubRegionTypes/SubText.lua b/WeakAuras/SubRegionTypes/SubText.lua index ac30e5f..d36f11a 100644 --- a/WeakAuras/SubRegionTypes/SubText.lua +++ b/WeakAuras/SubRegionTypes/SubText.lua @@ -244,7 +244,7 @@ local function modify(parent, region, parentData, data, first) end return data[fullKey] end - region.subTextFormatters = Private.CreateFormatters(texts, getter, false, parentData) + region.subTextFormatters, region.everyFrameFormatters = Private.CreateFormatters(texts, getter, false, parentData) function region:ConfigureTextUpdate() local UpdateText @@ -274,7 +274,9 @@ local function modify(parent, region, parentData, data, first) end local FrameTick - if Private.ContainsPlaceHolders(region.text_text, "p") then + if Private.ContainsPlaceHolders(region.text_text, "p") + or Private.AnyEveryFrameFormatters(region.text_text, region.everyFrameFormatters) + then FrameTick = UpdateText end diff --git a/WeakAuras/Types.lua b/WeakAuras/Types.lua index c4d2537..9519214 100644 --- a/WeakAuras/Types.lua +++ b/WeakAuras/Types.lua @@ -260,12 +260,52 @@ Private.format_types = { end local mainFormater = simpleFormatters.time[format] + local modRateProperty = {} + local timePointProperty = {} + + -- For the mod rate support, we need to know which state member is the modRate, as + -- different progressSources can have different modRates + -- Here, we only collect the names, so that the actual formatter can quickly lookup + -- the property + -- This is somewhat complicated by legacy behaviour (for %p, %t) and that %foo, can + -- be the foo of different triggers that might use different modRate properties + -- Similarly to distinguish between time formaters for durations and timepoints, + -- we maintain a lookup table for time points + -- Timepoint formatters need to run every frame, so we rturn true if we + -- are formatting a timepoint + local triggerNum, sym = string.match(symbol, "(.+)%.(.+)") + triggerNum = triggerNum and tonumber(triggerNum) + sym = sym or symbol + + if triggerNum then + local progressSource = Private.GetProgressSourceFor(data, triggerNum, sym) + if progressSource then + if progressSource[2] == "timer" or progressSource[2] == "elapsedTimer" then + timePointProperty[triggerNum] = true + end + end + else + for i = 1, #data.triggers do + local progressSource = Private.GetProgressSourceFor(data, i, symbol) + if progressSource then + if progressSource[2] == "timer" or progressSource[2] == "elapsedTimer" then + timePointProperty[i] = true + end + end + end + end + local formatter if threshold == 0 then formatter = function(value, state, trigger) if type(value) ~= 'number' or value == math.huge then return "" end + + if timePointProperty[trigger] then + value = abs(GetTime() - value) + end + if value <= 0 then return "" end @@ -277,6 +317,11 @@ Private.format_types = { if type(value) ~= 'number' or value == math.huge then return "" end + + if timePointProperty[trigger] then + value = abs(GetTime() - value) + end + if value <= 0 then return "" end @@ -288,8 +333,6 @@ Private.format_types = { end end - local triggerNum, sym = string.match(symbol, "(.+)%.(.+)") - sym = sym or symbol if sym == "p" or sym == "t" then -- Special case %p and %t. Since due to how the formatting -- work previously, the time formatter only formats %p and %t @@ -299,9 +342,9 @@ Private.format_types = { return value end return formatter(value, state, trigger) - end + end, next(timePointProperty) ~= nil else - return formatter + return formatter, next(timePointProperty) ~= nil end end }, diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 2a84715..f1422be 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -4618,6 +4618,8 @@ function Private.ContainsAnyPlaceHolders(textStr) return ContainsPlaceHolders(textStr, function(symbol) return true end, true) end +Private.ContainsPlaceHoldersPredicate = ContainsPlaceHolders + local function ValueForSymbol(symbol, region, customFunc, regionState, regionStates, useHiddenStates, formatters) local triggerNum, sym = string.match(symbol, "(.+)%.(.+)") triggerNum = triggerNum and tonumber(triggerNum) @@ -4790,6 +4792,7 @@ end function Private.CreateFormatters(input, getter, withoutColor, data) local seenSymbols = {} local formatters = {} + local everyFrameFormatters = {} local parseFn = function(symbol) if not seenSymbols[symbol] then @@ -4801,7 +4804,7 @@ function Private.CreateFormatters(input, getter, withoutColor, data) local default = (sym == "p" or sym == "t") and "timed" or "none" local selectedFormat = getter(symbol .. "_format", default) if (Private.format_types[selectedFormat]) then - formatters[symbol] = Private.format_types[selectedFormat].CreateFormatter(symbol, getter, withoutColor, data) + formatters[symbol], everyFrameFormatters[symbol] = Private.format_types[selectedFormat].CreateFormatter(symbol, getter, withoutColor, data) end end end @@ -4816,7 +4819,18 @@ function Private.CreateFormatters(input, getter, withoutColor, data) end end - return formatters + return formatters, everyFrameFormatters +end + +function Private.AnyEveryFrameFormatters(textStr, everyFrameFormatters) + if next(everyFrameFormatters) then + local function predicate(symbol) + if everyFrameFormatters[symbol] then + return true + end + end + return Private.ContainsPlaceHoldersPredicate(textStr, predicate) + end end function Private.IsAuraActive(uid)