From Arms of God Wiki
bot: Iconbox mode= named-arg fix (empty positional arg masked it) |
bot: operator iteration 2026-06-10d (hover tooltips / filter chips + DPS sort / damage-type hubs / stat reverse-lookup pages) |
||
| Line 37: | Line 37: | ||
local name = rec.name or key | local name = rec.name or key | ||
local icon = rec.icon or '' | local icon = rec.icon or '' | ||
-- .wm-tip: Common.js hover popup showing the target page's infobox | |||
-- (2026-06-10d). Plain link without JS. | |||
local tip = '<span class="wm-tip" data-tip-title="' .. slug .. '">' | |||
if icon == '' then | if icon == '' then | ||
if withname then return '[[' .. slug .. '|' .. name .. ']]' end | if withname then return tip .. '[[' .. slug .. '|' .. name .. ']]</span>' end | ||
return '' | return '' | ||
end | end | ||
local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug | local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug | ||
.. '|alt=' .. name .. ']]' | .. '|alt=' .. name .. ']]' | ||
if withname then return img .. ' [[' .. slug .. '|' .. name .. ']]' end | if withname then | ||
return tip .. img .. ' [[' .. slug .. '|' .. name .. ']]</span>' | |||
end | |||
return img | return img | ||
end | end | ||
return p | return p | ||
Revision as of 06:08, 10 June 2026
Documentation for this module may be created at Module:Iconbox/doc
-- Module:Iconbox — entity icon lookup (Arms of God).
-- Reads Data:Icons.json (lowercased display names + slugs -> icon/slug/name).
-- {{#invoke:Iconbox|render|<name-or-slug>}} -> icon + linked name (default)
-- {{#invoke:Iconbox|render|<name-or-slug>|icononly}} -> linked icon only
-- 'link' as 2nd arg is a no-op alias of the default; mode=icon == icononly.
-- Unknown entity or missing icon degrades to text-only (never a redlink file).
local p = {}
local function lookup(key)
if not key or key == '' then return nil end
local ok, data = pcall(mw.loadJsonData, 'Data:Icons.json')
if not ok or type(data) ~= 'table' or type(data.by_key) ~= 'table' then
return nil
end
return data.by_key[mw.ustring.lower(key)]
end
function p.render(frame)
local key = (frame.args[1] or ''):gsub('^%s+', ''):gsub('%s+$', '')
if key == '' then return '' end
-- positional arg 2 arrives as '' (not nil) via the template's {{{2|}}},
-- and '' is truthy in Lua — fall through to mode= only when 2 is blank.
local mode = frame.args[2] or ''
if mode:match('^%s*$') then mode = frame.args.mode or '' end
mode = mw.ustring.lower((mode:gsub('^%s+', ''):gsub('%s+$', '')))
-- default = icon + linked name; only an explicit icon-only flag drops the name
local iconlonly = (mode == 'icononly' or mode == 'icon' or mode == 'noname')
local withname = not iconlonly
local size = frame.args.size or '24'
local rec = lookup(key)
if not rec then
-- unknown key: plain link in named mode, nothing in icon-only mode
if withname then return '[[' .. key .. ']]' end
return ''
end
local slug = rec.slug or key
local name = rec.name or key
local icon = rec.icon or ''
-- .wm-tip: Common.js hover popup showing the target page's infobox
-- (2026-06-10d). Plain link without JS.
local tip = '<span class="wm-tip" data-tip-title="' .. slug .. '">'
if icon == '' then
if withname then return tip .. '[[' .. slug .. '|' .. name .. ']]</span>' end
return ''
end
local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug
.. '|alt=' .. name .. ']]'
if withname then
return tip .. img .. ' [[' .. slug .. '|' .. name .. ']]</span>'
end
return img
end
return p