Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Join the Playtest on Steam Now: SpiritVale

Module:GameSkills: Difference between revisions

From SpiritVale Wiki
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:GameSkills
-- Module:GameSkills
--
--
-- Renders SpiritVale skill infoboxes and class/user skill lists.
-- Phase 6.5+ (Plug-in Slot Architecture)
--
--
-- Phase 6.5+ (Plug-in Slot Architecture)
-- Layout:
-- Layout:
--  1) hero-title-bar        (TOP BAR, 2 slots: herobar 1..2)
--  1) hero-title-bar        (TOP BAR, 2 slots: herobar 1..2)
Line 10: Line 9:
--
--
-- Requires Common.js:
-- Requires Common.js:
--  - Updates .sv-dyn spans via data-series
--  - updates .sv-dyn spans via data-series
--  - Updates .sv-level-num + data-level on .sv-skill-card
--  - updates .sv-level-num + data-level on .sv-skill-card
--  - Binds to input.sv-level-range inside each card
--  - binds to input.sv-level-range inside each card


local GameData = require("Module:GameData")
local GameData = require("Module:GameData")
Line 24: Line 23:
local skillsCache
local skillsCache


-- Load skills once per page parse (cached).
-- getSkills: lazy-load + cache skill dataset from GameData.
local function getSkills()
local function getSkills()
if not skillsCache then
if not skillsCache then
Line 36: Line 35:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Read template args from parent if present.
-- getArgs: read args from parent frame when invoked from a template.
local function getArgs(frame)
local function getArgs(frame)
local parent = frame:getParent()
local parent = frame:getParent()
Line 42: Line 41:
end
end


-- Trim string, returning nil if empty/non-string.
-- trim: normalize strings (nil if empty).
local function trim(s)
local function trim(s)
if type(s) ~= "string" then
if type(s) ~= "string" then
Line 51: Line 50:
end
end


-- Coerce number-like values to a Lua number (supports { Value = ... }).
-- toNum: convert common scalar/table forms to a Lua number.
local function toNum(v)
local function toNum(v)
if type(v) == "number" then
if type(v) == "number" then
Line 65: Line 64:
end
end


-- Clamp numeric value into [lo, hi].
-- clamp: clamp a number into [lo, hi].
local function clamp(n, lo, hi)
local function clamp(n, lo, hi)
if type(n) ~= "number" then
if type(n) ~= "number" then
Line 75: Line 74:
end
end


-- Format numbers cleanly (integers without decimals, floats up to 4 dp).
-- fmtNum: consistent number formatting (trim trailing zeros).
local function fmtNum(n)
local function fmtNum(n)
if type(n) ~= "number" then
if type(n) ~= "number" then
Line 91: Line 90:
end
end


-- Join list to text, or nil if empty.
-- listToText: join an array into a readable string.
local function listToText(list, sep)
local function listToText(list, sep)
if type(list) ~= "table" or #list == 0 then
if type(list) ~= "table" or #list == 0 then
Line 99: Line 98:
end
end


-- Treat common “none-like” strings as empty.
-- isNoneLike: treat common "none" spellings as empty.
local function isNoneLike(v)
local function isNoneLike(v)
if v == nil then return true end
if v == nil then return true end
Line 108: Line 107:
end
end


-- Add an infobox row (label/value). Skips nil/empty values.
-- addRow: add a standard <tr><th>Label</th><td>Value</td></tr> row.
local function addRow(tbl, label, value, rowClass, dataKey)
local function addRow(tbl, label, value, rowClass, dataKey)
if value == nil or value == "" then
if value == nil or value == "" then
Line 123: Line 122:
end
end


-- Format either a scalar or { Value, Unit } pair to a display string.
-- formatUnitValue: format {Value, Unit} blocks (or scalar) for display.
local function formatUnitValue(v)
local function formatUnitValue(v)
if type(v) == "table" and v.Value ~= nil then
if type(v) == "table" and v.Value ~= nil then
Line 151: Line 150:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Build a .sv-dyn span that Common.js can update per selected level.
-- dynSpan: render a JS-updated span for a level series.
local function dynSpan(series, level)
local function dynSpan(series, level)
if type(series) ~= "table" or #series == 0 then
if type(series) ~= "table" or #series == 0 then
Line 167: Line 166:
end
end


-- True if list values are all identical (no need for a dyn span).
-- isFlatList: true if all values in list are identical.
local function isFlatList(list)
local function isFlatList(list)
if type(list) ~= "table" or #list == 0 then
if type(list) ~= "table" or #list == 0 then
Line 181: Line 180:
end
end


-- Treat value as present if not “zeroish”.
-- isNonZeroScalar: detect if a value is present and not effectively zero.
local function isNonZeroScalar(v)
local function isNonZeroScalar(v)
if v == nil then return false end
if v == nil then return false end
Line 196: Line 195:
end
end


-- Aggressive “is zero/empty” check used for hiding values.
-- isZeroish: aggressively treat common “zero” text forms as zero.
local function isZeroish(v)
local function isZeroish(v)
if v == nil then return true end
if v == nil then return true end
Line 215: Line 214:
end
end


-- Render a Base/Per Level block as a single readable string (non-dynamic).
-- valuePairRawText: render Base/Per Level blocks into readable text (fallback).
local function valuePairRawText(block)
local function valuePairRawText(block)
if type(block) ~= "table" then
if type(block) ~= "table" then
Line 249: Line 248:
end
end


-- Render only the value portion (dynamic if per-level series exists).
-- valuePairDynamicValueOnly: render Base/Per Level blocks using dyn spans where possible.
local function valuePairDynamicValueOnly(block, maxLevel, level)
local function valuePairDynamicValueOnly(block, maxLevel, level)
if type(block) ~= "table" then
if type(block) ~= "table" then
Line 285: Line 284:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Fetch skill record by internal ID.
-- getSkillById: locate a skill by internal ID.
local function getSkillById(id)
local function getSkillById(id)
id = trim(id)
id = trim(id)
Line 293: Line 292:
end
end


-- Find skill record by display/external/internal names.
-- findSkillByName: locate a skill by external/display name.
local function findSkillByName(name)
local function findSkillByName(name)
name = trim(name)
name = trim(name)
Line 320: Line 319:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Decide label for legacy damage basis.
-- basisLabel: label ATK/MATK basis in legacy damage blocks.
local function basisLabel(entry, isHealing)
local function basisLabel(entry, isHealing)
if isHealing then
if isHealing then
Line 340: Line 339:
end
end


