Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:C: Difference between revisions

From Teriock
Content deleted Content added
// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
 
(57 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


local function makeBar(frame, title, content, link, flags, bottom)
-- Memoize category lookups within a single parse
if content == '' then return '' end
local _catMemo = {}
local barSpace = mw.html.create('span')

barSpace:wikitext(frame:preprocess(' ')):css('display', 'none')
-- Resolve a raw ability name to a proper Title in the Ability namespace
local barTitle = mw.html.create('span')
local function resolveAbilityTitle(raw)
local barTitleClass = "{{lc:" .. title .. "}}"
if not raw or raw == "" then return nil end
barTitleClass = barTitleClass:gsub(' ', '-')

barTitleClass = barTitleClass:gsub('\'', '')
-- If caller already gave a full title and it exists, use it
barTitleClass = barTitleClass:gsub('\"', '')
local t = mw.title.new(raw)
local barText = "{{ucfirst:" .. title .. "}}"
if t and t.exists then return t end
if link then barText = "[[" .. link .. "|" .. barText .. "]]" end

barText = barText .. ":"
-- Otherwise, try in the Ability namespace
barTitle:addClass('ability-bar-title'):wikitext(frame:preprocess(barText))
local abilityNS = mw.site.namespaces["Ability"]
:css('font-weight', 'bold'):css('margin-right', '0.5em')
if abilityNS and abilityNS.id then
local barContent = mw.html.create('span')
local t2 = mw.title.new(raw, abilityNS.id) -- "Ability:raw"
barContent:addClass('ability-bar-content'):wikitext(content)
if t2 and t2.exists then return t2 end
local output = mw.html.create('div')
end
if bottom then output = mw.html.create('span') end

if not flags then flags = {} end
-- Fallback: explicit prefix (covers wikis where namespace lookup differs)
for k, v in pairs(flags) do
if not mw.ustring.find(raw, "^Ability:") then
if type(v) == 'string' then
local t3 = mw.title.new("Ability:" .. raw)
output:addClass('flag-' .. k .. '-' .. v)
if t3 and t3.exists then return t3 end
end
end
end

output:addClass('ability-bar'):addClass('ability-bar-' .. barTitleClass)
return nil
:attr(flags):attr('test', 'out'):node(barSpace):node(barTitle):node(
barSpace):node(barContent):css('display', 'block')
-- if flags then
-- for k, v in ipairs(flags) do
-- output:attr(k, v)
-- end
-- end
return tostring(output)
end
end


-- === NEW: shared abilities parsing helpers ===
-- Robust category check using parent categories (handles categories added via templates)
local function pageInCategory(pagetitle, cat)
local function parseAbilitiesString(abilitiesString)
local abilities = {}
if not pagetitle or pagetitle == "" or not cat or cat == "" then return false end
for ability in mw.text.gsplit(abilitiesString or '', ";;", true) do
ability = mw.text.trim(ability)
if ability ~= "" then
local name = ability
local limited, improved = "", ""
local gifted, adept = false, false


-- flags
local memoKey = pagetitle .. "@@" .. cat
if mw.ustring.find(ability, "%-g%-") then gifted = true end
if _catMemo[memoKey] ~= nil then
if mw.ustring.find(ability, "%-a%-") then adept = true end
return _catMemo[memoKey]
end


-- notes (order-insensitive, tolerate any following marker)
local title = resolveAbilityTitle(pagetitle)
local limitedMatch = mw.ustring.match(ability,
if not title then
"%-l%-(.-)(%-[liag]%-|$)") or
_catMemo[memoKey] = false
mw.ustring.match(ability, "%-l%-(.+)$")
return false
if limitedMatch then limited = mw.text.trim(limitedMatch) end
end


local improvedMatch = mw.ustring.match(ability,
-- Follow redirects
"%-i%-(.-)(%-[liag]%-|$)") or
if title.isRedirect and title.redirectTarget and title.redirectTarget.exists then
mw.ustring.match(ability, "%-i%-(.+)$")
title = title.redirectTarget
if improvedMatch then
end
improved = mw.text.trim(improvedMatch)
end


-- clean name (strip markers + payloads/flags)
local parents = title:getParentCategories()
name = mw.ustring.gsub(name, "%-l%-.+", "")
if not parents then
name = mw.ustring.gsub(name, "%-i%-.+", "")
_catMemo[memoKey] = false
name = mw.ustring.gsub(name, "%-g%-", "")
return false
name = mw.ustring.gsub(name, "%-a%-", "")
end
name = mw.text.trim(name)


table.insert(abilities, {
local want = "Category:" .. cat
name = name,
for parentCat in pairs(parents) do
limited = limited,
if parentCat == want then
improved = improved,
_catMemo[memoKey] = true
gifted = gifted,
return true
adept = adept
end
})
end
end
end


table.sort(abilities, function(a, b) return a.name < b.name end)
_catMemo[memoKey] = false
return false
return abilities
end
end


local function buildAETransclusions(abilities)

local transclusions = {}
-- Build AE template from an ability object
for _, a in ipairs(abilities or {}) do
local function aeTemplate(a)
local parts = {"{{AE|", a.name}
local t = {"{{AE|", a.name}
if a.limited and a.limited ~= "" then table.insert(parts, "|limited=" .. a.limited) end
if a.limited ~= "" then table.insert(t, "|limited=" .. a.limited) end
if a.improved and a.improved ~= "" then table.insert(parts, "|improved=" .. a.improved) end
if a.improved ~= "" then
if a.gifted then table.insert(parts, "|gifted=1") end
table.insert(t, "|improved=" .. a.improved)
end
if a.adept then table.insert(parts, "|adept=1") end
table.insert(parts, "}}")
if a.gifted then table.insert(t, "|gifted=1") end
if a.adept then table.insert(t, "|adept=1") end
return table.concat(parts)
table.insert(t, "}}")
table.insert(transclusions, table.concat(t))
end
-- no visible separators between AE templates
return table.concat(transclusions, "")
end
end
-- === END helpers ===


function p.c(frame)
function p.c(frame)
local args = frame.args
local args = frame.args
local rawAbilities = args['a'] or ''
local rawAbilities = args['a'] or ''

-- Prepopulate defaults
local abilities = {}
local indexByName = {}

local function addAbility(obj, isDefault)
local key = mw.text.trim(obj.name or "")
if key == "" then return end
obj.name = key
if indexByName[key] then
abilities[indexByName[key]] = obj
else
table.insert(abilities, obj)
indexByName[key] = #abilities
end
if isDefault then abilities[indexByName[key]]._isDefault = true end
end

local function removeByName(name)
local i = indexByName[name]
if not i then return end
table.remove(abilities, i)
-- rebuild index
indexByName = {}
for idx, ab in ipairs(abilities) do
indexByName[ab.name] = idx
end
end


-- === TAGS & CATEGORIES via TagBuilder ===
-- Defaults
local TagBuilder = require('Module:TagBuilder')
local defaults = {
local DiceEval = require('Module:DiceEval')
"Normal Intelligence",
"Normal Strength",
"Normal Movement",
"Normal Sneak",
"Normal Perception",
}
for _, n in ipairs(defaults) do
addAbility({
name = n, limited = "", improved = "", gifted = false, adept = false
}, true)
end


local tRaw = args['t'] or ''
-- Parse incoming abilities
local looks = args['l'] or ''
local incomingNames = {} -- keep a list to check categories against (only incoming)
local ranks = args['r'] or ''
for ability in mw.text.gsplit(rawAbilities, ";;", true) do
local name = args['name'] or ''
ability = mw.text.trim(ability)
local hpDice = args['hp'] or '1d10'
if ability ~= "" then
local name = ability
local mpDice = args['mp'] or '1d10'
local baseHp = tostring(DiceEval._eval(hpDice))
local limited, improved = "", ""
local baseMp = tostring(DiceEval._eval(mpDice))
local gifted, adept = false, false
local size = args['size'] or '3'
local br = args['br'] or '0'
local int = args['int'] or '0'
local str = args['str'] or '0'
local mov = args['mov'] or '0'
local snk = args['snk'] or '0'
local per = args['per'] or '0'


local preAbilities = ''
if mw.ustring.find(ability, "%-g%-") then gifted = true end
if (int == '0') then
if mw.ustring.find(ability, "%-a%-") then adept = true end
preAbilities = preAbilities .. "Normal Intelligence;; "
end
if (str == '0') then preAbilities = preAbilities .. "Normal Strength;; " end
if (mov == '0') then preAbilities = preAbilities .. "Normal Movement;; " end
if (snk == '0') then preAbilities = preAbilities .. "Normal Sneak;; " end
if (per == '0') then
preAbilities = preAbilities .. "Normal Perception;; "
end


local abilitiesString = preAbilities .. rawAbilities
local limitedMatch = mw.ustring.match(ability, "%-l%-(.-)(%-[liag]%-|$)")
local opts = {
or mw.ustring.match(ability, "%-l%-(.+)$")
name = name,
if limitedMatch then limited = mw.text.trim(limitedMatch) end
ns = 'Creature',
transparent = args.o or args.transparent
}
local tagOut, catOut =
TagBuilder.build(tRaw, 'TagCreatures', 'traits', opts)


-- === Parse and render main abilities with shared helpers ===
local improvedMatch = mw.ustring.match(ability, "%-i%-(.-)(%-[liag]%-|$)")
local abilities = parseAbilitiesString(abilitiesString)
or mw.ustring.match(ability, "%-i%-(.+)$")
local inner = buildAETransclusions(abilities)
if improvedMatch then improved = mw.text.trim(improvedMatch) end


local categoryString = '[[Category:Creatures]]'
-- clean name (strip markers and payloads/flags)
name = mw.ustring.gsub(name, "%-l%-.+", "")
name = mw.ustring.gsub(name, "%-i%-.+", "")
name = mw.ustring.gsub(name, "%-g%-", "")
name = mw.ustring.gsub(name, "%-a%-", "")
name = mw.text.trim(name)


local statContent = ''
addAbility({
statContent = statContent .. "{{Tag|" .. hpDice ..
name = name,
" Hit Dice|❤️|l=:Category:" .. hpDice ..
limited = limited,
" hit die creatures|c=#e01b24|class=hp-dice-tagged " ..
improved = improved,
hpDice .. "}}" .. "{{Tag|" .. baseHp ..
gifted = gifted,
" HP|❤️|l=:Category:" .. baseHp ..
adept = adept
" HP creatures|c=#e01b24|class=cost-tagged hp" .. baseHp ..
}, false)
"}}"
categoryString = categoryString .. "[[Category:" .. hpDice ..
" hit die creatures" .. "]]"
categoryString = categoryString .. "[[Category:" .. baseHp ..
" HP creatures" .. "]]"
statContent = statContent .. "{{Tag|" .. mpDice ..
" Mana Dice|🩵|l=:Category:" .. mpDice ..
" mana die creatures|c=#3584e4|class=mp-dice-tagged " ..
mpDice .. "}}" .. "{{Tag|" .. baseMp ..
" MP|🩵|l=:Category:" .. baseMp ..
" MP creatures|c=#3584e4|class=cost-tagged hp" .. baseMp ..
"}}"
categoryString = categoryString .. "[[Category:" .. baseMp ..
" MP creatures" .. "]]"
categoryString = categoryString .. "[[Category:" .. mpDice ..
" mana die creatures" .. "]]"
statContent = statContent .. "{{Tag|Size " .. size ..
"|⬆️|l=:Category:Size " .. size ..
" creatures|c=#e4a835|class=size-tagged size" .. size ..
"}}"
categoryString = categoryString .. "[[Category:Size " .. size ..
" creatures" .. "]]"


local attributeContent = ''
table.insert(incomingNames, name)
attributeContent = ""
end
attributeContent = attributeContent .. "{{Tag|" .. int ..
end
"|INT|l=:Category:INT value of " .. int ..
" creatures}}"
categoryString = categoryString .. "[[Category:INT value of " .. int ..
" creatures]]"
attributeContent = attributeContent .. "{{Tag|" .. str ..
"|STR|l=:Category:STR value of " .. str ..
" creatures}}"
categoryString = categoryString .. "[[Category:STR value of " .. str ..
" creatures]]"
attributeContent = attributeContent .. "{{Tag|" .. mov ..
"|MOV|l=:Category:MOV value of " .. mov ..
" creatures}}"
categoryString = categoryString .. "[[Category:MOV value of " .. mov ..
" creatures]]"
attributeContent = attributeContent .. "{{Tag|" .. snk ..
"|SNK|l=:Category:SNK value of " .. snk ..
" creatures}}"
categoryString = categoryString .. "[[Category:SNK value of " .. snk ..
" creatures]]"
attributeContent = attributeContent .. "{{Tag|" .. per ..
"|PER|l=:Category:PER value of " .. per ..
" creatures}}"
categoryString = categoryString .. "[[Category:PER value of " .. per ..
" creatures]]"
traitsContent = (tagOut or '') .. "{{Tag|BR " .. br ..
"|⚠️|l=:Category:BR " .. br ..
" creatures|class=br-tagged br" .. br .. "}}"
categoryString = categoryString .. "[[Category:BR " .. br .. " creatures]]"


local out = ""
-- If any incoming ability is in the mapped category, remove the corresponding default
out = out .. makeBar(frame, "Stats", statContent, nil, nil, false)
local catMap = {
out = out .. makeBar(frame, "Attributes", attributeContent, nil, nil, false)
["Normal Intelligence"] = "INT setting abilities",
out = out .. makeBar(frame, "Traits", traitsContent, nil, nil, false)
["Normal Strength"] = "STR setting abilities",
out = out .. makeBar(frame, "Looks", looks, nil, nil, false)
["Normal Movement"] = "MOV setting abilities",
out = out .. makeBar(frame, "Innate ranks", ranks, nil, nil, false)
["Normal Sneak"] = "SNK setting abilities",
if args['lifespan'] then
["Normal Perception"] = "PER setting abilities",
local lifespanText = args['lifespan'] .. " years."
}
categoryString = categoryString .. "[[Category:" .. args['lifespan'] ..
" year lifespan creatures]]"
if args['adult'] then
lifespanText = lifespanText .. " Adult at age " .. args['adult'] ..
"."
end
out = out .. makeBar(frame, "Lifespan", lifespanText, nil, nil, false)
end


out = out .. '<hr>'
local shouldRemove = {
if args['d'] then
["Normal Intelligence"] = false,
out = out .. '<span class="creature-description>' .. args['d'] ..
["Normal Strength"] = false,
'</span><hr>'
["Normal Movement"] = false,
end
["Normal Sneak"] = false,
["Normal Perception"] = false,
}


-- main abilities block
for _, inName in ipairs(incomingNames) do
out = out .. '<div class="expandable-table"><div>' ..
for normalName, cat in pairs(catMap) do
frame:preprocess(inner) .. '</div></div>'
if not shouldRemove[normalName] and pageInCategory(inName, cat) then
shouldRemove[normalName] = true
end
end
end


-- === familiar abilities (args['f']) using the same parsing ===
for normalName, flag in pairs(shouldRemove) do
if args['f'] and mw.text.trim(args['f']) ~= '' then
if flag then
local fAbilities = parseAbilitiesString(args['f'])
removeByName(normalName)
local fInner = buildAETransclusions(fAbilities)
end
-- You can wrap in a bar or just mirror the main output style; here we label it:
end
out = out .. '<hr>' .. makeBar(frame, "Familiar Abilities",
frame:preprocess(
'<div class="expandable-table"><div>' ..
fInner .. '</div></div>'), nil,
nil, false)
end


out = out .. (catOut or '')
-- Sort alphabetically by name (case-insensitive, but stable on original)
table.sort(abilities, function(a, b)
local aa, bb = mw.ustring.lower(a.name), mw.ustring.lower(b.name)
if aa == bb then return a.name < b.name end
return aa < bb
end)


local page = mw.title.getCurrentTitle().text
-- Assemble output and expand the AE templates right here
local namespace = frame:preprocess('{{NAMESPACE}}')
local outParts = {}
if ((namespace == "Creature") and (page == name)) then
for _, a in ipairs(abilities) do
out = out .. categoryString
table.insert(outParts, aeTemplate(a))
end
end
local inner = table.concat(outParts, "")
local out = '<div class="expandable-table"><div>' .. frame:preprocess(inner) .. '</div></div>'


return out
return frame:preprocess(out)
end
end



Latest revision as of 18:25, 18 August 2025

Documentation for this module may be created at Module:C/doc

local p = {}

local function makeBar(frame, title, content, link, flags, bottom)
    if content == '' then return '' end
    local barSpace = mw.html.create('span')
    barSpace:wikitext(frame:preprocess('&nbsp;')):css('display', 'none')
    local barTitle = mw.html.create('span')
    local barTitleClass = "{{lc:" .. title .. "}}"
    barTitleClass = barTitleClass:gsub(' ', '-')
    barTitleClass = barTitleClass:gsub('\'', '')
    barTitleClass = barTitleClass:gsub('\"', '')
    local barText = "{{ucfirst:" .. title .. "}}"
    if link then barText = "[[" .. link .. "|" .. barText .. "]]" end
    barText = barText .. ":"
    barTitle:addClass('ability-bar-title'):wikitext(frame:preprocess(barText))
        :css('font-weight', 'bold'):css('margin-right', '0.5em')
    local barContent = mw.html.create('span')
    barContent:addClass('ability-bar-content'):wikitext(content)
    local output = mw.html.create('div')
    if bottom then output = mw.html.create('span') end
    if not flags then flags = {} end
    for k, v in pairs(flags) do
        if type(v) == 'string' then
            output:addClass('flag-' .. k .. '-' .. v)
        end
    end
    output:addClass('ability-bar'):addClass('ability-bar-' .. barTitleClass)
        :attr(flags):attr('test', 'out'):node(barSpace):node(barTitle):node(
            barSpace):node(barContent):css('display', 'block')
    -- if flags then
    -- for k, v in ipairs(flags) do
    --     output:attr(k, v)
    -- end
    -- end
    return tostring(output)
end

-- === NEW: shared abilities parsing helpers ===
local function parseAbilitiesString(abilitiesString)
    local abilities = {}
    for ability in mw.text.gsplit(abilitiesString or '', ";;", true) do
        ability = mw.text.trim(ability)
        if ability ~= "" then
            local name = ability
            local limited, improved = "", ""
            local gifted, adept = false, false

            -- flags
            if mw.ustring.find(ability, "%-g%-") then gifted = true end
            if mw.ustring.find(ability, "%-a%-") then adept = true end

            -- notes (order-insensitive, tolerate any following marker)
            local limitedMatch = mw.ustring.match(ability,
                                                  "%-l%-(.-)(%-[liag]%-|$)") or
                                     mw.ustring.match(ability, "%-l%-(.+)$")
            if limitedMatch then limited = mw.text.trim(limitedMatch) end

            local improvedMatch = mw.ustring.match(ability,
                                                   "%-i%-(.-)(%-[liag]%-|$)") or
                                      mw.ustring.match(ability, "%-i%-(.+)$")
            if improvedMatch then
                improved = mw.text.trim(improvedMatch)
            end

            -- clean name (strip markers + payloads/flags)
            name = mw.ustring.gsub(name, "%-l%-.+", "")
            name = mw.ustring.gsub(name, "%-i%-.+", "")
            name = mw.ustring.gsub(name, "%-g%-", "")
            name = mw.ustring.gsub(name, "%-a%-", "")
            name = mw.text.trim(name)

            table.insert(abilities, {
                name = name,
                limited = limited,
                improved = improved,
                gifted = gifted,
                adept = adept
            })
        end
    end

    table.sort(abilities, function(a, b) return a.name < b.name end)
    return abilities
end

local function buildAETransclusions(abilities)
    local transclusions = {}
    for _, a in ipairs(abilities or {}) do
        local t = {"{{AE|", a.name}
        if a.limited ~= "" then table.insert(t, "|limited=" .. a.limited) end
        if a.improved ~= "" then
            table.insert(t, "|improved=" .. a.improved)
        end
        if a.gifted then table.insert(t, "|gifted=1") end
        if a.adept then table.insert(t, "|adept=1") end
        table.insert(t, "}}")
        table.insert(transclusions, table.concat(t))
    end
    -- no visible separators between AE templates
    return table.concat(transclusions, "")
end
-- === END helpers ===

function p.c(frame)
    local args = frame.args
    local rawAbilities = args['a'] or ''

    -- === TAGS & CATEGORIES via TagBuilder ===
    local TagBuilder = require('Module:TagBuilder')
    local DiceEval = require('Module:DiceEval')

    local tRaw = args['t'] or ''
    local looks = args['l'] or ''
    local ranks = args['r'] or ''
    local name = args['name'] or ''
    local hpDice = args['hp'] or '1d10'
    local mpDice = args['mp'] or '1d10'
    local baseHp = tostring(DiceEval._eval(hpDice))
    local baseMp = tostring(DiceEval._eval(mpDice))
    local size = args['size'] or '3'
    local br = args['br'] or '0'
    local int = args['int'] or '0'
    local str = args['str'] or '0'
    local mov = args['mov'] or '0'
    local snk = args['snk'] or '0'
    local per = args['per'] or '0'

    local preAbilities = ''
    if (int == '0') then
        preAbilities = preAbilities .. "Normal Intelligence;; "
    end
    if (str == '0') then preAbilities = preAbilities .. "Normal Strength;; " end
    if (mov == '0') then preAbilities = preAbilities .. "Normal Movement;; " end
    if (snk == '0') then preAbilities = preAbilities .. "Normal Sneak;; " end
    if (per == '0') then
        preAbilities = preAbilities .. "Normal Perception;; "
    end

    local abilitiesString = preAbilities .. rawAbilities
    local opts = {
        name = name,
        ns = 'Creature',
        transparent = args.o or args.transparent
    }
    local tagOut, catOut =
        TagBuilder.build(tRaw, 'TagCreatures', 'traits', opts)

    -- === Parse and render main abilities with shared helpers ===
    local abilities = parseAbilitiesString(abilitiesString)
    local inner = buildAETransclusions(abilities)

    local categoryString = '[[Category:Creatures]]'

    local statContent = ''
    statContent = statContent .. "{{Tag|" .. hpDice ..
                      " Hit Dice|❤️|l=:Category:" .. hpDice ..
                      " hit die creatures|c=#e01b24|class=hp-dice-tagged " ..
                      hpDice .. "}}" .. "{{Tag|" .. baseHp ..
                      " HP|❤️|l=:Category:" .. baseHp ..
                      " HP creatures|c=#e01b24|class=cost-tagged hp" .. baseHp ..
                      "}}"
    categoryString = categoryString .. "[[Category:" .. hpDice ..
                         " hit die creatures" .. "]]"
    categoryString = categoryString .. "[[Category:" .. baseHp ..
                         " HP creatures" .. "]]"
    statContent = statContent .. "{{Tag|" .. mpDice ..
                      " Mana Dice|🩵|l=:Category:" .. mpDice ..
                      " mana die creatures|c=#3584e4|class=mp-dice-tagged " ..
                      mpDice .. "}}" .. "{{Tag|" .. baseMp ..
                      " MP|🩵|l=:Category:" .. baseMp ..
                      " MP creatures|c=#3584e4|class=cost-tagged hp" .. baseMp ..
                      "}}"
    categoryString = categoryString .. "[[Category:" .. baseMp ..
                         " MP creatures" .. "]]"
    categoryString = categoryString .. "[[Category:" .. mpDice ..
                         " mana die creatures" .. "]]"
    statContent = statContent .. "{{Tag|Size " .. size ..
                      "|⬆️|l=:Category:Size " .. size ..
                      " creatures|c=#e4a835|class=size-tagged size" .. size ..
                      "}}"
    categoryString = categoryString .. "[[Category:Size " .. size ..
                         " creatures" .. "]]"

    local attributeContent = ''
    attributeContent = ""
    attributeContent = attributeContent .. "{{Tag|" .. int ..
                           "|INT|l=:Category:INT value of " .. int ..
                           " creatures}}"
    categoryString = categoryString .. "[[Category:INT value of " .. int ..
                         " creatures]]"
    attributeContent = attributeContent .. "{{Tag|" .. str ..
                           "|STR|l=:Category:STR value of " .. str ..
                           " creatures}}"
    categoryString = categoryString .. "[[Category:STR value of " .. str ..
                         " creatures]]"
    attributeContent = attributeContent .. "{{Tag|" .. mov ..
                           "|MOV|l=:Category:MOV value of " .. mov ..
                           " creatures}}"
    categoryString = categoryString .. "[[Category:MOV value of " .. mov ..
                         " creatures]]"
    attributeContent = attributeContent .. "{{Tag|" .. snk ..
                           "|SNK|l=:Category:SNK value of " .. snk ..
                           " creatures}}"
    categoryString = categoryString .. "[[Category:SNK value of " .. snk ..
                         " creatures]]"
    attributeContent = attributeContent .. "{{Tag|" .. per ..
                           "|PER|l=:Category:PER value of " .. per ..
                           " creatures}}"
    categoryString = categoryString .. "[[Category:PER value of " .. per ..
                         " creatures]]"
    traitsContent = (tagOut or '') .. "{{Tag|BR " .. br ..
                        "|⚠️|l=:Category:BR " .. br ..
                        " creatures|class=br-tagged br" .. br .. "}}"
    categoryString = categoryString .. "[[Category:BR " .. br .. " creatures]]"

    local out = ""
    out = out .. makeBar(frame, "Stats", statContent, nil, nil, false)
    out = out .. makeBar(frame, "Attributes", attributeContent, nil, nil, false)
    out = out .. makeBar(frame, "Traits", traitsContent, nil, nil, false)
    out = out .. makeBar(frame, "Looks", looks, nil, nil, false)
    out = out .. makeBar(frame, "Innate ranks", ranks, nil, nil, false)
    if args['lifespan'] then
        local lifespanText = args['lifespan'] .. " years."
        categoryString = categoryString .. "[[Category:" .. args['lifespan'] ..
                             " year lifespan creatures]]"
        if args['adult'] then
            lifespanText = lifespanText .. " Adult at age " .. args['adult'] ..
                               "."
        end
        out = out .. makeBar(frame, "Lifespan", lifespanText, nil, nil, false)
    end

    out = out .. '<hr>'
    if args['d'] then
        out = out .. '<span class="creature-description>' .. args['d'] ..
                  '</span><hr>'
    end

    -- main abilities block
    out = out .. '<div class="expandable-table"><div>' ..
              frame:preprocess(inner) .. '</div></div>'

    -- === familiar abilities (args['f']) using the same parsing ===
    if args['f'] and mw.text.trim(args['f']) ~= '' then
        local fAbilities = parseAbilitiesString(args['f'])
        local fInner = buildAETransclusions(fAbilities)
        -- You can wrap in a bar or just mirror the main output style; here we label it:
        out = out .. '<hr>' .. makeBar(frame, "Familiar Abilities",
                                       frame:preprocess(
                                           '<div class="expandable-table"><div>' ..
                                               fInner .. '</div></div>'), nil,
                                       nil, false)
    end

    out = out .. (catOut or '')

    local page = mw.title.getCurrentTitle().text
    local namespace = frame:preprocess('{{NAMESPACE}}')
    if ((namespace == "Creature") and (page == name)) then
        out = out .. categoryString
    end

    return frame:preprocess(out)
end

return p