From Arms of God Wiki
Documentation for this module may be created at Module:Iconbox/doc
-- Module:Iconbox — entity icon + linked name (Arms of God).
-- RENDER-TIME DERIVATION: icons live on each entity's own source record
-- (rec.icon in Data:<Category>.json); there is no Data:Icons.json.
--
-- Brotato-style category-first signature (documented standard):
-- {{Iconbox|Weapon|Cutter}} -> icon + linked name
-- {{Iconbox|Weapon|Cutter|icononly}} -> linked icon glyph only
-- Category accepts singular or plural (Weapon/Weapons, Tag/Tags, ...) and
-- makes the lookup single-category + collision-safe (e.g. Upgrade vs
-- Achievement of the same name).
--
-- Bare-name fallback (cross-category Core.find scan; first category in
-- registry order wins):
-- {{Iconbox|Cutter}} / {{Iconbox|Cutter|icononly}}
--
-- Unknown entity or missing icon degrades to a plain link (never a
-- redlink file); icon-only mode degrades to nothing.
local Core = require('Module:Core')
local p = {}
local function trim(s)
return (tostring(s or ''):gsub('^%s+', ''):gsub('%s+$', ''))
end
local function findInCategory(cat, key)
local k = mw.ustring.lower(key)
local rec = Core.byId(cat)[key]
if rec then return rec end
for _, r in ipairs(Core.load(cat)) do
if (r.name and mw.ustring.lower(r.name) == k)
or (r.slug and mw.ustring.lower(r.slug) == k) then
return r
end
end
return nil
end
function p.render(frame)
local a1 = trim(frame.args[1])
if a1 == '' then return '' end
local a2 = trim(frame.args[2])
local a3 = trim(frame.args[3])
local cat = Core.resolveCategory(a1)
local key, mode, rec
if cat and a2 ~= '' then
-- category-first form: {{Iconbox|Weapon|Cutter|icononly?}}
key, mode = a2, a3
rec = findInCategory(cat, key)
else
-- bare-name form: {{Iconbox|Cutter|icononly?}}
key, mode = a1, a2
local _, found = Core.find(key)
rec = found
end
if mode == '' then mode = trim(frame.args.mode) end
mode = mw.ustring.lower(mode)
local icononly = (mode == 'icononly' or mode == 'icon' or mode == 'noname')
local size = trim(frame.args.size)
if size == '' then size = '24' end
if not rec then
if icononly then return '' end
return '[[' .. key .. ']]'
end
local slug = rec.slug or key
local name = rec.name or key
local icon = rec.icon or ''
local tip = '<span class="wm-tip" data-tip-title="' .. slug .. '">'
if icon == '' then
if icononly then return '' end
return tip .. '[[' .. slug .. '|' .. name .. ']]</span>'
end
local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug
.. '|alt=' .. name .. ']]'
if icononly then return img end
return tip .. img .. ' [[' .. slug .. '|' .. name .. ']]</span>'
end
return p