Module:GameSkills: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 10: | Line 10: | ||
-- | -- | ||
-- Requires the JS you installed in MediaWiki:Common.js. | -- Requires the JS you installed in MediaWiki:Common.js. | ||
-- Uses the Common.css classes you added: | |||
-- .sv-topband-cell, .sv-topband-table, .sv-type-table, .sv-level-ui, .sv-level-title, .sv-level-label, .sv-level-slider | |||
local GameData = require("Module:GameData") | local GameData = require("Module:GameData") | ||
| Line 816: | Line 818: | ||
local wrap = mw.html.create("div") | local wrap = mw.html.create("div") | ||
wrap:addClass("sv-level-ui") | wrap:addClass("sv-level-ui") | ||
-- | -- Title (matches Common.css) | ||
wrap:tag("div") | |||
:addClass("sv-level-title") | |||
:wikitext("Level Select") | |||
-- Label line | |||
wrap:tag("div") | |||
:addClass("sv-level-label") | |||
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel)) | :wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel)) | ||
-- | -- Slider placeholder (JS will insert the input) | ||
wrap | wrap:tag("div"):addClass("sv-level-slider") | ||
return tostring(wrap) | return tostring(wrap) | ||
end | end | ||
local function | local function buildTypeTableUI(typeBlock) | ||
if type(typeBlock) ~= "table" or next(typeBlock) == nil then | if type(typeBlock) ~= "table" or next(typeBlock) == nil then | ||
return nil | return nil | ||
end | end | ||
local | local t = mw.html.create("table") | ||
t:addClass("sv-type-table") | |||
local | local added = false | ||
local | local function valName(x) | ||
if x == nil then return nil end | |||
if type(x) == "table" then | |||
if x.Name and x.Name ~= "" then return tostring(x.Name) end | |||
if x.ID and x.ID ~= "" then return tostring(x.ID) end | |||
end | |||
if type(x) == "string" and x ~= "" then return x end | |||
return nil | |||
end | end | ||
local | local function addRowKV(k, v) | ||
if not v or v == "" then return end | |||
added = true | |||
local r = t:tag("tr") | |||
r:tag("th"):wikitext(mw.text.nowiki(k)):done() | |||
r:tag("td"):wikitext(mw.text.nowiki(v)):done() | |||
end | end | ||
addRowKV("Type", valName(typeBlock["Damage Type"])) -- renamed from "Damage Type" | |||
addRowKV("Element", valName(typeBlock["Element Type"])) | |||
addRowKV("Target", valName(typeBlock["Target Type"])) | |||
addRowKV("Cast Type", valName(typeBlock["Cast Type"])) | |||
if not added then | |||
if not | |||
return nil | return nil | ||
end | end | ||
return tostring( | return tostring(t) | ||
end | end | ||
local function addTopBand(tbl, levelUI, typeUI) | local function addTopBand(tbl, levelUI, typeUI) | ||
if not levelUI and not typeUI then | if not levelUI and not typeUI then | ||
return | return | ||
| Line 886: | Line 884: | ||
cell:addClass("sv-topband-cell") | cell:addClass("sv-topband-cell") | ||
local | -- Nested table (this is what your new CSS targets) | ||
local inner = cell:tag("table") | |||
inner:addClass("sv-topband-table") | |||
local | local tr = inner:tag("tr") | ||
if levelUI and typeUI then | |||
tr:tag("td"):wikitext(levelUI):done() | |||
tr:tag("td"):wikitext(typeUI):done() | |||
elseif levelUI then | |||
tr:tag("td"):attr("colspan", 2):wikitext(levelUI):done() | |||
else | |||
tr:tag("td"):attr("colspan", 2):wikitext(typeUI):done() | |||
end | |||
end | end | ||
| Line 951: | Line 953: | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
-- | -- Unified top band (Level Select left, Type list right) | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
local levelUI = buildLevelSelectUI(level, maxLevel) | local levelUI = buildLevelSelectUI(level, maxLevel) | ||
local typeUI = buildTypeTableUI(rec.Type or {}) | |||
addTopBand(root, levelUI, typeUI) | addTopBand(root, levelUI, typeUI) | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
-- Users (kept as rows | -- Users (kept as rows; hidden on lists or skill page) | ||
------------------------------------------------------------------ | ------------------------------------------------------------------ | ||
if showUsers then | if showUsers then | ||
| Line 1,013: | Line 1,015: | ||
addRow(root, "Resource Cost", formatResourceCost(mech["Resource Cost"], maxLevel, level)) | addRow(root, "Resource Cost", formatResourceCost(mech["Resource Cost"], maxLevel, level)) | ||
addRow(root, "Combo", formatCombo(mech.Combo)) | addRow(root, "Combo", formatCombo(mech.Combo)) | ||
addRow(root, "Special Mechanics", formatMechanicEffects(mech.Effects, maxLevel, level)) | addRow(root, "Special Mechanics", formatMechanicEffects(mech.Effects, maxLevel, level)) | ||
end | end | ||