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: render-time derivation refactor (phase 1)
Line 1: Line 1:
-- Module:Iconbox — entity icon lookup (Arms of God).
-- Module:Iconbox — entity icon + linked name (Arms of God).
-- Reads Data:Icons.json (lowercased display names + slugs -> icon/slug/name).
-- RENDER-TIME DERIVATION: icons live on each entity's own source record
-- {{#invoke:Iconbox|render|<name-or-slug>}}            -> icon + linked name (default)
-- (rec.icon in Data:<Category>.json); there is no Data:Icons.json.
-- {{#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.
-- Brotato-style category-first signature (documented standard):
-- Unknown entity or missing icon degrades to text-only (never a redlink file).
--   {{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 p = {}


local function lookup(key)
local function trim(s)
   if not key or key == '' then return nil end
   return (tostring(s or ''):gsub('^%s+', ''):gsub('%s+$', ''))
   local ok, data = pcall(mw.loadJsonData, 'Data:Icons.json')
end
  if not ok or type(data) ~= 'table' or type(data.by_key) ~= 'table' then
 
     return nil
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 data.by_key[mw.ustring.lower(key)]
   return nil
end
end


function p.render(frame)
function p.render(frame)
   local key = (frame.args[1] or ''):gsub('^%s+', ''):gsub('%s+$', '')
   local a1 = trim(frame.args[1])
   if key == '' then return '' end
   if a1 == '' then return '' end
   -- positional arg 2 arrives as '' (not nil) via the template's {{{2|}}},
   local a2 = trim(frame.args[2])
   -- and '' is truthy in Lua — fall through to mode= only when 2 is blank.
  local a3 = trim(frame.args[3])
  local mode = frame.args[2] or ''
 
   if mode:match('^%s*$') then mode = frame.args.mode or '' end
  local cat = Core.resolveCategory(a1)
   mode = mw.ustring.lower((mode:gsub('^%s+', ''):gsub('%s+$', '')))
  local key, mode, rec
  -- default = icon + linked name; only an explicit icon-only flag drops the name
  if cat and a2 ~= '' then
   local iconlonly = (mode == 'icononly' or mode == 'icon' or mode == 'noname')
    -- category-first form: {{Iconbox|Weapon|Cutter|icononly?}}
  local withname = not iconlonly
    key, mode = a2, a3
   local size = frame.args.size or '24'
    rec = findInCategory(cat, key)
  local rec = lookup(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
     -- unknown key: plain link in named mode, nothing in icon-only mode
     if icononly then return '' end
     if withname then return '[[' .. key .. ']]' end
     return '[[' .. key .. ']]'
    return ''
   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 ''
  -- .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 .. '">'
   local tip = '<span class="wm-tip" data-tip-title="' .. slug .. '">'
   if icon == '' then
   if icon == '' then
     if withname then return tip .. '[[' .. slug .. '|' .. name .. ']]</span>' end
     if icononly then return '' end
    return ''
    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 withname then
   if icononly then return img end
    return tip .. img .. ' [[' .. slug .. '|' .. name .. ']]</span>'
  return tip .. img .. ' [[' .. slug .. '|' .. name .. ']]</span>'
  end
  return img
end
end


return p
return p

Revision as of 08:29, 10 June 2026

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