DEV Community

Cover image for Drawing your own DoTs on WoW nameplates without touching the nameplate
Felix Helleckes
Felix Helleckes

Posted on Fully Autonomous

Drawing your own DoTs on WoW nameplates without touching the nameplate

HotsNDots is a small World of Warcraft addon I maintain. It does one thing: it shows only your own damage-over-time effects on enemies and heal-over-time effects on friends, large, above the nameplate, with a seconds countdown and real stack counts. It sits at about 890 downloads on CurseForge, which is modest, but as a QA engineer I found its constraints more interesting than its features.

The interesting part is not the icons. It's the rule the current addon API forces on you: in combat, aura data can be secret, and anything you touch on a Blizzard frame can taint it. This post is about how the addon draws on top of nameplates while never writing a single field on them.

The bug that set the rule

Early versions did the obvious thing: grab the nameplate's UnitFrame, hang your own stuff off it, and hide the default aura frame so you don't get duplicate icons.

Since game version 12.1 that is a trap. Writing a field onto the nameplate's frame, or hiding its aura frame, taints it. A tainted nameplate then fails in places that have nothing to do with your addon. The comment at the top of Nameplates.lua keeps the error message for posterity:

attempt to compare local 'currValue' (a secret number value)
Enter fullscreen mode Exit fullscreen mode

That was the nameplate failing to update its own mana bar. The addon looked innocent from the outside; the default UI broke.

So the file now opens with the rule written down:

-- HotsNDots never reads aura data, and it never touches
-- the Blizzard nameplate itself - the container hangs off our own
-- holder frame and is only anchored to the plate.
Enter fullscreen mode Exit fullscreen mode

The honest cost, also in the changelog: the default nameplate auras are no longer hidden. Correctness beat tidiness.

Let the game fill in the numbers

The trick is an AuraContainer. You create it, describe groups (here: harmful auras and helpful auras), and the game decides which aura goes into which button and writes the values in. Your addon never sees the duration or the stack count; it only provides the regions to draw them into.

local GROUPS = {
    { key = "dots", kind = "HARMFUL", r = 0.65, g = 0.10, b = 0.10 },
    { key = "hots", kind = "HELPFUL", r = 0.10, g = 0.55, b = 0.15 },
}
Enter fullscreen mode Exit fullscreen mode

Each group gets a filter, a sort method and an initializeFrame callback:

container:AddAuraGroup(group.key, ns.FilterString(group.kind, "INCLUDE_NAME_PLATE_ONLY"), {
    maxFrameCount    = ns.GroupMaxFrames(group.kind, cfg.maxIcons),
    candidateFilters = ns.CandidateFilters(group.kind),
    sortMethod       = ns.SortMethod.ExpirationOnly,
    sortDirection    = ns.SortDirection.Normal,
    initializeFrame  = function(button) BuildIcon(group, button) end,
    ...
})
Enter fullscreen mode Exit fullscreen mode

Inside BuildIcon, the addon creates textures and font strings and then registers them with the button instead of writing to them:

button:SetIcon(style.icon)
button:SetDurationCooldown(cooldown)
button:SetDurationText(style.timer)
button:SetApplicationCount(style.count)
Enter fullscreen mode Exit fullscreen mode

From that moment the button belongs to the game. The comment says it bluntly: "from this point on the button belongs to the game and may not be touched by us while auras are secret."

One nice side effect: without a formatter, the game only writes a stack number at two or more applications. That is exactly the "show only real stacks" behaviour I wanted, for free.

Layout when you can't know the size

Here is a puzzle I didn't expect. The container sizes itself from the auras it holds, and that size is secret too. You can't centre something whose width you can't read.

The workaround is to anchor by a corner and fake the centre for the common case:

-- Growing right from half an icon left of the plate centre keeps a
-- single icon centred, which is the common case.
holder:SetPoint("BOTTOMLEFT", plate, "TOP", cfg.xOffset - halfIcon, cfg.yOffset)
Enter fullscreen mode Exit fullscreen mode

And the holder is the addon's own frame, parented to UIParent, only anchored to the plate. Moving the display around never means writing to anything Blizzard owns.

Restyling: try, and if refused, try again after combat

Players change icon sizes and fonts in the options. But the buttons belong to the game now, and changing them is only allowed while auras are not secret. Instead of checking every condition up front, the addon just tries:

function ns.TryRestyle(fn, ...)
    if pcall(fn, ...) then return true end
    pendingRestyle = true
    return false
end
Enter fullscreen mode Exit fullscreen mode

If the call is refused, a flag is set and the restyle runs again when combat ends. From a testing point of view I like this a lot: the code doesn't model the game's rules, it asks the game, and has one well-defined retry path.

Pooling, because nameplates come and go

Nameplates appear and disappear constantly in a fight. Building a container allocates a batch of buttons up front, and doing that for the first time in the middle of a pull is a visible hitch. So five displays are built at login and recycled:

local PREWARM = 5
Enter fullscreen mode Exit fullscreen mode

There is also a defensive bit: a unit token can come back without a matching "removed" event (zoning, a plate recycled onto a different mob). The add handler re-attaches what is already there instead of leaking a display:

local display = byUnit[unit]
if not display then
    display = AcquireDisplay()
    byUnit[unit] = display
end
Attach(display, unit, plate)
Enter fullscreen mode Exit fullscreen mode

Testing an addon without the game

This is the part my QA brain cares about most. You can't run WoW in CI. But you can run Lua.

tests/load_test.py loads the whole addon under a real Lua interpreter (via lupa) against a stub WoW API and drives the login sequence: ADDON_LOADED, PLAYER_LOGIN, PLAYER_ENTERING_WORLD, a nameplate appearing, a spec change.

The stub is deliberately permissive: any unknown method is a no-op that returns the frame. That means the test can't check what anything looks like. It checks something narrower and more valuable: that no code path calls something that doesn't exist, indexes a nil or throws at load. That is precisely the class of bug that kills an addon for everyone.

Why it matters: nameplates, bars, options and the minimap button all start from one event handler. One Lua error in any of them aborts the rest. Because the minimap button is built last, a bug anywhere used to show up as "the minimap icon is gone", with nothing pointing at the real culprit. The fix was twofold: the test, and a SafeInit wrapper so each part starts on its own and the error is kept in the saved variables, because the interesting error happens at login and has scrolled away by the time anyone looks.

What I'd take from this outside of WoW

  • If you don't own a component, don't write to it, even when it works today. Anchor to it and keep your state in your own objects.
  • When the platform hides values from you, register where things go and let the platform fill them in.
  • "Try, and on refusal retry at a safe point" is often simpler and more robust than re-implementing the platform's rules.
  • A permissive stub can't test visuals, but it can make a whole class of startup failures much harder to ship.

HotsNDots is free and open source: CurseForge ยท GitHub.

HotsNDots by Felix Helleckes. More of my apps and all ten addons: felix-helleckes.github.io/apps.

Top comments (0)