From 79f6935837fa40c796dc9a62503b83ceb8a846d7 Mon Sep 17 00:00:00 2001 From: NoM0Re <1629787+NoM0Re@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:04:21 +0200 Subject: [PATCH] Fix PUI npcId that never worked correctly --- WeakAuras/Prototypes.lua | 61 ++++++++++++++++++++++++++++++++++++---- WeakAuras/WeakAuras.lua | 34 ++++++++++++++++++++++ 2 files changed, 89 insertions(+), 6 deletions(-) diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index fee5c15..79a7373 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -1417,8 +1417,21 @@ Private.event_prototypes = { display = L["Npc ID"], type = "string", store = true, + init = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '')", conditionType = "string", - test = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '') == %q", + preamble = "local npcIdChecker = WeakAuras.ParseStringCheck(%q)", + test = "npcIdChecker:Check(npcId)", + conditionPreamble = function(input) + return WeakAuras.ParseStringCheck(input) + end, + conditionTest = function(state, needle, op, preamble) + return preamble:Check(state.npcId) + end, + operator_types = "none", + desc = L["Supports multiple entries, separated by commas"], + enable = function(trigger) + return not trigger.use_inverse + end, }, { name = "attackable", @@ -1702,8 +1715,21 @@ Private.event_prototypes = { display = L["Npc ID"], type = "string", store = true, + init = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '')", conditionType = "string", - test = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '') == %q", + preamble = "local npcIdChecker = WeakAuras.ParseStringCheck(%q)", + test = "npcIdChecker:Check(npcId)", + conditionPreamble = function(input) + return WeakAuras.ParseStringCheck(input) + end, + conditionTest = function(state, needle, op, preamble) + return preamble:Check(state.npcId) + end, + operator_types = "none", + desc = L["Supports multiple entries, separated by commas"], + enable = function(trigger) + return not trigger.use_inverse + end, }, { name = "class", @@ -1986,8 +2012,21 @@ Private.event_prototypes = { display = L["Npc ID"], type = "string", store = true, + init = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '')", conditionType = "string", - test = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '') == %q", + preamble = "local npcIdChecker = WeakAuras.ParseStringCheck(%q)", + test = "npcIdChecker:Check(npcId)", + conditionPreamble = function(input) + return WeakAuras.ParseStringCheck(input) + end, + conditionTest = function(state, needle, op, preamble) + return preamble:Check(state.npcId) + end, + operator_types = "none", + desc = L["Supports multiple entries, separated by commas"], + enable = function(trigger) + return not trigger.use_inverse + end, }, { name = "class", @@ -5505,11 +5544,21 @@ Private.event_prototypes = { display = L["Npc ID"], type = "string", store = true, + init = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '')", conditionType = "string", - test = "tostring(tonumber(string.sub(UnitGUID(unit) or '', 8, 12), 16) or '') == %q", + preamble = "local npcIdChecker = WeakAuras.ParseStringCheck(%q)", + test = "npcIdChecker:Check(npcId)", + conditionPreamble = function(input) + return WeakAuras.ParseStringCheck(input) + end, + conditionTest = function(state, needle, op, preamble) + return preamble:Check(state.npcId) + end, + operator_types = "none", + desc = L["Supports multiple entries, separated by commas"], enable = function(trigger) - return not trigger.use_inverse - end + return not trigger.use_inverse + end, }, { name = "class", diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index a300242..1e0b639 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -4786,6 +4786,40 @@ function WeakAuras.ParseZoneCheck(input) return matcher end +function WeakAuras.ParseStringCheck(input) + if not input then return end + local matcher = { + zones = {}, + Check = function(self, zone) + return self.zones[zone] + end, + Add = function(self, z) + self.zones[z] = true + end + } + + local start = 1 + local escaped = false + local partial = "" + for i = 1, #input do + local c = input:sub(i, i) + if escaped then + escaped = false + elseif c == '\\' then + partial = partial .. input:sub(start, i - 1) + start = i + 1 + escaped = true + elseif c == "," then + matcher:Add(partial .. input:sub(start, i - 1):trim()) + start = i + 1 + partial = "" + end + end + matcher:Add(partial .. input:sub(start, #input):trim()) + + return matcher +end + function WeakAuras.IsAuraLoaded(id) return Private.loaded[id] end