-- Build dynamic legacy damage percent string for a single entry.
-- formatDamageEntry: legacy percent damage formatting (dynamic by level).
local function formatDamageEntry(entry, maxLevel, level)
local function formatDamageEntry(entry, maxLevel, level)
if type(entry) ~= "table" then
if type(entry) ~= "table" then
Line 392: Line 391:
end
end


-- Render a list of legacy damage entries (stacked).
-- formatDamageList: render a list of legacy damage entries into <br/> blocks.
local function formatDamageList(list, maxLevel, level, includeTypePrefix)
local function formatDamageList(list, maxLevel, level, includeTypePrefix)
if type(list) ~= "table" or #list == 0 then
if type(list) ~= "table" or #list == 0 then
Line 419: Line 418:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- True if a skill record belongs to a given user/class/summon/etc.
-- skillMatchesUser: check if a skill is used by a specific class/monster/summon/event.
local function skillMatchesUser(rec, userName)
local function skillMatchesUser(rec, userName)
if type(rec) ~= "table" or not userName or userName == "" then
if type(rec) ~= "table" or not userName or userName == "" then
Line 451: Line 450:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Determine if current page is the skill’s own page (so we can hide Users rows).
-- isDirectSkillPage: hide Users rows when viewing the skill page itself.
local function isDirectSkillPage(rec)
local function isDirectSkillPage(rec)
if type(rec) ~= "table" then
if type(rec) ~= "table" then
Line 478: Line 477:
local HERO_BAR_SLOT_ASSIGNMENT = {
local HERO_BAR_SLOT_ASSIGNMENT = {
[1] = "IconName",
[1] = "IconName",
[2] = "SkillType",
[2] = "SkillType", -- Damage/Element/Hits/Target/Cast/Combo strip
}
}


Line 492: Line 491:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Render a hero-bar slot wrapper.
-- heroBarBox: wrapper for hero-bar slot modules.
local function heroBarBox(slot, extraClasses, innerHtml, isEmpty)
local function heroBarBox(slot, extraClasses, innerHtml, isEmpty)
local box = mw.html.create("div")
local box = mw.html.create("div")
Line 523: Line 522:
end
end


-- Render a hero-module slot wrapper (2x2 grid tiles).
-- moduleBox: wrapper for hero-module (2x2 grid) slot modules.
local function moduleBox(slot, extraClasses, innerHtml, isEmpty)
local function moduleBox(slot, extraClasses, innerHtml, isEmpty)
local box = mw.html.create("div")
local box = mw.html.create("div")
Line 554: Line 553:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Format scaling list into “X% Stat” compact lines.
-- formatScalingCompactLines: build compact “Scaling” lines for SourceType.
local function formatScalingCompactLines(scaling)
local function formatScalingCompactLines(scaling)
if type(scaling) ~= "table" then
if type(scaling) ~= "table" then
Line 587: Line 586:
end
end


-- Compute modifier word from ATK/MATK flags (used in SourceType module).
-- basisWordFromFlags: compute “Attack/Magic/Hybrid” from ATK/MATK booleans.
local function basisWordFromFlags(atkFlag, matkFlag)
local function basisWordFromFlags(atkFlag, matkFlag)
if atkFlag and matkFlag then
if atkFlag and matkFlag then
Line 599: Line 598:
end
end


-- Legacy damage percent at a given level.
-- legacyPercentAtLevel: compute “Base% + PerLevel%*level” for legacy entries.
local function legacyPercentAtLevel(entry, level)
local function legacyPercentAtLevel(entry, level)
if type(entry) ~= "table" then
if type(entry) ~= "table" then
Line 625: Line 624:
end
end


-- Expand a Base/Per Level block into a per-level display series.
-- seriesFromValuePair: normalize Base/Per Level blocks into a level-indexed series.
local function seriesFromValuePair(block, maxLevel)
local function seriesFromValuePair(block, maxLevel)
if type(block) ~= "table" then
if type(block) ~= "table" then
Line 706: Line 705:
end
end


-- Convert a per-level series into a display value (flat -> plain text, else dyn span).
-- displayFromSeries: render a series as fixed text or dynSpan (nil if all “—”).
local function displayFromSeries(series, level)
local function displayFromSeries(series, level)
if type(series) ~= "table" or #series == 0 then
if type(series) ~= "table" or #series == 0 then
Line 729: Line 728:
end
end


-- Format Area Size block into a human display string.
-- formatAreaSize: human readable area sizing for QuickStats.
local function formatAreaSize(area)
-- Shows: "<Area Size> (<number>)" e.g. "Medium (4)"
local function formatAreaSize(area, maxLevel, level)
if type(area) ~= "table" then
if type(area) ~= "table" then
return nil
return nil
end
end


local raw = area["Area Size"]
-- Helper: pull a number from scalar/unit/valuepair-ish things.
if raw == nil then
local function extractNumber(v)
if v == nil then return nil end
 
-- Unit block {Value, Unit}
if type(v) == "table" and v.Value ~= nil then
local n = toNum(v.Value)
return n
end
 
-- ValuePair {Base, Per Level} -> prefer Base at current level if series exists
if type(v) == "table" and (v.Base ~= nil or v["Per Level"] ~= nil) then
local s = seriesFromValuePair(v, maxLevel or 1)
if type(s) == "table" and #s > 0 then
local idx = clamp(level or 1, 1, #s)
local txt = s[idx]
if txt and txt ~= "—" then
-- try parse numeric from string (e.g. "4 tiles" -> 4)
local num = tonumber((mw.ustring.gsub(tostring(txt), "[^0-9%.%-]", "")))
return num
end
end
return nil
end
 
-- Plain scalar
if type(v) == "number" then return v end
if type(v) == "string" then
local num = tonumber((mw.ustring.gsub(mw.text.trim(v), "[^0-9%.%-]", "")))
return num
end
 
return nil
end
 
-- 1) Read Area Size label/name
local rawSize = area["Area Size"]
if rawSize == nil then
return nil
return nil
end
end


local name, num
local sizeName = nil
if type(rawSize) == "table" then
sizeName = rawSize.Name or rawSize.ID or rawSize.Value
elseif type(rawSize) == "string" then
sizeName = rawSize
elseif type(rawSize) == "number" then
-- uncommon; treat as numeric-only label
sizeName = tostring(rawSize)
end


