From Arms of God Wiki
Documentation for this module may be created at Module:TagIndex/doc
-- Module:TagIndex — render-time tag reverse-index (Arms of God).
-- Scans every tag-bearing category's source Data page (via Core's
-- memoized cross-category membership map) for records carrying a tag key.
-- Powers the Tag-<key> reverse-index pages. No baked membership lists.
--
-- {{#invoke:TagIndex|members|<tagkey>}}
local Core = require('Module:Core')
local p = {}
-- Section order + labels (presentation config).
local SECTIONS = {
{'Weapons', 'Weapons with this tag'},
{'Characters', 'Characters with this tag'},
{'Blessings', 'Blessings with this tag'},
{'Upgrades', 'Upgrades with this tag'},
{'Passives', 'Passives with this tag'},
{'Enemies', 'Enemies with this tag'},
}
-- Computed '== <Cat> with this tag ==' bullet sections for one tag key.
function p.sectionsFor(key)
if not key or key == '' then return '' end
local m = Core.tagMembership()[key]
if not m then return '' end
local CrossRef = require('Module:CrossRef')
local out = {}
for _, sec in ipairs(SECTIONS) do
local cat, label = sec[1], sec[2]
local recs = m[cat]
if recs and #recs > 0 then
local sorted = {}
for i, r in ipairs(recs) do sorted[i] = r end
table.sort(sorted, function(a, b)
return mw.ustring.lower(a.name or '') < mw.ustring.lower(b.name or '')
end)
out[#out + 1] = CrossRef.renderSection(label, sorted)
end
end
return table.concat(out, '\n')
end
function p.members(frame)
local key = (frame.args[1] or ''):gsub('^%s+', ''):gsub('%s+$', '')
-- Accept either the bare tag key ('Melee') or the page slug ('Tag-Melee').
if not Core.tagMembership()[key] and key:sub(1, 4) == 'Tag-' then
local rec = Core.byId('Tags')[key]
if rec then key = rec.id or rec.name end
end
local body = p.sectionsFor(key)
if body == '' then
return "''Nothing in the current game data carries this tag.''"
end
return mw.getCurrentFrame():preprocess(body)
end
return p