Module:GameSkills: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 1,179: | Line 1,179: | ||
local maxLevel = ctx.maxLevel or 1 | local maxLevel = ctx.maxLevel or 1 | ||
local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {} | local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {} | ||
local effects = (type(mech.Effects) == "table") and mech.Effects or nil | local effects = (type(mech.Effects) == "table") and mech.Effects or nil | ||
local combo = (type(mech.Combo) == "table") and mech.Combo or nil | local combo = (type(mech.Combo) == "table") and mech.Combo or nil | ||
local mods = (type(rec.Modifiers) == "table") and rec.Modifiers or nil | local mods = (type(rec.Modifiers) == "table") and rec.Modifiers or nil | ||
-- | ------------------------------------------------------------------ | ||
-- Flags (flat, de-duped) | |||
------------------------------------------------------------------ | |||
local flagSet = {} | local flagSet = {} | ||
| Line 1,211: | Line 1,213: | ||
table.sort(flags) | table.sort(flags) | ||
-- | ------------------------------------------------------------------ | ||
local | -- Special mechanics (label/value items) | ||
------------------------------------------------------------------ | |||
local mechItems = {} | |||
if effects then | if effects then | ||
| Line 1,225: | Line 1,229: | ||
local t = trim(block.Type) | local t = trim(block.Type) | ||
local | local value = nil | ||
if disp then | if disp then | ||
value = disp | |||
end | end | ||
-- If Type exists and is distinct, prefix it (keeps your previous behavior) | |||
if | if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then | ||
value | if value then | ||
value = mw.text.nowiki(t) .. ": " .. value | |||
else | |||
value = mw.text.nowiki(t) | |||
end | |||
end | end | ||
if value then | if value then | ||
table.insert( | table.insert(mechItems, { label = tostring(name), value = value }) | ||
end | end | ||
end | end | ||
| Line 1,247: | Line 1,250: | ||
end | end | ||
-- Combo ( | ------------------------------------------------------------------ | ||
-- Combo (separate group) | |||
------------------------------------------------------------------ | |||
local comboText = nil | |||
if combo then | if combo then | ||
local typ = trim(combo.Type) | local typ = trim(combo.Type) | ||
| Line 1,263: | Line 1,269: | ||
end | end | ||
if #details > 0 then | if #details > 0 then | ||
comboText = mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")" | comboText = mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")" | ||
| Line 1,269: | Line 1,274: | ||
comboText = mw.text.nowiki(typ) | comboText = mw.text.nowiki(typ) | ||
end | end | ||
end | end | ||
end | end | ||
local | ------------------------------------------------------------------ | ||
-- Presence + empty fallback | |||
------------------------------------------------------------------ | |||
local hasFlags = (#flags > 0) | |||
local hasMech = (#mechItems > 0) | |||
local hasCombo = (comboText ~= nil and comboText ~= "") | |||
local root = mw.html.create("div") | if (not hasFlags) and (not hasMech) and (not hasCombo) then | ||
local root = mw.html.create("div") | |||
root:addClass("sv-sm-root") | |||
root:addClass("sv-compact-root") | |||
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics") | |||
return { | return { | ||
inner = tostring(root), | inner = tostring(root), | ||
| Line 1,289: | Line 1,295: | ||
} | } | ||
end | end | ||
local count = 0 | |||
if hasFlags then count = count + 1 end | |||
if hasMech then count = count + 1 end | |||
if hasCombo then count = count + 1 end | |||
------------------------------------------------------------------ | |||
-- Markup: 3 columns on desktop when all present; mobile CSS collapses | |||
------------------------------------------------------------------ | |||
local root = mw.html.create("div") | |||
root:addClass("sv-sm-root") | |||
root:addClass("sv-compact-root") | |||
local layout = root:tag("div"):addClass("sv-sm-layout") | local layout = root:tag("div"):addClass("sv-sm-layout") | ||
if | layout:addClass("sv-sm-count-" .. tostring(count)) | ||
if hasFlags then layout:addClass("sv-sm-has-flags") end | |||
local fcol = layout:tag("div"):addClass("sv-sm-flags") | if hasMech then layout:addClass("sv-sm-has-mech") end | ||
if hasCombo then layout:addClass("sv-sm-has-combo") end | |||
-- Column 1: Flags | |||
if hasFlags then | |||
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags") | |||
for _, f in ipairs(flags) do | for _, f in ipairs(flags) do | ||
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f)) | fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f)) | ||
| Line 1,299: | Line 1,322: | ||
end | end | ||
local | -- Column 2: Special Mechanics (stacked) | ||
if hasMech then | |||
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech") | |||
for _, it in ipairs(mechItems) do | |||
local one = mcol:tag("div"):addClass("sv-sm-mech") | |||
one:tag("div"):addClass("sv-sm-label"):wikitext(mw.text.nowiki(it.label)) | |||
one:tag("div"):addClass("sv-sm-value"):wikitext(it.value or "—") | |||
end | |||
end | |||
-- Column 3: Combo | |||
if hasCombo then | |||
local ccol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-combo") | |||
local one = ccol:tag("div"):addClass("sv-sm-mech"):addClass("sv-sm-combo") | |||
one:tag("div"):addClass("sv-sm-label"):wikitext("Combo") | |||
one:tag("div"):addClass("sv-sm-value"):wikitext(comboText or "—") | |||
end | end | ||
| Line 1,311: | Line 1,345: | ||
} | } | ||
end | end | ||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||