if type(raw) == "table" then
sizeName = sizeName and mw.text.trim(tostring(sizeName)) or nil
name = raw.Name or raw.ID or raw.Value
if not sizeName or sizeName == "" or isNoneLike(sizeName) then
num = raw.Value
return nil
if raw.Name or raw.ID then
end
name = raw.Name or raw.ID
 
-- 2) Find the numeric “exact number” to append
-- Prefer the explicit Area Distance block, then fall back to other known numeric keys.
local num = nil
 
local dist = area["Area Distance"]
if type(dist) == "table" then
-- Prefer Effective Distance if present and non-zero, else Base
num = extractNumber(dist["Effective Distance"]) or extractNumber(dist.Effective) or extractNumber(dist["Effective"])
if not num or num == 0 then
num = extractNumber(dist.Base) or extractNumber(dist["Base"])
end
end
elseif type(raw) == "string" then
name = raw
elseif type(raw) == "number" then
num = raw
end
end


if num == nil then
if not num or num == 0 then
num = toNum(area["Area Value"]) or toNum(area["Area Size Value"]) or toNum(area["Area Number"]) or toNum(area["Area Radius"])
num =
extractNumber(area["Area Value"]) or
extractNumber(area["Area Size Value"]) or
extractNumber(area["Area Number"]) or
extractNumber(area["Area Radius"])
end
end


if name ~= nil then
-- 3) Render
local s = mw.text.trim(tostring(name))
-- If size already contains parentheses, assume it already includes the numeric.
if s == "" or isNoneLike(s) then
if mw.ustring.find(sizeName, "%(") then
return nil
return mw.text.nowiki(sizeName)
end
if mw.ustring.find(s, "%(") then
return mw.text.nowiki(s)
end
if num ~= nil and num ~= 0 then
return mw.text.nowiki(string.format("%s (%s)", s, fmtNum(num)))
end
return mw.text.nowiki(s)
end
end


if num ~= nil and num ~= 0 then
if num and num ~= 0 then
return mw.text.nowiki(string.format("(%s)", fmtNum(num)))
return mw.text.nowiki(string.format("%s (%s)", sizeName, fmtNum(num)))
end
end


return nil
return mw.text.nowiki(sizeName)
end
end


-- True if any non-empty damage/source exists for this skill (used for hiding Damage/Element/Hits).
-- skillHasAnyDamage: determine if a skill has any meaningful damage (for non-damaging rules).
local function skillHasAnyDamage(rec, maxLevel)
local function skillHasAnyDamage(rec, maxLevel)
if type(rec.Source) == "table" then
if type(rec.Source) == "table" then
Line 803: Line 849:
end
end


-- Promote first status-application duration into QuickStats if Duration is otherwise empty (non-damaging only).
-- computeDurationPromotion: promote status-duration into QuickStats when a skill is non-damaging.
local function computeDurationPromotion(rec, maxLevel)
local function computeDurationPromotion(rec, maxLevel)
if type(rec) ~= "table" then return nil end
if type(rec) ~= "table" then return nil end
Line 850: Line 896:
local PLUGINS = {}
local PLUGINS = {}


-- Hero Bar Slot 1: Icon + Name
-- PLUGIN: IconName (Hero Bar Slot 1) - icon + name.
function PLUGINS.IconName(rec, ctx)
function PLUGINS.IconName(rec, ctx)
local icon  = rec.Icon
local icon  = rec.Icon
Line 874: Line 920:
end
end


-- Hero Bar Slot 2: Skill Type (Damage/Element/Hits/Target/Cast/Combo)
-- PLUGIN: SkillType (Hero Bar Slot 2) - 2 rows x 3 cells (desktop + mobile).
-- Rules:
--  - If skill is non-damaging, hide Damage/Element/Hits.
--  - If Hits is empty, hide Hits.
--  - If Combo is empty, hide Combo.
-- Ordering:
--  - Desktop: Damage, Element, Hits, Target, Cast, Combo
--  - Mobile:  Damage, Element, Target, Cast, Hits, Combo (CSS reorder)
function PLUGINS.SkillType(rec, ctx)
function PLUGINS.SkillType(rec, ctx)
local level = ctx.level or 1
local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local mech      = (type(rec.Mechanics) == "table") and rec.Mechanics or {}
 
local level   = ctx.level or 1
local maxLevel = ctx.maxLevel or 1
local maxLevel = ctx.maxLevel or 1


local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local hideDamageBundle = (ctx.nonDamaging == true)
local mech = (type(rec.Mechanics) == "table") and rec.Mechanics or {}
 
-- Rule: If Damage is none/non-damaging -> hide Damage, Element, Hits.
local hideDamageElementHits = (ctx.nonDamaging == true)


-- Extract a friendly display string from common { Name/ID/Value } tables.
-- valName: extract a display string from typical {Name/ID/Value} objects.
-- NOTE: Includes number support so Hits=2 (number) doesn't get dropped.
local function valName(x)
local function valName(x)
if x == nil then return nil end
if x == nil then return nil end
Line 892: Line 945:
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.Value ~= nil then return tostring(x.Value) end
if x.Value ~= nil then return tostring(x.Value) end
end
if type(x) == "number" then
return tostring(x)
end
end
if type(x) == "string" and x ~= "" then
if type(x) == "string" and x ~= "" then
Line 899: Line 955:
end
end


-- Build “Combo” display text (Type + optional percent/duration).
-- hitsDisplay: find + render Hits from multiple possible structured locations.
local function formatComboText(combo)
local function hitsDisplay()
if combo == nil then return nil end
local effects = (type(mech.Effects) == "table") and mech.Effects or {}
 
local h =
typeBlock.Hits or typeBlock["Hits"] or typeBlock["Hit Count"] or typeBlock["Hits Count"] or
mech.Hits or mech["Hits"] or mech["Hit Count"] or mech["Hits Count"] or
effects.Hits or effects["Hits"] or effects["Hit Count"] or effects["Hits Count"] or
rec.Hits or rec["Hits"]
 
if h == nil or isNoneLike(h) then
return nil
end
 
-- ValuePair-style table (Base/Per Level) => dynamic series
if type(h) == "table" then
if h.Base ~= nil or h["Per Level"] ~= nil or type(h["Per Level"]) == "table" then
return displayFromSeries(seriesFromValuePair(h, maxLevel), level)
end
 
-- Unit block {Value, Unit}
if h.Value ~= nil then
local t = formatUnitValue(h)
return t and mw.text.nowiki(t) or nil
end
 
