From Arms of God Wiki

Revision as of 03:52, 10 June 2026 by Ta1ha (talk | contribs) (bot: operator iteration 2026-06-10)

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

-- Module:Compare — comparison-table renderer (Arms of God).
-- Reads Data:Compare_<dataset>.json (headers + rows of {t=display, s=sortval}).
-- Cell `t` is pre-rendered wikitext (icon+link, colored chips) — rendered
-- verbatim. `s` becomes data-sort-value. Dark-theme inline styles carry
-- var(--token, fallback) so the operator's Common.css tokens win once pasted.
local p = {}

local TBL_STYLE = 'font-size:0.92em;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);'

local function cell(c)
  local t = tostring(c.t or '—')
  if c.s ~= nil then
    return '| data-sort-value="' .. tostring(c.s) .. '" | ' .. t
  end
  return '| ' .. t
end

function p.render(frame)
  local ds = frame.args[1] or frame.args.cat
  if not ds or ds == '' then
    return '<strong class="error">Module:Compare: missing dataset arg</strong>'
  end
  ds = ds:gsub('^%s+', ''):gsub('%s+$', '')
  local ok, data = pcall(mw.loadJsonData, 'Data:Compare_' .. ds .. '.json')
  if not ok or type(data) ~= 'table' or not data.rows then
    return '<strong class="error">Module:Compare: cannot load Data:Compare_'
      .. ds .. '.json</strong>'
  end
  local out = { '{| class="wikitable sortable" style="' .. TBL_STYLE .. '"' }
  out[#out+1] = '|-'
  for _, h in ipairs(data.headers or {}) do
    out[#out+1] = '! style="' .. TH_STYLE .. '" | ' .. tostring(h)
  end
  for _, row in ipairs(data.rows) do
    out[#out+1] = '|-'
    for _, c in ipairs(row) do
      out[#out+1] = cell(c)
    end
  end
  out[#out+1] = '|}'
  return table.concat(out, '\n')
end

return p