From Arms of God Wiki
bot: operator iteration 2026-06-10d (hover tooltips / filter chips + DPS sort / damage-type hubs / stat reverse-lookup pages) |
bot: documentation pass — editor-facing docs (data descriptions, module comments, template usage, Help rewrite) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- Module:Iconbox — entity icon | -- Module:Iconbox — an entity's small icon + linked name, anywhere. | ||
-- | -- | ||
-- {{ | -- WHAT IT DOES | ||
-- {{ | -- Looks up an entity by category + name (or just name) and renders | ||
-- | -- its icon and a link to its page. Icons come from each entity's own | ||
-- Unknown entity or missing icon degrades to | -- record (rec.icon in Data:<Category>.json) — there is no separate | ||
-- icon lookup table to maintain. | |||
-- | |||
-- HOW TO INVOKE (normally via Template:Iconbox) | |||
-- Category-first form (preferred — collision-safe): | |||
-- {{Iconbox|Weapon|Cutter}} icon + linked name | |||
-- {{Iconbox|Weapon|Cutter|icononly}} linked icon glyph only | |||
-- {{Iconbox|Blessing|Sanctified Halo|size=32}} | |||
-- Category accepts singular or plural (Weapon/Weapons, Tag/Tags, ...). | |||
-- Bare-name fallback (scans every category; first match in registry | |||
-- order wins — beware same-named entities in two categories): | |||
-- {{Iconbox|Cutter}} / {{Iconbox|Cutter|icononly}} | |||
-- | |||
-- SOURCE DATA IT READS (via Module:Core) | |||
-- Any/all of the ten Data:<Category>.json pages, depending on the call. | |||
-- | |||
-- EDITING NOTES | |||
-- Unknown entity or missing icon degrades to a plain page link (never | |||
-- a broken-file box); icon-only mode degrades to nothing. | |||
local Core = require('Module:Core') | |||
local p = {} | local p = {} | ||
local function | 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 | end | ||
return | return nil | ||
end | end | ||
function p.render(frame) | function p.render(frame) | ||
local | local a1 = trim(frame.args[1]) | ||
if | if a1 == '' then return '' end | ||
local a2 = trim(frame.args[2]) | |||
-- | local a3 = trim(frame.args[3]) | ||
if mode | local cat = Core.resolveCategory(a1) | ||
mode = mw.ustring.lower | local key, mode, rec | ||
if cat and a2 ~= '' then | |||
local | -- category-first form: {{Iconbox|Weapon|Cutter|icononly?}} | ||
key, mode = a2, a3 | |||
local size = frame.args.size | 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 not rec then | ||
if icononly then return '' end | |||
return '[[' .. key .. ']]' | |||
end | end | ||
local slug = rec.slug or key | local slug = rec.slug or key | ||
local name = rec.name or key | local name = rec.name or key | ||
local icon = rec.icon or '' | local icon = rec.icon or '' | ||
local tip = '<span class="wm-tip" data-tip-title="' .. slug .. '">' | local tip = '<span class="wm-tip" data-tip-title="' .. slug .. '">' | ||
if icon == '' then | if icon == '' then | ||
if | if icononly then return '' end | ||
return tip .. '[[' .. slug .. '|' .. name .. ']]</span>' | |||
end | end | ||
local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug | local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug | ||
.. '|alt=' .. name .. ']]' | .. '|alt=' .. name .. ']]' | ||
if | if icononly then return img end | ||
return tip .. img .. ' [[' .. slug .. '|' .. name .. ']]</span>' | |||
end | end | ||
return p | return p | ||
Latest revision as of 16:04, 10 June 2026
Documentation for this module may be created at Module:Iconbox/doc
-- Module:Iconbox — an entity's small icon + linked name, anywhere.
--
-- WHAT IT DOES
-- Looks up an entity by category + name (or just name) and renders
-- its icon and a link to its page. Icons come from each entity's own
-- record (rec.icon in Data:<Category>.json) — there is no separate
-- icon lookup table to maintain.
--
-- HOW TO INVOKE (normally via Template:Iconbox)
-- Category-first form (preferred — collision-safe):
-- {{Iconbox|Weapon|Cutter}} icon + linked name
-- {{Iconbox|Weapon|Cutter|icononly}} linked icon glyph only
-- {{Iconbox|Blessing|Sanctified Halo|size=32}}
-- Category accepts singular or plural (Weapon/Weapons, Tag/Tags, ...).
-- Bare-name fallback (scans every category; first match in registry
-- order wins — beware same-named entities in two categories):
-- {{Iconbox|Cutter}} / {{Iconbox|Cutter|icononly}}
--
-- SOURCE DATA IT READS (via Module:Core)
-- Any/all of the ten Data:<Category>.json pages, depending on the call.
--
-- EDITING NOTES
-- Unknown entity or missing icon degrades to a plain page link (never
-- a broken-file box); 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