-- Fallback name extraction
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
if x.Value ~= nil then return tostring(x.Value) end
end
if type(x) == "number" then return tostring(x) end
if type(x) == "string" and x ~= "" then return x end
return nil
end


-- Sometimes data may store combo as a simple string.
local vn = valName(h)
if type(combo) == "string" then
if vn and not isNoneLike(vn) then
local s = trim(combo)
return mw.text.nowiki(vn)
return (s and not isNoneLike(s)) and mw.text.nowiki(s) or nil
end
end
end


if type(combo) ~= "table" then
-- Scalar number/string
return nil
if type(h) == "number" then
return mw.text.nowiki(fmtNum(h))
end
if type(h) == "string" then
local t = trim(h)
return (t and not isNoneLike(t)) and mw.text.nowiki(t) or nil
end
end


local typ = trim(combo.Type)
return nil
end
 
-- comboDisplay: render Combo as a compact text block (Type (+ details)).
local function comboDisplay()
local c = (type(mech.Combo) == "table") and mech.Combo or nil
if not c then return nil end
 
local typ = trim(c.Type)
if not typ or isNoneLike(typ) then
if not typ or isNoneLike(typ) then
return nil
return nil
Line 920: Line 1,024:
local details = {}
local details = {}


local pct = formatUnitValue(combo.Percent)
local pct = formatUnitValue(c.Percent)
if pct and not isZeroish(pct) then
if pct and not isZeroish(pct) then
table.insert(details, mw.text.nowiki(pct))
table.insert(details, mw.text.nowiki(pct))
end
end


local dur = formatUnitValue(combo.Duration)
local dur = formatUnitValue(c.Duration)
if dur and not isZeroish(dur) then
if dur and not isZeroish(dur) then
table.insert(details, mw.text.nowiki(dur))
table.insert(details, mw.text.nowiki(dur))
Line 936: Line 1,040:
end
end


-- Compute “Hits” display (supports Base/Per Level blocks and scalars).
local grid = mw.html.create("div")
local function formatHitsValue(rawHits)
grid:addClass("sv-type-grid")
if rawHits == nil or isNoneLike(rawHits) or isZeroish(rawHits) then
grid:addClass("sv-compact-root")
return nil
end


if type(rawHits) == "table" then
local added = false
-- If it looks like a value-pair block, prefer series rendering.
local s = seriesFromValuePair(rawHits, maxLevel)
local disp = displayFromSeries(s, level)
if disp then return disp end


-- Fallback: raw rendering.
-- addChunk: add one labeled value cell (key drives CSS ordering).
local txt = valuePairDynamicValueOnly(rawHits, maxLevel, level)
local function addChunk(key, label, valueHtml)
return txt
if valueHtml == nil or valueHtml == "" then return end
end
added = true
 
local chunk = grid:tag("div")
:addClass("sv-type-chunk")
:addClass("sv-type-" .. tostring(key))
:attr("data-type-key", tostring(key))


return mw.text.nowiki(tostring(rawHits))
chunk:tag("div")
end
:addClass("sv-type-label")
:wikitext(mw.text.nowiki(label))


local hitsVal = nil
chunk:tag("div")
if not hideDamageElementHits then
:addClass("sv-type-value")
hitsVal = formatHitsValue(mech.Hits or mech["Hits"])
:wikitext(valueHtml)
end
end


local comboVal = formatComboText(mech.Combo or mech["Combo"])
-- Damage + Element + Hits bundle (hidden when non-damaging)
if not hideDamageBundle then
local dmg  = valName(typeBlock.Damage or typeBlock["Damage Type"])
local ele  = valName(typeBlock.Element or typeBlock["Element Type"])
local hits = hitsDisplay()


local grid = mw.html.create("div")
if dmg and not isNoneLike(dmg) then
grid:addClass("sv-type-grid")
addChunk("damage", "Damage", mw.text.nowiki(dmg))
grid:addClass("sv-compact-root")
end
if ele and not isNoneLike(ele) then
addChunk("element", "Element", mw.text.nowiki(ele))
end
if hits then
addChunk("hits", "Hits", hits)
end
end


local added = false
-- Target + Cast
local tgt = valName(typeBlock.Target or typeBlock["Target Type"])
local cst = valName(typeBlock.Cast  or typeBlock["Cast Type"])


-- Add a grid “chunk” cell. If isHtml=true, value is already safe wikitext/HTML.
if tgt and not isNoneLike(tgt) then
local function addChunk(label, value, chunkClass, isHtml)
addChunk("target", "Target", mw.text.nowiki(tgt))
if value == nil or value == "" then return end
end
added = true
if cst and not isNoneLike(cst) then
 
addChunk("cast", "Cast", mw.text.nowiki(cst))
local chunk = grid:tag("div"):addClass("sv-type-chunk")
if chunkClass then chunk:addClass(chunkClass) end
 
chunk:tag("div"):addClass("sv-type-label"):wikitext(mw.text.nowiki(label))
 
local v = chunk:tag("div"):addClass("sv-type-value")
if isHtml then
v:wikitext(value)
else
v:wikitext(mw.text.nowiki(tostring(value)))
end
end
end


-- Desktop order (row-major 4 columns):
-- Combo
-- Damage, Element, Hits, Target / Cast, Combo
local combo = comboDisplay()
if not hideDamageElementHits then
if combo then
addChunk("Damage",  valName(typeBlock.Damage  or typeBlock["Damage Type"]), "sv-type-chunk--damage",  false)
addChunk("combo", "Combo", combo)
addChunk("Element", valName(typeBlock.Element or typeBlock["Element Type"]), "sv-type-chunk--element", false)
addChunk("Hits",    hitsVal,                                              "sv-type-chunk--hits",   true)
end
end
addChunk("Target", valName(typeBlock.Target or typeBlock["Target Type"]), "sv-type-chunk--target", false)
addChunk("Cast",  valName(typeBlock.Cast  or typeBlock["Cast Type"]),  "sv-type-chunk--cast",  false)
addChunk("Combo",  comboVal,                                              "sv-type-chunk--combo",  true)


return {
return {
Line 1,005: Line 1,105:
end
end


-- Module Tile: Level Selector (hero-module-4)
-- PLUGIN: SourceType (Hero Module Slot 1) - Modifier + Source + Scaling.
function PLUGINS.LevelSelector(rec, ctx)
function PLUGINS.SourceType(rec, ctx)
local level = ctx.level or 1
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1
local maxLevel = ctx.maxLevel or 1


local inner = mw.html.create("div")
local basisWord = nil
inner:addClass("sv-level-ui")
local sourceKind = nil
local sourceVal  = nil
local scaling    = nil


inner:tag("div")
-- sourceValueForLevel: dynamic formatting for structured Source blocks.
:addClass("sv-level-label")
local function sourceValueForLevel(src)
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))
if type(src) ~= "table" then
return nil
end
 
