wow-addons/tests/test_wf.lua
rope ee9509e52d Windfury!: turn on combat text events, hide Blizzard's text
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:22:39 +00:00

171 lines
6.4 KiB
Lua

-- Runs Windfury.lua against a mock of the WoW API.
-- arg[1] = addon file
local clock = 100
function GetTime() return clock end
STANDARD_TEXT_FONT = "Fonts\\FRIZQT__.TTF"
SOUNDKIT = { RAID_WARNING = 8959, UI_RAID_BOSS_WHISPER_WARNING = 37666 }
local sounds = {}
function PlaySound(id, channel) sounds[#sounds + 1] = id; assert(channel == "Master") end
local fctOn = false
C_CVar = { GetCVarBool = function(n) assert(n == "enableFloatingCombatText"); return fctOn end }
C_CVar.SetCVar = function(n, v) assert(n == "enableFloatingCombatText" and v == "1"); fctOn = true end
local secrets = {}
function issecretvalue(v) return secrets[v] == true end
local spell
C_CombatText = { GetCurrentEventInfo = function() return spell end }
local printed = {}
function print(s) printed[#printed + 1] = s end
SlashCmdList = {}
local frames = {}
local function region()
local r = { shown = true, alpha = 1, scale = 1 }
function r:SetAlpha(a) assert(a >= -1e-9 and a <= 1 + 1e-9, "alpha " .. a); self.alpha = a end
function r:SetScale(s) assert(s > 0); self.scale = s end
function r:Show() self.shown = true end
function r:Hide() self.shown = false end
function r:IsShown() return self.shown end
function r:SetText(t) self.text = t end
local noop = function() end
for _, k in ipairs({ "SetPoint", "ClearAllPoints", "SetAllPoints", "SetSize", "SetTexture", "SetColorTexture",
"SetBlendMode", "SetVertexColor", "SetRotation", "AddMaskTexture", "SetFont", "SetTextColor",
"SetShadowOffset", "SetShadowColor", "SetFrameStrata", "EnableMouse" }) do
r[k] = r[k] or noop
end
return r
end
function CreateFrame(_, name)
local fr = region()
fr.scripts, fr.events = {}, {}
function fr:SetScript(k, fn) self.scripts[k] = fn end
function fr:RegisterEvent(e) self.events[e] = true end
function fr:RegisterUnitEvent(e) self.events[e] = true end
function fr:UnregisterEvent(e) self.events[e] = nil end
function fr:CreateTexture() return region() end
function fr:CreateMaskTexture() return region() end
function fr:CreateFontString() return region() end
frames[#frames + 1] = fr
if name then _G[name] = fr end
return fr
end
UIParent = region()
dofile(arg[1])
local overlay = WindfuryOverlay
local events
for _, fr in ipairs(frames) do if fr.events.ADDON_LOADED and not events then events = fr end end
assert(overlay and events)
local function fire(...) events.scripts.OnEvent(events, ...) end
local function run(sec)
local steps = math.floor(sec / 0.016)
for _ = 1, steps do
clock = clock + 0.016
if overlay.shown then overlay.scripts.OnUpdate(overlay, 0.016) end
end
end
fire("ADDON_LOADED", "Other")
assert(WindfuryDB == nil)
fire("ADDON_LOADED", "Windfury")
assert(events.events.COMBAT_TEXT_UPDATE and not events.events.ADDON_LOADED)
assert(not overlay.shown)
-- Other combat text is ignored but logged.
fire("COMBAT_TEXT_UPDATE", "DAMAGE")
assert(not overlay.shown and WindfuryDB.types.DAMAGE == 1)
-- A readable Windfury proc fires the show, which hides itself again.
spell = "Windfury Weapon"
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
assert(overlay.shown and WindfuryDB.procs == 1 and #sounds == 1)
assert(WindfuryDB.names["Windfury Weapon"] == 1)
run(0.5)
assert(overlay.shown)
run(1)
assert(not overlay.shown, "show should end")
-- A readable non-Windfury extra attack is skipped.
spell = "Hand of Justice"
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
assert(not overlay.shown and WindfuryDB.procs == 1)
-- A secret name counts (combat hides it).
spell = {}
secrets[spell] = true
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
assert(overlay.shown and WindfuryDB.procs == 2)
-- A secret event type is ignored without touching it.
local st = {}
secrets[st] = true
fire("COMBAT_TEXT_UPDATE", st)
-- Procs within the window build a combo; the third adds the second horn.
spell = "Windfury Totem"
run(0.3)
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
run(2)
assert(not overlay.shown)
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
assert(#sounds == 6, "sounds " .. #sounds)
run(3)
-- After a long gap the combo resets: one horn only.
run(10)
local before = #sounds
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
assert(#sounds == before + 1)
run(2)
-- Big combos stay in range.
for _ = 1, 12 do fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS"); run(0.2) end
run(3)
assert(not overlay.shown)
-- Slash command.
SlashCmdList.WINDFURY("off")
fire("COMBAT_TEXT_UPDATE", "EXTRA_ATTACKS")
assert(not overlay.shown)
SlashCmdList.WINDFURY(" ON ")
SlashCmdList.WINDFURY("sound off")
before = #sounds
SlashCmdList.WINDFURY("")
assert(overlay.shown and #sounds == before, "test show, silent")
assert(printed[#printed]:find("Scrolling Combat Text"))
fctOn = true
SlashCmdList.WINDFURY("sound on")
SlashCmdList.WINDFURY("")
assert(not printed[#printed]:find("Scrolling Combat Text"))
-- Debug log: casts and auras by name; a "Windfury Attack" cast fires the show.
C_Spell = { GetSpellName = function(id) return ({ [8517] = "Windfury Attack", [133] = "Fireball" })[id] end }
-- Login turns Scrolling Combat Text on and keeps Blizzard's text hidden.
fctOn = false
local fctFrame
for _, fr in ipairs(frames) do if fr.events.PLAYER_LOGIN and fr.events.ADDON_LOADED then fctFrame = fr end end
fctFrame.scripts.OnEvent(fctFrame, "PLAYER_LOGIN")
assert(fctOn and WindfuryDB.hideBlizzardText)
CombatText = CreateFrame("Frame")
function CombatText:HookScript(k, fn) local o = self[k]; self.onShow = fn end
fctFrame.scripts.OnEvent(fctFrame, "ADDON_LOADED", "Blizzard_CombatText")
assert(not CombatText.shown)
CombatText:Show(); CombatText.onShow(CombatText)
assert(not CombatText.shown)
local dbg
for _, fr in ipairs(frames) do if fr.events.PLAYER_LOGIN then dbg = fr end end
dbg.scripts.OnEvent(dbg, "PLAYER_LOGIN")
assert(WindfuryDB.debug.fct == true)
run(5)
local procs = WindfuryDB.procs
dbg.scripts.OnEvent(dbg, "UNIT_SPELLCAST_SUCCEEDED", "player", "guid", 133)
assert(not overlay.shown and WindfuryDB.debug.casts["133 Fireball"] == 1)
dbg.scripts.OnEvent(dbg, "UNIT_SPELLCAST_SUCCEEDED", "player", "guid", 8517)
assert(overlay.shown and WindfuryDB.procs == procs + 1)
dbg.scripts.OnEvent(dbg, "UNIT_SPELLCAST_SUCCEEDED", "player", "guid", st)
assert(WindfuryDB.debug.casts.secret == 1)
dbg.scripts.OnEvent(dbg, "UNIT_AURA", "player", { addedAuras = { { spellId = 1, name = "Flurry" }, { spellId = st, name = "x" } } })
assert(WindfuryDB.debug.auras["1 Flurry"] == 1 and WindfuryDB.debug.auras.secret == 1)
print = _G.print
io.write("ok\n")