From Arms of God Wiki

Revision as of 03:52, 10 June 2026 by Ta1ha (talk | contribs) (bot: operator iteration 2026-06-10)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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>}}        -> linked icon only
-- {{#invoke:Iconbox|render|<name-or-slug>|link}}   -> icon + linked name
-- 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
  local withname = (frame.args[2] or frame.args.text or '') ~= ''
  local size = frame.args.size or '24'
  local rec = lookup(key)
  if not rec then
    -- unknown key: plain link in text 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 ''
  if icon == '' then
    if withname then return '[[' .. slug .. '|' .. name .. ']]' end
    return ''
  end
  local img = '[[File:' .. icon .. '|' .. size .. 'px|link=' .. slug
    .. '|alt=' .. name .. ']]'
  if withname then return img .. ' [[' .. slug .. '|' .. name .. ']]' end
  return img
end

return p