local per = src["Per Level"]
if type(per) == "table" and #per > 0 then
if isFlatList(per) then
local one  = formatUnitValue(per[1]) or tostring(per[1])
local show = formatUnitValue(src.Base) or one
return show and mw.text.nowiki(show) or nil
end


local slider = inner:tag("div"):addClass("sv-level-slider")
local series = {}
for _, v in ipairs(per) do
table.insert(series, formatUnitValue(v) or tostring(v))
end
return dynSpan(series, level)
end


if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
return valuePairDynamicValueOnly(src, maxLevel, level)
slider:tag("input")
:attr("type", "range")
:attr("min", "1")
:attr("max", tostring(maxLevel))
:attr("value", tostring(level))
:addClass("sv-level-range")
:attr("aria-label", "Skill level select")
else
inner:addClass("sv-level-ui-single")
slider:addClass("sv-level-slider-single")
end
end


return {
if type(rec.Source) == "table" then
inner = tostring(inner),
local src = rec.Source
classes = "module-level-selector",
local atkFlag  = (src["ATK-Based"] == true)
}
local matkFlag = (src["MATK-Based"] == true)
end
basisWord = basisWordFromFlags(atkFlag, matkFlag)


-- Module Tile: SourceType (Modifier + Source + Scaling)
sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
function PLUGINS.SourceType(rec, ctx)
sourceVal  = sourceValueForLevel(src)
local level = ctx.level or 1
scaling    = src.Scaling
local maxLevel = ctx.maxLevel or 1
end


local basisWord = nil
-- Fallback to legacy Damage lists if Source absent
local sourceKind = nil
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
local sourceVal  = nil
local dmg = rec.Damage
local scaling   = nil
scaling = scaling or dmg.Scaling


-- Render Source value at selected level (supports per-level series).
local main = dmg["Main Damage"]
local function sourceValueForLevel(src)
local refl = dmg["Reflect Damage"]
if type(src) ~= "table" then
local flat = dmg["Flat Damage"]
return nil
end


local per = src["Per Level"]
if type(main) == "table" and #main > 0 then
if type(per) == "table" and #per > 0 then
local pick = nil
if isFlatList(per) then
for _, d in ipairs(main) do
local one  = formatUnitValue(per[1]) or tostring(per[1])
if type(d) == "table" and d.Type ~= "Healing" then
local show = formatUnitValue(src.Base) or one
pick = d
return show and mw.text.nowiki(show) or nil
break
end
end
end
pick = pick or main[1]


local series = {}
if type(pick) == "table" then
for _, v in ipairs(per) do
local atkFlag  = (pick["ATK-Based"] == true)
table.insert(series, formatUnitValue(v) or tostring(v))
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
 
sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
sourceVal  = legacyPercentAtLevel(pick, level)
end
end
return dynSpan(series, level)
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
local pick = refl[1]
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
 
sourceKind = "Reflect"
sourceVal  = legacyPercentAtLevel(pick, level)
elseif type(flat) == "table" and #flat > 0 and type(flat[1]) == "table" then
local pick = flat[1]
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
 
sourceKind = "Flat"
sourceVal  = legacyPercentAtLevel(pick, level)
end
end
return valuePairDynamicValueOnly(src, maxLevel, level)
end
end


if type(rec.Source) == "table" then
local scalingLines = formatScalingCompactLines(scaling)
local src = rec.Source
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
local atkFlag  = (src["ATK-Based"] == true)
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)
local matkFlag = (src["MATK-Based"] == true)
basisWord = basisWordFromFlags(atkFlag, matkFlag)


sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
if (not hasSource) and (not hasScaling) then
sourceVal  = sourceValueForLevel(src)
return nil
scaling    = src.Scaling
end
end


-- Fallback to legacy Damage lists if Source absent
local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
local dmg = rec.Damage
scaling = scaling or dmg.Scaling


local main = dmg["Main Damage"]
local extra = { "skill-source-module" }
local refl = dmg["Reflect Damage"]
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
local flat = dmg["Flat Damage"]


if type(main) == "table" and #main > 0 then
if hasSource and (not hasScaling) then
local pick = nil
table.insert(extra, "sv-only-source")
for _, d in ipairs(main) do
elseif hasScaling and (not hasSource) then
if type(d) == "table" and d.Type ~= "Healing" then
table.insert(extra, "sv-only-scaling")
pick = d
end
break
end
end
pick = pick or main[1]


if type(pick) == "table" then
local wrap = mw.html.create("div")
local atkFlag  = (pick["ATK-Based"] == true)
wrap:addClass("sv-source-grid")
local matkFlag = (pick["MATK-Based"] == true)
wrap:addClass("sv-compact-root")
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
if hasMod then
sourceVal  = legacyPercentAtLevel(pick, level)
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
end
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
local pick = refl[1]
end
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = "Reflect"
if hasSource then
sourceVal  = legacyPercentAtLevel(pick, level)
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
elseif type(flat) == "table" and #flat > 0 and type(flat[1]) == "table" then
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
local pick = flat[1]
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
 
sourceKind = "Flat"
sourceVal = legacyPercentAtLevel(pick, level)
end
end
end


local scalingLines = formatScalingCompactLines(scaling)
if hasScaling then
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")


if (not hasSource) and (not hasScaling) then
local list = scalingCol:tag("div"):addClass("sv-scaling-list")
return nil
for _, line in ipairs(scalingLines) do
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
end
end
end


local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
return {
inner = tostring(wrap),
classes = extra,
}
end


local extra = { "skill-source-module" }
-- PLUGIN: QuickStats (Hero Module Slot 2) - 3x2 grid (range/area/cost/cast/cd/duration).
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
-- NOTE: Hits does NOT live here (it lives in SkillType).
function PLUGINS.QuickStats(rec, ctx)
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1
local promo = ctx.promo


if hasSource and (not hasScaling) then
local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
table.insert(extra, "sv-only-source")
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
elseif hasScaling and (not hasSource) then
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}
table.insert(extra, "sv-only-scaling")
end


