Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created June 16, 2025 21:55
Show Gist options
  • Save Langmans/64d891546ffaff25c6ed5408ae3bd78b to your computer and use it in GitHub Desktop.
Save Langmans/64d891546ffaff25c6ed5408ae3bd78b to your computer and use it in GitHub Desktop.
do
local lower = string.lower
local format = string.format
local gsub = string.gsub
local CreateAtlasMarkup = CreateAtlasMarkup
local raceIcons = setmetatable({}, {
__mode = "kv",
__index = function(self, key)
self[key] = CreateAtlasMarkup(key)
--Debug(format('atlasMarkup[%q] = %s', key, dump(self[key])))
return self[key]
end
})
local raceReplacements = {
Scourge = "Undead",
HighmountainTauren = "Highmountain",
LightforgedDraenei = "Lightforged",
ZandalariTroll = "Zandalari",
}
Chattynator.API.AddModifier(function(data)
if data.typeInfo.player and data.typeInfo.player.race and data.typeInfo.player.sex then
local player = data.typeInfo.player
local race, sex = player.race, player.sex
local atlas = format("raceicon-%s-%s",
lower(raceReplacements[race] or race),
sex == 3 and "female" or "male"
)
local icon = raceIcons[atlas]
--data.text = gsub(data.text, "|Hplayer:", markup .. "|Hplayer:")
--[[
(|Hplayer:[^|]+|h) matches the player link up to |h.
(%[?) matches an optional [.
The replacement %1%2 preserves both parts, then adds the icon markup after, regardless of whether [ is present.
--]]
data.text = gsub(data.text, "(|Hplayer:[^|]+|h)(%[?)", "%1%2" .. icon)
--Debug("race = %q, atlas = %q, icon = %q", name, race, atlas, icon)
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment