From Arms of God Wiki
bot: operator iteration 2026-06-10 |
bot: operator iteration 2026-06-10d (hover tooltips / filter chips + DPS sort / damage-type hubs / stat reverse-lookup pages) |
||
| Line 1: | Line 1: | ||
-- Module:Compare — comparison-table renderer (Arms of God). | -- Module:Compare — comparison-table renderer (Arms of God). | ||
-- Reads Data:Compare_<dataset>.json ( | -- Reads Data:Compare_<dataset>.json. Each row is {a = row-attribute string | ||
-- Cell `t` is pre-rendered wikitext (icon+link, colored chips) — rendered | -- (data-element / data-class / data-tier / data-type for the Common.js | ||
-- filter chips), c = list of cells {t=display, s=sortval}}; legacy plain | |||
-- cell-array rows still render (a treated as ''). 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 p = {} | ||
| Line 34: | Line 37: | ||
end | end | ||
for _, row in ipairs(data.rows) do | for _, row in ipairs(data.rows) do | ||
out[#out+1] = '|-' | local cells = row.c or row | ||
for _, c in ipairs( | out[#out+1] = '|-' .. tostring(row.a or '') | ||
for _, c in ipairs(cells) do | |||
out[#out+1] = cell(c) | out[#out+1] = cell(c) | ||
end | end | ||
Revision as of 06:08, 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. Each row is {a = row-attribute string
-- (data-element / data-class / data-tier / data-type for the Common.js
-- filter chips), c = list of cells {t=display, s=sortval}}; legacy plain
-- cell-array rows still render (a treated as ''). 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
local cells = row.c or row
out[#out+1] = '|-' .. tostring(row.a or '')
for _, c in ipairs(cells) do
out[#out+1] = cell(c)
end
end
out[#out+1] = '|}'
return table.concat(out, '\n')
end
return p