Files
WeakestAuras/Compat.lua
T
github-actions[bot] 9588a9cf0a WeakestAuras 0.18.0
ClassicAPI 1.18 is now the only requirement

Requirements
- Needs ClassicAPI 1.18.0 or newer. SuperWoW is no longer used, and Nampower is optional.
- On an older ClassicAPI the addon stays off, and a popup links the download.
- Custom triggers on SuperWoW or Nampower events only fire while that mod is installed.

Triggers
- New Combat Log trigger, with lists of spell IDs, spell names and NPC IDs.
  WeakAuras2 auras that use one now import.
- Custom triggers can listen to the combat log with CLEU or CLEU:SUBEVENT.
- Crowd Control matches a specific type (stun, fear, root, silence, disarm and
  more) or a school lockout, with the effect's real timer.
- Saved Crowd Control auras: Root, Silence and Disarm filters carry over; CC and
  Snare become "any type", and snares are no longer detected.
- Cast bars follow pushback and channel updates.

Displays
- Icon cooldown swipes are drawn by the client's own cooldown frame.
- Sound actions play on a chosen channel, and a new Stop sound type ends a
  looping sound.

Fixes
- Cooldown auras no longer sweep on every wand shot.
- The Global Cooldown trigger ignores wand and Auto Shot shots.
2026-10-29 20:41:53 +00:00

63 lines
3.0 KiB
Lua

-- WeakestAuras -- helpers the ported WeakAuras2 idioms lean on that ClassicAPI
-- does not provide. Kept deliberately small: only what's actually used, no speculative polyfills.
-- Upstream section refs (§N) point at design/architecture/weakauras2-reference.md
if WeakestAuras.disabled then return end
local WA = WeakestAuras
-- The first `n` *characters* of a UTF-8 string. A plain string.sub cuts on a
-- byte and can land inside a multi-byte sequence, which renders as a garbage
-- glyph -- and every accented spell name on this client is Latin-1 encoded as
-- UTF-8, so that is the common case rather than the exotic one. Continuation
-- bytes are 0x80-0xBF, so anything outside that range starts a character.
function WA.Utf8Sub(s, n)
if type(s) ~= "string" or type(n) ~= "number" or n < 0 then return s end
local len = string.len(s)
local chars = 0
for i = 1, len do
local b = string.byte(s, i)
if b < 128 or b >= 192 then
if chars == n then return string.sub(s, 1, i - 1) end
chars = chars + 1
end
end
return s
end
-- xpcall-wrapped call with the aura id prefixed onto any error, so a broken
-- aura reports itself and fails alone rather than taking down a whole tick
-- (§12's error-attribution pattern, minus the sandbox). ClassicAPI's xpcall
-- forwards trailing arguments to the callee. The arguments are fixed
-- parameters, capped at eleven -- what the widest call site needs: a compiled
-- trigger function takes (state, event, arg1..arg9). A `...` signature would
-- not do: ClassicAPI rewrites it to 5.0's `arg`, a fresh table per call, and
-- safecall sits under nearly every dispatch in the addon. Returns the
-- pcall-style (ok, result-or-error) so callers can branch on success.
local errHandler = function(err) return err end
function WA.safecall(errTag, fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
if type(fn) ~= "function" then return false, "not a function" end
local ok, res = xpcall(fn, errHandler, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
if not ok then
-- The options preview runs trigger code that was written to read a live
-- event payload, and an aura opted into swallowing that (WA2's
-- ignoreOptionsEventErrors) wants the failure gone, not reported once per
-- preview. Nothing else sets this, and the one setter clears it in the
-- same call.
if WA.silenceErrors then return ok, res end
local message = "[" .. tostring(errTag) .. "] " .. tostring(res)
-- `errTag` is a label for a chat line, and half the call sites are not an
-- aura at all (Comm, the trigger-system dispatch), so it cannot key a
-- per-aura registry. The aura is read off the ambient instead; nil means
-- chat only, which is what a non-aura caller gets. Late-bound because this
-- file loads before both the registry and the aura environment.
local uid = WA.CurrentWarningUid and WA.CurrentWarningUid()
if uid and WA.UpdateWarning then
WA.UpdateWarning(uid, "runtime:" .. tostring(errTag), "error", message, true)
else
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000WeakestAuras|r " .. message, 1, 0.3, 0.3)
end
end
return ok, res
end