local wrap = mw.html.create("div")
local function dash() return "" end
wrap:addClass("sv-source-grid")
wrap:addClass("sv-compact-root")


if hasMod then
-- Range (0 => —)
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
local rangeVal = nil
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
if mech.Range ~= nil and not isNoneLike(mech.Range) then
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
local n = toNum(mech.Range)
if n ~= nil then
if n ~= 0 then
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
end
else
local t = mw.text.trim(tostring(mech.Range))
if t ~= "" and not isNoneLike(t) then
rangeVal = mw.text.nowiki(t)
end
end
end
end


if hasSource then
-- Area
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
local areaVal = formatAreaSize(mech.Area, maxLevel, level)
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
end


if hasScaling then
-- Timings
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"],  maxLevel), level)


local list = scalingCol:tag("div"):addClass("sv-scaling-list")
-- Promote status duration if needed
for _, line in ipairs(scalingLines) do
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
end
end
end


return {
-- Cost: MP + HP
inner = tostring(wrap),
local function labeledSeries(block, label)
classes = extra,
local s = seriesFromValuePair(block, maxLevel)
}
if not s then return nil end
end
local any = false
for i, v in ipairs(s) do
if v ~= "—" then
s[i] = tostring(v) .. " " .. label
any = true
else
s[i] = "—"
end
end
return any and s or nil
end


-- Module Tile: Quick Stats (Range/Area/Cost/Cast/CD/Duration)
local mpS = labeledSeries(rc["Mana Cost"], "MP")
function PLUGINS.QuickStats(rec, ctx)
local hpS = labeledSeries(rc["Health Cost"], "HP")
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1
local promo = ctx.promo


local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
local costSeries = {}
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
for lv = 1, maxLevel do
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}
local mp = mpS and mpS[lv] or ""
local hp = hpS and hpS[lv] or ""


local function dash() return "—" end
if mp ~= "—" and hp ~= "—" then
 
costSeries[lv] = mp .. " + " .. hp
-- Range: hide if 0/none-like.
elseif mp ~= "—" then
local rangeVal = nil
costSeries[lv] = mp
if mech.Range ~= nil and not isNoneLike(mech.Range) then
elseif hp ~= "—" then
local n = toNum(mech.Range)
costSeries[lv] = hp
if n ~= nil then
if n ~= 0 then
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
end
else
else
local t = mw.text.trim(tostring(mech.Range))
costSeries[lv] = ""
if t ~= "" and not isNoneLike(t) then
rangeVal = mw.text.nowiki(t)
end
end
end
end
end


-- Area (friendly formatting)
local costVal = displayFromSeries(costSeries, level)
local areaVal = formatAreaSize(mech.Area)


-- Timings
local grid = mw.html.create("div")
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
grid:addClass("sv-m4-grid")
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
grid:addClass("sv-compact-root")
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"],  maxLevel), level)


-- Promote status duration into QuickStats when needed
local function addCell(label, val)
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
local cell = grid:tag("div"):addClass("sv-m4-cell")
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
end
end


-- Cost: MP + HP (combined)
addCell("Range",    rangeVal)
local function labeledSeries(block, label)
addCell("Area",      areaVal)
local s = seriesFromValuePair(block, maxLevel)
addCell("Cost",      costVal)
if not s then return nil end
addCell("Cast Time", castVal)
local any = false
addCell("Cooldown", cdVal)
for i, v in ipairs(s) do
addCell("Duration", durVal)
if v ~= "" then
 
s[i] = tostring(v) .. " " .. label
return {
any = true
inner = tostring(grid),
else
classes = "module-quick-stats",
s[i] = "—"
}
end
end
end
 
return any and s or nil
-- PLUGIN: SpecialMechanics (Hero Module Slot 3)
end
-- Shows:
--  - Flags (deduped)
--  - Special mechanics (mech.Effects)
-- NOTE: Combo lives in SkillType (Hero Bar Slot 2).
function PLUGINS.SpecialMechanics(rec, ctx)
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


local mpS = labeledSeries(rc["Mana Cost"], "MP")
local mech    = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
local hpS = labeledSeries(rc["Health Cost"], "HP")
local effects = (type(mech.Effects) == "table") and mech.Effects or nil
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil


local costSeries = {}
------------------------------------------------------------------
for lv = 1, maxLevel do
-- Hits guard (we want Hits ONLY in SkillType)
local mp = mpS and mpS[lv] or ""
------------------------------------------------------------------
local hp = hpS and hpS[lv] or ""
local function isHitsKey(name)
if not name then return false end
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
return (
k == "hit" or
k == "hits" or
k == "hit count" or
k == "hits count" or
k == "hitcount" or
k == "hitscount"
)
end


if mp ~= "—" and hp ~= "—" then
------------------------------------------------------------------
costSeries[lv] = mp .. " + " .. hp
-- Flags (flat, de-duped)
elseif mp ~= "—" then
------------------------------------------------------------------
costSeries[lv] = mp
local flagSet = {}
elseif hp ~= "—" then
costSeries[lv] = hp
else
costSeries[lv] = "—"
end
end


local costVal = displayFromSeries(costSeries, level)
local denyFlags = {
["self centered"] = true,
["self-centred"] = true,
["bond"] = true,
["combo"] = true,
        ["hybrid"] = true,


local grid = mw.html.create("div")
-- hits variants
grid:addClass("sv-m4-grid")
["hit"] = true,
grid:addClass("sv-compact-root")
["hits"] = true,
["hit count"] = true,
["hits count"] = true,
["hitcount"] = true,
["hitscount"] = true,
}


-- Add one QuickStats cell.
local function allowFlag(name)
local function addCell(label, val)
if not name then return false end
local cell = grid:tag("div"):addClass("sv-m4-cell")
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
if k == "" then return false end
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
if denyFlags[k] then return false end
return true
end
end


addCell("Range",    rangeVal)
local function addFlags(sub)
addCell("Area",     areaVal)
if type(sub) ~= "table" then return end
addCell("Cost",      costVal)
for k, v in pairs(sub) do
addCell("Cast Time", castVal)
if v and allowFlag(k) then
addCell("Cooldown",  cdVal)
flagSet[tostring(k)] = true
addCell("Duration",  durVal)
end
end
end


return {
if mods then
inner = tostring(grid),
addFlags(mods["Movement Modifiers"])
classes = "module-quick-stats",
addFlags(mods["Combat Modifiers"])
}
addFlags(mods["Special Modifiers"])
end
for k, v in pairs(mods) do
if type(v) == "boolean" and v and allowFlag(k) then
flagSet[tostring(k)] = true
end
end
end


