From Arms of God Wiki

Revision as of 06:08, 10 June 2026 by Ta1ha (talk | contribs) (bot: operator iteration 2026-06-10d (hover tooltips / filter chips + DPS sort / damage-type hubs / stat reverse-lookup pages))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:StatIndex/doc

-- Module:StatIndex — stat reverse-lookup renderer (Arms of God).
-- Reads Data:StatIndex.json (built by the flatten step):
--   stats[key]           -> every hero / blessing / upgrade / passive / Crux
--                           power modifying the stat (desc by amount)
--   element_weapons[key] -> every weapon dealing that elemental damage type
-- {{#invoke:StatIndex|boosters|<stat>}}  -> 'Boosted by' sortable table
-- {{#invoke:StatIndex|weapons|<stat>}}   -> 'Dealt by' sortable table
-- Source cells are .wm-tip wrapped (Common.js hover-infobox popup).
local p = {}

local TBL = '{| class="wikitable sortable" style="font-size:0.95em;background:var(--table-row-odd, #1b1c20);color:var(--table-text, #e6e6e6);border-color:var(--table-border, #3a3c44);"'
local TH  = '! style="background:var(--table-header-bg, #26272e);color:var(--infobox-header-fg, #f1e9d2);" | '

-- SC-01: canonicalise the frozen mw.loadJsonData table (its `#` is 0).
local function fix(t)
  if type(t) ~= 'table' then return t end
  local out = {}
  for k, v in pairs(t) do out[k] = fix(v) end
  return out
end

local function loadData()
  local ok, data = pcall(mw.loadJsonData, 'Data:StatIndex.json')
  if not ok or type(data) ~= 'table' then return nil end
  return data
end

local function tipcell(e)
  local label
  if e.icon and e.icon ~= '' then
    label = '[[File:' .. e.icon .. '|24px|link=' .. e.slug .. ']] [['
      .. e.slug .. '|' .. e.name .. ']]'
  else
    label = '[[' .. e.slug .. '|' .. e.name .. ']]'
  end
  return '<span class="wm-tip" data-tip-title="' .. e.slug .. '">'
    .. label .. '</span>'
end

local function arg1(frame)
  local k = frame.args[1] or ''
  return (k:gsub('^%s+', ''):gsub('%s+$', ''))
end

function p.boosters(frame)
  local key = arg1(frame)
  local data = loadData()
  local list = data and data.stats and data.stats[key]
  if not list then
    return "''No heroes, blessings, upgrades, passives or Crux powers " ..
      "modify this stat in the current game data.''"
  end
  list = fix(list)
  local out = { TBL, '|-',
    TH .. 'Source', TH .. 'Category', TH .. 'Tier / Type', TH .. 'Amount' }
  for _, e in ipairs(list) do
    out[#out+1] = '|-'
    out[#out+1] = '| ' .. tipcell(e)
    out[#out+1] = '| ' .. (e.cat or '')
    out[#out+1] = '| ' .. ((e.tier ~= nil and e.tier ~= '') and e.tier or '—')
    out[#out+1] = '| data-sort-value="' .. tostring(e.sort or 0) .. '" | '
      .. (e.value or '')
  end
  out[#out+1] = '|}'
  return table.concat(out, '\n')
end

function p.weapons(frame)
  local key = arg1(frame)
  local data = loadData()
  local list = data and data.element_weapons and data.element_weapons[key]
  if not list then
    return "''No weapons deal this damage type in the current game data.''"
  end
  list = fix(list)
  local out = { TBL, '|-',
    TH .. 'Weapon', TH .. 'Class', TH .. 'Tier', TH .. key }
  for _, e in ipairs(list) do
    out[#out+1] = '|-'
    out[#out+1] = '| ' .. tipcell(e)
    out[#out+1] = '| ' .. (e['class'] or '')
    out[#out+1] = '| ' .. (e.tier or '')
    out[#out+1] = '| data-sort-value="' .. tostring(e.sort or 0) .. '" | '
      .. (e.value or '')
  end
  out[#out+1] = '|}'
  return table.concat(out, '\n')
end

return p