From Arms of God Wiki

bot: Phase 12 grade-S (comparison tables + tier theming)
 
bot: operator iteration 2026-06-10
Line 1: Line 1:
-- Module:Compare — Phase 12 comparison-table renderer (Arms of God).
-- Module:Compare — comparison-table renderer (Arms of God).
-- Reads Data:Compare_<Cat>.json (headers + rows of {t=display, s=sortval}).
-- Reads Data:Compare_<dataset>.json (headers + rows of {t=display, s=sortval}).
-- Renders a class="sortable wikitable" with data-sort-value on numeric cells.
-- Cell `t` is pre-rendered wikitext (icon+link, colored chips) — rendered
-- Pure presentation; no game logic. Re-run safe — data lives in the Data: page.
-- 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 p = {}


local function cell(c, isFirst)
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 '—')
   local t = tostring(c.t or '—')
  if isFirst then
    -- first column: link to the entity page (display name == page title)
    if t ~= '—' then t = '[[' .. t .. ']]' end
    return '| ' .. t
  end
   if c.s ~= nil then
   if c.s ~= nil then
     return '| data-sort-value="' .. tostring(c.s) .. '" | ' .. t
     return '| data-sort-value="' .. tostring(c.s) .. '" | ' .. t
Line 19: Line 18:


function p.render(frame)
function p.render(frame)
   local cat = frame.args[1] or frame.args.cat
   local ds = frame.args[1] or frame.args.cat
   if not cat or cat == '' then
   if not ds or ds == '' then
     return '<strong class="error">Module:Compare: missing category arg</strong>'
     return '<strong class="error">Module:Compare: missing dataset arg</strong>'
   end
   end
   local ok, data = pcall(mw.loadJsonData, 'Data:Compare_' .. cat .. '.json')
  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
   if not ok or type(data) ~= 'table' or not data.rows then
     return '<strong class="error">Module:Compare: cannot load Data:Compare_'
     return '<strong class="error">Module:Compare: cannot load Data:Compare_'
       .. cat .. '.json</strong>'
       .. ds .. '.json</strong>'
   end
   end
   local out = { '{| class="wikitable sortable" style="font-size:0.95em;"' }
   local out = { '{| class="wikitable sortable" style="' .. TBL_STYLE .. '"' }
  -- header row
   out[#out+1] = '|-'
   out[#out+1] = '|-'
   for _, h in ipairs(data.headers or {}) do
   for _, h in ipairs(data.headers or {}) do
     out[#out+1] = '! ' .. tostring(h)
     out[#out+1] = '! style="' .. TH_STYLE .. '" | ' .. tostring(h)
   end
   end
   for _, row in ipairs(data.rows) do
   for _, row in ipairs(data.rows) do
     out[#out+1] = '|-'
     out[#out+1] = '|-'
     for i, c in ipairs(row) do
     for _, c in ipairs(row) do
       out[#out+1] = cell(c, i == 1)
       out[#out+1] = cell(c)
     end
     end
   end
   end

Revision as of 03:52, 10 June 2026

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