-- Module Tile: Special Mechanics (Flags + Special Effects)
local flags = {}
-- NOTE: Hybrid/Self-centered/Bond/Combo/Hits are intentionally excluded here.
for k, _ in pairs(flagSet) do table.insert(flags, k) end
function PLUGINS.SpecialMechanics(rec, ctx)
table.sort(flags)
local level = ctx.level or 1
 
local maxLevel = ctx.maxLevel or 1
------------------------------------------------------------------
-- Special mechanics (name => value)
------------------------------------------------------------------
local mechItems = {}


local mech    = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
if effects then
local effects = (type(mech.Effects) == "table") and mech.Effects or nil
local keys = {}
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil
for k, _ in pairs(effects) do table.insert(keys, k) end
table.sort(keys)


-- Case-insensitive omit list for mechanics/flags we are not showing in this module.
for _, name in ipairs(keys) do
local OMIT = {
-- Skip Hits completely (it belongs in SkillType)
["hybrid"] = true,
if not isHitsKey(name) then
["self centered"] = true,
local block = effects[name]
["self-centered"] = true,
if type(block) == "table" then
["bond"] = true,
-- Also skip if the block's Type is "Hits" (some data may encode it that way)
["combo"] = true,
if not isHitsKey(block.Type) then
["hits"] = true,
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
}
local t = trim(block.Type)


-- True if a name should be omitted from this module.
local value = disp
local function shouldOmit(name)
if not name then return false end
local s = mw.ustring.lower(mw.text.trim(tostring(name)))
return (s ~= "" and OMIT[s] == true) or false
end


------------------------------------------------------------------
-- If Type exists and is distinct, prefix it.
-- Flags (flat, de-duped)
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
------------------------------------------------------------------
if value then
local flagSet = {}
value = mw.text.nowiki(t) .. ": " .. value
else
value = mw.text.nowiki(t)
end
end


-- Add boolean flags from a sub-table into a set.
if value then
local function addFlags(sub)
table.insert(mechItems, { label = tostring(name), value = value })
if type(sub) ~= "table" then return end
end
for k, v in pairs(sub) do
end
if v and not shouldOmit(k) then
end
flagSet[tostring(k)] = true
end
end
end
end
end
end


if mods then
local hasFlags = (#flags > 0)
addFlags(mods["Movement Modifiers"])
local hasMech  = (#mechItems > 0)
addFlags(mods["Combat Modifiers"])
addFlags(mods["Special Modifiers"])
for k, v in pairs(mods) do
if type(v) == "boolean" and v and not shouldOmit(k) then
flagSet[tostring(k)] = true
end
end
end


local flags = {}
if (not hasFlags) and (not hasMech) then
for k, _ in pairs(flagSet) do table.insert(flags, k) end
local root = mw.html.create("div")
table.sort(flags)
root:addClass("sv-sm-root")
root:addClass("sv-compact-root")
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")


------------------------------------------------------------------
return {
-- Special effects (name => value)
inner = tostring(root),
------------------------------------------------------------------
classes = "module-special-mechanics",
local mechItems = {}
}
end


if effects then
local count = 0
local keys = {}
if hasFlags then count = count + 1 end
for k, _ in pairs(effects) do
if hasMech  then count = count + 1 end
if not shouldOmit(k) then
table.insert(keys, k)
end
end
table.sort(keys)


for _, name in ipairs(keys) do
local root = mw.html.create("div")
local block = effects[name]
root:addClass("sv-sm-root")
if type(block) == "table" then
root:addClass("sv-compact-root")
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
local t = trim(block.Type)


local value = disp
local layout = root:tag("div"):addClass("sv-sm-layout")
layout:addClass("sv-sm-count-" .. tostring(count))


-- If Type exists and is distinct, prefix it.
-- Column 1: Flags
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
if hasFlags then
if value then
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
value = mw.text.nowiki(t) .. ": " .. value
for _, f in ipairs(flags) do
else
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
value = mw.text.nowiki(t)
end
end
 
if value then
table.insert(mechItems, { label = tostring(name), value = value })
end
end
end
end
end
end


local hasFlags = (#flags > 0)
-- Column 2: Special Mechanics (stacked)
local hasMech  = (#mechItems > 0)
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


if (not hasFlags) and (not hasMech) then
return {
local root = mw.html.create("div")
inner = tostring(root),
root:addClass("sv-sm-root")
classes = "module-special-mechanics",
root:addClass("sv-compact-root")
}
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")
end


return {
-- PLUGIN: LevelSelector (Hero Module Slot 4) - JS level slider.
inner = tostring(root),
function PLUGINS.LevelSelector(rec, ctx)
classes = "module-special-mechanics",
local level = ctx.level or 1
}
local maxLevel = ctx.maxLevel or 1
end


local count = 0
local inner = mw.html.create("div")
if hasFlags then count = count + 1 end
inner:addClass("sv-level-ui")
if hasMech  then count = count + 1 end


-- Desktop:
inner:tag("div")
--  1 group => centered
:addClass("sv-level-label")
--  2 groups => 2 columns (flags | mechanics)
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))
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 slider = inner:tag("div"):addClass("sv-level-slider")
layout:addClass("sv-sm-count-" .. tostring(count))


-- Column: Flags
if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
if hasFlags then
slider:tag("input")
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
:attr("type", "range")
for _, f in ipairs(flags) do
:attr("min", "1")
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
:attr("max", tostring(maxLevel))
end
:attr("value", tostring(level))
end
:addClass("sv-level-range")
 
:attr("aria-label", "Skill level select")
-- Column: Special Effects (stacked)
else
if hasMech then
inner:addClass("sv-level-ui-single")
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech")
slider:addClass("sv-level-slider-single")
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
end


return {
return {
inner = tostring(root),
inner = tostring(inner),
classes = "module-special-mechanics",
classes = "module-level-selector",
}
}
end
end
Line 1,434: Line 1,558:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Normalize plugin return into { inner = string, classes = string|table|nil }.
-- normalizeResult: normalize plugin return values into {inner, classes}.
local function normalizeResult(res)
local function normalizeResult(res)
if res == nil then return nil end
if res == nil then return nil end
Line 1,450: Line 1,574:
end
end


-- Safe plugin call (pcall) to prevent infobox from breaking the page.
-- safeCallPlugin: pcall wrapper to prevent infobox failure on plugin errors.
local function safeCallPlugin(name, rec, ctx)
local function safeCallPlugin(name, rec, ctx)
local fn = PLUGINS[name]
local fn = PLUGINS[name]
Line 1,463: Line 1,587:
end
end


-- Render one hero-bar slot via assignment table.
-- renderHeroBarSlot: render a hero-bar slot by plugin assignment.
local function renderHeroBarSlot(slotIndex, rec, ctx)
local function renderHeroBarSlot(slotIndex, rec, ctx)
local pluginName = HERO_BAR_SLOT_ASSIGNMENT[slotIndex]
local pluginName = HERO_BAR_SLOT_ASSIGNMENT[slotIndex]
Line 1,478: Line 1,602:
end
end


-- Render one hero-module tile via assignment table.
-- renderModuleSlot: render a hero-module slot by plugin assignment.
local function renderModuleSlot(slotIndex, rec, ctx)
local function renderModuleSlot(slotIndex, rec, ctx)
local pluginName = HERO_MODULE_SLOT_ASSIGNMENT[slotIndex]
local pluginName = HERO_MODULE_SLOT_ASSIGNMENT[slotIndex]
Line 1,497: Line 1,621:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Build the hero title bar (2 slots).
-- buildHeroBarUI: build the top hero bar (2 slots).
local function buildHeroBarUI(rec, ctx)
local function buildHeroBarUI(rec, ctx)
local bar = mw.html.create("div")
local bar = mw.html.create("div")
Line 1,506: Line 1,630:
end
end


-- Build the 2x2 hero-module grid (4 slots).
-- buildHeroModulesUI: build the 2x2 module grid row (4 slots).
local function buildHeroModulesUI(rec, ctx)
local function buildHeroModulesUI(rec, ctx)
local grid = mw.html.create("div")
local grid = mw.html.create("div")
Line 1,516: Line 1,640:
end
end


-- Add the modules grid row (single cell spanning infobox width).
-- addHeroModulesRow: add the hero-modules row into the infobox table.
local function addHeroModulesRow(tbl, modulesUI)
local function addHeroModulesRow(tbl, modulesUI)
if not modulesUI or modulesUI == "" then
if not modulesUI or modulesUI == "" then
Line 1,535: Line 1,659:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Build a single skill infobox table.
-- buildInfobox: render a single skill infobox.
local function buildInfobox(rec, opts)
local function buildInfobox(rec, opts)
opts = opts or {}
opts = opts or {}
Line 1,551: Line 1,675:
}
}


-- Determine “non-damaging” for hiding Damage/Element/Hits in SkillType.
-- Non-damaging hides Damage/Element/Hits in SkillType
do
do
local dmgVal = nil
local dmgVal = nil
Line 1,563: Line 1,687:
end
end


-- Duration promotion into QuickStats (non-damaging only).
ctx.promo = computeDurationPromotion(rec, maxLevel)
ctx.promo = computeDurationPromotion(rec, maxLevel)


Line 1,616: Line 1,739:
addHeroModulesRow(root, buildHeroModulesUI(rec, ctx))
addHeroModulesRow(root, buildHeroModulesUI(rec, ctx))


-- Users (optionally hidden on direct skill pages)
-- Users (hide on direct skill page)
if showUsers then
if showUsers then
local users = rec.Users or {}
local users = rec.Users or {}
Line 1,651: Line 1,774:
end
end


-- Mechanics (keep only small extras here; most are in hero tiles)
-- Mechanics (keep small extras only)
local mech = rec.Mechanics or {}
local mech = rec.Mechanics or {}
if next(mech) ~= nil then
if next(mech) ~= nil then
Line 1,684: Line 1,807:


-- Status rows
-- Status rows
-- Format Status Applications list into display text.
local function formatStatusApplications(list, suppressDurationIndex)
local function formatStatusApplications(list, suppressDurationIndex)
if type(list) ~= "table" or #list == 0 then return nil end
if type(list) ~= "table" or #list == 0 then return nil end
Line 1,717: Line 1,839:
end
end


-- Format Status Removal list into display text.
local function formatStatusRemoval(list)
local function formatStatusRemoval(list)
if type(list) ~= "table" or #list == 0 then return nil end
if type(list) ~= "table" or #list == 0 then return nil end
Line 1,758: Line 1,879:


-- Events
-- Events
-- Format event triggers list into display text.
local function formatEvents(list)
local function formatEvents(list)
if type(list) ~= "table" or #list == 0 then return nil end
if type(list) ~= "table" or #list == 0 then return nil end
Line 1,789: Line 1,909:
----------------------------------------------------------------------
----------------------------------------------------------------------


function p.listForUser(frame)
function p.listForUser(frame)
local args = getArgs(frame)
local args = getArgs(frame)
 
 
local userName = args.user or args[1]
local userName = args.user or args[1]
if not userName or userName == "" then
if not userName or userName == "" then
userName = mw.title.getCurrentTitle().text
userName = mw.title.getCurrentTitle().text
end
end
 
 
if not userName or userName == "" then
if not userName or userName == "" then
return "<strong>No user name provided to Skill list.</strong>"
return "<strong>No user name provided to Skill list.</strong>"
end
end
 
 
local dataset = getSkills()
local dataset = getSkills()
local matches = {}
local matches = {}
 
 
for _, rec in ipairs(dataset.records or {}) do
for _, rec in ipairs(dataset.records or {}) do
if skillMatchesUser(rec, userName) then
if skillMatchesUser(rec, userName) then
table.insert(matches, rec)
table.insert(matches, rec)
end
end
end
end
 
 
if #matches == 0 then
if #matches == 0 then
return string.format("<strong>No skills found for:</strong> %s", mw.text.nowiki(userName))
return string.format("<strong>No skills found for:</strong> %s", mw.text.nowiki(userName))
end
end
 
local out = {}
 
for _, rec in ipairs(matches) do
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"
 
-- List mode: emit a raw H3 heading before each standalone card so TOC/anchors work.
table.insert(out, string.format("=== %s ===", title))


local root = mw.html.create("div")
-- List mode cards are independent (no single wrapper container).
root:addClass("sv-skill-collection")
table.insert(out, buildInfobox(rec, { showUsers = false, inList = true }))
 
for _, rec in ipairs(matches) do
local item = root:tag("div"):addClass("sv-skill-item")
item:wikitext(buildInfobox(rec, { showUsers = false, inList = true }))
end
end


return tostring(root)
return table.concat(out, "\n")
end
end