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
 
(12 intermediate revisions by the same user not shown)
Line 4: Line 4:
--
--
-- Layout:
-- Layout:
--  1) hero-title-bar        (TOP BAR, 2 slots: herobar 1..2)
--  Row 1: Slot 1 + Slot 2 (Icon + SkillType)
--  2) hero-description-bar  (description strip)
--  Row 2: Slot 3 + Slot 4 (Description + Placeholder)
--  3) hero-modules row      (4 slots: hero-module-1..4)
--   Row 3: Slot 5 + Slot 6 (SourceType + QuickStats)
--  Row 4: Slot 7 + Slot 8 (SpecialMechanics + LevelSelector)
--
--
-- Requires Common.js:
-- Requires Common.js:
Line 22: Line 23:


local skillsCache
local skillsCache
local eventsCache


-- getSkills: lazy-load + cache skill dataset from GameData.
-- getSkills: lazy-load + cache skill dataset from GameData.
local function getSkills()
local function getSkills()
if not skillsCache then
        if not skillsCache then
skillsCache = GameData.loadSkills()
                skillsCache = GameData.loadSkills()
end
        end
return skillsCache
        return skillsCache
end
 
local function getEvents()
        if eventsCache == nil then
                if type(GameData.loadEvents) == "function" then
                        eventsCache = GameData.loadEvents()
                else
                        eventsCache = false
                end
        end
 
        return eventsCache
end
end


Line 92: Line 106:
-- listToText: join an array into a readable string.
-- 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
return nil
                return nil
end
        end
return table.concat(list, sep or ", ")
        return table.concat(list, sep or ", ")
end
 
local function resolveDisplayName(v, kind)
        if v == nil then return nil end
 
        local function firstString(keys, source)
                for _, key in ipairs(keys) do
                        local candidate = source[key]
                        if type(candidate) == "string" and candidate ~= "" then
                                return candidate
                        end
                end
                return nil
        end
 
        if type(v) == "table" then
                local primaryKeys = { "External Name", "Display Name", "Name" }
                local extendedKeys = { "Skill External Name", "Status External Name" }
                local internalKeys = { "Internal Name", "Internal ID", "ID", "InternalID", "Skill Internal Name", "InternalID" }
 
                return firstString(primaryKeys, v)
                        or firstString(extendedKeys, v)
                        or firstString(internalKeys, v)
        end
 
        if type(v) == "string" then
                if kind == "event" then
                        local events = getEvents()
                        if events and events.byId and events.byId[v] then
                                local mapped = resolveDisplayName(events.byId[v], "event")
                                if mapped then
                                        return mapped
                                end
                        end
                end
 
                return v
        end
 
        return tostring(v)
end
 
local function resolveEventName(v)
        local resolved = resolveDisplayName(v, "event")
        if type(resolved) == "string" then
                return resolved
        end
        return (resolved ~= nil) and tostring(resolved) or nil
end
 
local function resolveSkillNameFromEvent(ev)
        if type(ev) ~= "table" then
                return resolveDisplayName(ev, "skill") or "Unknown skill"
        end
 
        local displayKeys = {
                "Skill External Name",
                "External Name",
                "Display Name",
                "Name",
                "Skill Name",
        }
 
        for _, key in ipairs(displayKeys) do
                local candidate = resolveDisplayName(ev[key], "skill")
                if candidate then
                        return candidate
                end
        end
 
        local internalKeys = {
                "Skill Internal Name",
                "Skill ID",
                "Internal Name",
                "Internal ID",
                "ID",
        }
 
        for _, key in ipairs(internalKeys) do
                local candidate = ev[key]
                if type(candidate) == "string" and candidate ~= "" then
                        return candidate
                end
        end
 
        return "Unknown skill"
end
end


Line 475: Line 575:
----------------------------------------------------------------------
----------------------------------------------------------------------


local HERO_BAR_SLOT_ASSIGNMENT = {
local HERO_SLOT_ASSIGNMENT = {
[1] = "IconName",
[1] = "IconName",
[2] = "SkillType", -- Damage/Element/Hits/Target/Cast/Combo strip
[2] = "Description",
}
[3] = "LevelSelector",
 
[4] = "SkillType",
local HERO_MODULE_SLOT_ASSIGNMENT = {
[5] = "SourceType",
[1] = "SourceType",
[6] = "QuickStats",
[2] = "QuickStats",
[7] = "SpecialMechanics",
[3] = "SpecialMechanics",
[8] = "Placeholder",
[4] = "LevelSelector",
}
}


Line 491: Line 590:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- heroBarBox: wrapper for hero-bar slot modules.
-- slotBox: standardized wrapper for all hero card slots.
local function heroBarBox(slot, extraClasses, innerHtml, isEmpty)
local function slotBox(slot, extraClasses, innerHtml, opts)
opts = opts or {}
 
local box = mw.html.create("div")
local box = mw.html.create("div")
box:addClass("hero-bar-module")
box:addClass("sv-slot")
box:addClass("hero-bar-module-" .. tostring(slot))
box:addClass("sv-slot--" .. tostring(slot))
box:attr("data-hero-bar-module", tostring(slot))
box:attr("data-hero-slot", tostring(slot))


if slot == 2 then
if opts.isFull then
box:addClass("sv-herobar-compact")
box:addClass("sv-slot--full")
end
end


Line 510: Line 611:
end
end


if isEmpty then
if opts.isEmpty then
box:addClass("hero-bar-module-empty")
box:addClass("sv-slot--empty")
end
end


local body = box:tag("div"):addClass("hero-bar-module-body")
local body = box:tag("div"):addClass("sv-slot__body")
if innerHtml and innerHtml ~= "" then
if innerHtml and innerHtml ~= "" then
body:wikitext(innerHtml)
body:wikitext(innerHtml)
Line 522: Line 623:
end
end


-- moduleBox: wrapper for hero-module (2x2 grid) slot modules.
----------------------------------------------------------------------
local function moduleBox(slot, extraClasses, innerHtml, isEmpty)
local box = mw.html.create("div")
box:addClass("hero-module")
box:addClass("hero-module-" .. tostring(slot))
box:attr("data-hero-module", tostring(slot))
 
if extraClasses then
if type(extraClasses) == "string" then
box:addClass(extraClasses)
elseif type(extraClasses) == "table" then
for _, c in ipairs(extraClasses) do box:addClass(c) end
end
end
 
if isEmpty then
box:addClass("hero-module-empty")
end
 
local body = box:tag("div"):addClass("hero-module-body")
if innerHtml and innerHtml ~= "" then
body:wikitext(innerHtml)
end
 
return tostring(box)
end
 
----------------------------------------------------------------------
-- Shared helpers (Source + QuickStats + SpecialMechanics)
-- Shared helpers (Source + QuickStats + SpecialMechanics)
----------------------------------------------------------------------
----------------------------------------------------------------------
Line 901: Line 975:
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"


local wrap = mw.html.create("div")
local notesList = {}
wrap:addClass("sv-herobar-1-wrap")
if type(rec.Notes) == "table" then
 
for _, note in ipairs(rec.Notes) do
if icon and icon ~= "" then
local n = trim(note)
wrap:tag("div")
if n then
:addClass("sv-herobar-icon")
table.insert(notesList, mw.text.nowiki(n))
:wikitext(string.format("[[File:%s|80px|link=]]", icon))
end
end
elseif type(rec.Notes) == "string" then
local n = trim(rec.Notes)
if n then
notesList = { mw.text.nowiki(n) }
end
end
end


wrap:tag("div")
local req = rec.Requirements or {}
:addClass("spiritvale-infobox-title")
local reqSkillsRaw = (type(req["Required Skills"]) == "table") and req["Required Skills"] or {}
:wikitext(title)
local reqWeaponsRaw = (type(req["Required Weapons"]) == "table") and req["Required Weapons"] or {}
local reqStancesRaw = (type(req["Required Stances"]) == "table") and req["Required Stances"] or {}


return {
local reqSkills = {}
inner = tostring(wrap),
for _, rs in ipairs(reqSkillsRaw) do
classes = "module-herobar-1",
if type(rs) == "table" then
}
local nameReq = rs["Skill External Name"] or rs["Skill Internal Name"] or "Unknown"
end
local lvlReq  = rs["Required Level"]
if lvlReq then
table.insert(reqSkills, string.format("%s (Lv.%s)", mw.text.nowiki(nameReq), mw.text.nowiki(tostring(lvlReq))))
else
table.insert(reqSkills, mw.text.nowiki(nameReq))
end
end
end
 
local reqWeapons = {}
for _, w in ipairs(reqWeaponsRaw) do
local wn = trim(w)
if wn then table.insert(reqWeapons, mw.text.nowiki(wn)) end
end


-- PLUGIN: SkillType (Hero Bar Slot 2) - 2 rows x 3 cells (desktop + mobile).
local reqStances = {}
-- Rules:
for _, s in ipairs(reqStancesRaw) do
--  - If skill is non-damaging, hide Damage/Element/Hits.
local sn = trim(s)
--  - If Hits is empty, hide Hits.
if sn then table.insert(reqStances, mw.text.nowiki(sn)) end
--  - If Combo is empty, hide Combo.
end
-- Ordering:
--  - Desktop: Damage, Element, Hits, Target, Cast, Combo
--  - Mobile:  Damage, Element, Target, Cast, Hits, Combo (CSS reorder)
function PLUGINS.SkillType(rec, ctx)
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 hasNotes = (#notesList > 0)
local maxLevel = ctx.maxLevel or 1
local hasReq = (#reqSkills > 0) or (#reqWeapons > 0) or (#reqStances > 0)


local hideDamageBundle = (ctx.nonDamaging == true)


-- valName: extract a display string from typical {Name/ID/Value} objects.
local wrap = mw.html.create("div")
-- NOTE: Includes number support so Hits=2 (number) doesn't get dropped.
wrap:addClass("sv-herobar-1-wrap")
local function valName(x)
wrap:addClass("sv-tip-scope")
if x == nil then return nil end
 
if type(x) == "table" then
local iconBox = wrap:tag("div")
if x.Name and x.Name ~= "" then return tostring(x.Name) end
iconBox:addClass("sv-herobar-icon")
if x.ID and x.ID ~= "" then return tostring(x.ID) end
 
if x.Value ~= nil then return tostring(x.Value) end
if icon and icon ~= "" then
end
iconBox:wikitext(string.format("[[File:%s|80px|link=]]", icon))
if type(x) == "number" then
return tostring(x)
end
if type(x) == "string" and x ~= "" then
return x
end
return nil
end
end


-- hitsDisplay: find + render Hits from multiple possible structured locations.
local textBox = wrap:tag("div")
local function hitsDisplay()
textBox:addClass("sv-herobar-text")
local effects = (type(mech.Effects) == "table") and mech.Effects or {}
 
local titleRow = textBox:tag("div")
titleRow:addClass("sv-herobar-title-row")


local h =
local titleBox = titleRow:tag("div")
typeBlock.Hits or typeBlock["Hits"] or typeBlock["Hit Count"] or typeBlock["Hits Count"] or
titleBox:addClass("spiritvale-infobox-title")
mech.Hits or mech["Hits"] or mech["Hit Count"] or mech["Hits Count"] or
titleBox:wikitext(title)
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
if hasNotes then
return nil
local notesBtn = mw.html.create("span")
end
notesBtn:addClass("sv-tip-btn sv-tip-btn--notes")
notesBtn:attr("role", "button")
notesBtn:attr("tabindex", "0")
notesBtn:attr("data-sv-tip", "notes")
notesBtn:attr("aria-label", "Notes")
notesBtn:attr("aria-expanded", "false")
notesBtn:tag("span"):addClass("sv-ico sv-ico--info"):attr("aria-hidden", "true"):wikitext("i")
titleRow:node(notesBtn)
end


-- ValuePair-style table (Base/Per Level) => dynamic series
if hasReq then
if type(h) == "table" then
local pillRow = wrap:tag("div")
if h.Base ~= nil or h["Per Level"] ~= nil or type(h["Per Level"]) == "table" then
pillRow:addClass("sv-pill-row")
return displayFromSeries(seriesFromValuePair(h, maxLevel), level)
pillRow:addClass("sv-pill-row--req")
end
local pill = pillRow:tag("span")
pill:addClass("sv-pill sv-pill--req sv-tip-btn")
pill:attr("role", "button")
pill:attr("tabindex", "0")
pill:attr("data-sv-tip", "req")
pill:attr("aria-label", "Requirements")
pill:attr("aria-expanded", "false")
pill:wikitext("Requirements")
end
 
if hasNotes then
local notesContent = wrap:tag("div")
notesContent:addClass("sv-tip-content")
notesContent:attr("data-sv-tip-content", "notes")
notesContent:tag("div"):addClass("sv-tip-title"):wikitext("Notes")
notesContent:tag("div"):wikitext(table.concat(notesList, "<br />"))
end


-- Unit block {Value, Unit}
if hasReq then
if h.Value ~= nil then
local reqContent = wrap:tag("div")
local t = formatUnitValue(h)
reqContent:addClass("sv-tip-content")
return t and mw.text.nowiki(t) or nil
reqContent:attr("data-sv-tip-content", "req")
end


-- Fallback name extraction
if #reqSkills > 0 then
local function valName(x)
local section = reqContent:tag("div")
if x == nil then return nil end
section:addClass("sv-tip-section")
if type(x) == "table" then
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Skills")
if x.Name and x.Name ~= "" then return tostring(x.Name) end
section:tag("div"):wikitext(table.concat(reqSkills, "<br />"))
if x.ID and x.ID ~= "" then return tostring(x.ID) end
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


local vn = valName(h)
if #reqWeapons > 0 then
if vn and not isNoneLike(vn) then
local section = reqContent:tag("div")
return mw.text.nowiki(vn)
section:addClass("sv-tip-section")
end
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Weapons")
section:tag("div"):wikitext(table.concat(reqWeapons, ", "))
end
end


-- Scalar number/string
if #reqStances > 0 then
if type(h) == "number" then
local section = reqContent:tag("div")
return mw.text.nowiki(fmtNum(h))
section:addClass("sv-tip-section")
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Stances")
section:tag("div"):wikitext(table.concat(reqStances, ", "))
end
end
if type(h) == "string" then
local t = trim(h)
return (t and not isNoneLike(t)) and mw.text.nowiki(t) or nil
end
return nil
end
end


-- comboDisplay: render Combo as a compact text block (Type (+ details)).
return {
local function comboDisplay()
inner = tostring(wrap),
local c = (type(mech.Combo) == "table") and mech.Combo or nil
classes = "module-icon-name",
if not c then return nil end
}
end


local typ = trim(c.Type)
-- PLUGIN: SkillType (Hero Bar Slot 2) - 2 rows x 3 cells (desktop + mobile).
if not typ or isNoneLike(typ) then
-- Rules:
return nil
--  - If skill is non-damaging, hide Damage/Element/Hits.
end
--  - 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)
local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local mech      = (type(rec.Mechanics) == "table") and rec.Mechanics or {}


local details = {}
local level    = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


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


local dur = formatUnitValue(c.Duration)
-- valName: extract a display string from typical {Name/ID/Value} objects.
if dur and not isZeroish(dur) then
-- NOTE: Includes number support so Hits=2 (number) doesn't get dropped.
table.insert(details, mw.text.nowiki(dur))
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
end
 
if type(x) == "number" then
if #details > 0 then
return tostring(x)
return mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")"
end
if type(x) == "string" and x ~= "" then
return x
end
end
return mw.text.nowiki(typ)
return nil
end
end


local grid = mw.html.create("div")
-- hitsDisplay: find + render Hits from multiple possible structured locations.
grid:addClass("sv-type-grid")
local function hitsDisplay()
grid:addClass("sv-compact-root")
local effects = (type(mech.Effects) == "table") and mech.Effects or {}


local added = false
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"]


-- addChunk: add one labeled value cell (key drives CSS ordering).
if h == nil or isNoneLike(h) then
local function addChunk(key, label, valueHtml)
return nil
if valueHtml == nil or valueHtml == "" then return end
end
added = true


local chunk = grid:tag("div")
-- ValuePair-style table (Base/Per Level) => dynamic series
:addClass("sv-type-chunk")
if type(h) == "table" then
:addClass("sv-type-" .. tostring(key))
if h.Base ~= nil or h["Per Level"] ~= nil or type(h["Per Level"]) == "table" then
:attr("data-type-key", tostring(key))
return displayFromSeries(seriesFromValuePair(h, maxLevel), level)
end


chunk:tag("div")
-- Unit block {Value, Unit}
:addClass("sv-type-label")
if h.Value ~= nil then
:wikitext(mw.text.nowiki(label))
local t = formatUnitValue(h)
return t and mw.text.nowiki(t) or nil
end


chunk:tag("div")
-- Fallback name extraction
:addClass("sv-type-value")
local function valName(x)
:wikitext(valueHtml)
if x == nil then return nil end
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


-- Damage + Element + Hits bundle (hidden when non-damaging)
local vn = valName(h)
if not hideDamageBundle then
if vn and not isNoneLike(vn) then
local dmg  = valName(typeBlock.Damage or typeBlock["Damage Type"])
return mw.text.nowiki(vn)
local ele  = valName(typeBlock.Element or typeBlock["Element Type"])
end
local hits = hitsDisplay()
end


if dmg and not isNoneLike(dmg) then
-- Scalar number/string
addChunk("damage", "Damage", mw.text.nowiki(dmg))
if type(h) == "number" then
return mw.text.nowiki(fmtNum(h))
end
end
if ele and not isNoneLike(ele) then
if type(h) == "string" then
addChunk("element", "Element", mw.text.nowiki(ele))
local t = trim(h)
end
return (t and not isNoneLike(t)) and mw.text.nowiki(t) or nil
if hits then
addChunk("hits", "Hits", hits)
end
end
return nil
end
end


-- Target + Cast
-- comboDisplay: render Combo as a compact text block (Type (+ details)).
local tgt = valName(typeBlock.Target or typeBlock["Target Type"])
local function comboDisplay()
local cst = valName(typeBlock.Cast  or typeBlock["Cast Type"])
local c = (type(mech.Combo) == "table") and mech.Combo or nil
if not c then return nil end


if tgt and not isNoneLike(tgt) then
local typ = trim(c.Type)
addChunk("target", "Target", mw.text.nowiki(tgt))
if not typ or isNoneLike(typ) then
end
return nil
if cst and not isNoneLike(cst) then
end
addChunk("cast", "Cast", mw.text.nowiki(cst))
end


-- Combo
local details = {}
local combo = comboDisplay()
if combo then
addChunk("combo", "Combo", combo)
end


return {
local pct = formatUnitValue(c.Percent)
inner = added and tostring(grid) or "",
if pct and not isZeroish(pct) then
classes = "module-skill-type",
table.insert(details, mw.text.nowiki(pct))
}
end
end


-- PLUGIN: SourceType (Hero Module Slot 1) - Modifier + Source + Scaling.
local dur = formatUnitValue(c.Duration)
function PLUGINS.SourceType(rec, ctx)
if dur and not isZeroish(dur) then
local level = ctx.level or 1
table.insert(details, mw.text.nowiki(dur))
local maxLevel = ctx.maxLevel or 1
end


local basisWord = nil
if #details > 0 then
local sourceKind = nil
return mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")"
local sourceVal  = nil
local scaling    = nil
 
-- sourceValueForLevel: dynamic formatting for structured Source blocks.
local function sourceValueForLevel(src)
if type(src) ~= "table" then
return nil
end
end
return mw.text.nowiki(typ)
end


local per = src["Per Level"]
local grid = mw.html.create("div")
if type(per) == "table" and #per > 0 then
grid:addClass("sv-type-grid")
if isFlatList(per) then
grid:addClass("sv-compact-root")
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 series = {}
local added = false
for _, v in ipairs(per) do
table.insert(series, formatUnitValue(v) or tostring(v))
end
return dynSpan(series, level)
end


return valuePairDynamicValueOnly(src, maxLevel, level)
-- addChunk: add one labeled value cell (key drives CSS ordering).
end
local function addChunk(key, label, valueHtml)
if valueHtml == nil or valueHtml == "" then return end
added = true


if type(rec.Source) == "table" then
local chunk = grid:tag("div")
local src = rec.Source
:addClass("sv-type-chunk")
local atkFlag  = (src["ATK-Based"] == true)
:addClass("sv-type-" .. tostring(key))
local matkFlag = (src["MATK-Based"] == true)
:attr("data-type-key", tostring(key))
basisWord = basisWordFromFlags(atkFlag, matkFlag)


sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
chunk:tag("div")
sourceVal  = sourceValueForLevel(src)
:addClass("sv-type-label")
scaling    = src.Scaling
:wikitext(mw.text.nowiki(label))
end


-- Fallback to legacy Damage lists if Source absent
chunk:tag("div")
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
:addClass("sv-type-value")
local dmg = rec.Damage
:wikitext(valueHtml)
scaling = scaling or dmg.Scaling
end


local main = dmg["Main Damage"]
-- Damage + Element + Hits bundle (hidden when non-damaging)
local refl = dmg["Reflect Damage"]
if not hideDamageBundle then
local flat = dmg["Flat Damage"]
local dmg  = valName(typeBlock.Damage or typeBlock["Damage Type"])
local ele  = valName(typeBlock.Element or typeBlock["Element Type"])
local hits = hitsDisplay()


if type(main) == "table" and #main > 0 then
if dmg and not isNoneLike(dmg) then
local pick = nil
addChunk("damage", "Damage", mw.text.nowiki(dmg))
for _, d in ipairs(main) do
end
if type(d) == "table" and d.Type ~= "Healing" then
if ele and not isNoneLike(ele) then
pick = d
addChunk("element", "Element", mw.text.nowiki(ele))
break
end
end
if hits then
end
addChunk("hits", "Hits", hits)
pick = pick or main[1]
end
end


if type(pick) == "table" then
-- Target + Cast
local atkFlag  = (pick["ATK-Based"] == true)
local tgt = valName(typeBlock.Target or typeBlock["Target Type"])
local matkFlag = (pick["MATK-Based"] == true)
local cst = valName(typeBlock.Cast  or typeBlock["Cast Type"])
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
if tgt and not isNoneLike(tgt) then
sourceVal  = legacyPercentAtLevel(pick, level)
addChunk("target", "Target", mw.text.nowiki(tgt))
end
end
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
if cst and not isNoneLike(cst) then
local pick = refl[1]
addChunk("cast", "Cast", mw.text.nowiki(cst))
local atkFlag  = (pick["ATK-Based"] == true)
end
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = "Reflect"
-- Combo
sourceVal  = legacyPercentAtLevel(pick, level)
local combo = comboDisplay()
elseif type(flat) == "table" and #flat > 0 and type(flat[1]) == "table" then
if combo then
local pick = flat[1]
addChunk("combo", "Combo", combo)
local atkFlag  = (pick["ATK-Based"] == true)
end
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = "Flat"
        return {
sourceVal  = legacyPercentAtLevel(pick, level)
                inner = added and tostring(grid) or "",
end
                classes = "module-skill-type",
end
        }
end


local scalingLines = formatScalingCompactLines(scaling)
-- PLUGIN: Description (Hero Slot 3) - primary description text.
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
function PLUGINS.Description(rec)
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)
        local desc = trim(rec.Description)
        if not desc then
                return nil
        end


if (not hasSource) and (not hasScaling) then
        local body = mw.html.create("div")
return nil
        body:addClass("sv-description")
end
        body:wikitext(string.format("''%s''", desc))


local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
        return {
                inner = tostring(body),
                classes = "module-description",
        }
end


local extra = { "skill-source-module" }
-- PLUGIN: Placeholder (Hero Slot 4) - reserved/blank.
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
function PLUGINS.Placeholder()
        return nil
end


if hasSource and (not hasScaling) then
table.insert(extra, "sv-only-source")
elseif hasScaling and (not hasSource) then
table.insert(extra, "sv-only-scaling")
end


local wrap = mw.html.create("div")
-- PLUGIN: SourceType (Hero Module Slot 1) - Modifier + Source + Scaling.
wrap:addClass("sv-source-grid")
function PLUGINS.SourceType(rec, ctx)
wrap:addClass("sv-compact-root")
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


if hasMod then
local basisWord = nil
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
local sourceKind = nil
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
local sourceVal  = nil
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
local scaling    = nil
end


if hasSource then
-- sourceValueForLevel: dynamic formatting for structured Source blocks.
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
local function sourceValueForLevel(src)
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
if type(src) ~= "table" then
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
return nil
end
end


if hasScaling then
local per = src["Per Level"]
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
if type(per) == "table" and #per > 0 then
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")
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 list = scalingCol:tag("div"):addClass("sv-scaling-list")
local series = {}
for _, line in ipairs(scalingLines) do
for _, v in ipairs(per) do
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
table.insert(series, formatUnitValue(v) or tostring(v))
end
return dynSpan(series, level)
end
end
return valuePairDynamicValueOnly(src, maxLevel, level)
end
end


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


-- PLUGIN: QuickStats (Hero Module Slot 2) - 3x2 grid (range/area/cost/cast/cd/duration).
sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
-- NOTE: Hits does NOT live here (it lives in SkillType).
sourceVal  = sourceValueForLevel(src)
function PLUGINS.QuickStats(rec, ctx)
scaling    = src.Scaling
local level = ctx.level or 1
end
local maxLevel = ctx.maxLevel or 1
local promo = ctx.promo


local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
-- Fallback to legacy Damage lists if Source absent
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}
local dmg = rec.Damage
scaling = scaling or dmg.Scaling


local function dash() return "" end
local main = dmg["Main Damage"]
local refl = dmg["Reflect Damage"]
local flat = dmg["Flat Damage"]


-- Range (0 => —)
if type(main) == "table" and #main > 0 then
local rangeVal = nil
local pick = nil
if mech.Range ~= nil and not isNoneLike(mech.Range) then
for _, d in ipairs(main) do
local n = toNum(mech.Range)
if type(d) == "table" and d.Type ~= "Healing" then
if n ~= nil then
pick = d
if n ~= 0 then
break
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
end
end
end
else
pick = pick or main[1]
local t = mw.text.trim(tostring(mech.Range))
if t ~= "" and not isNoneLike(t) then
rangeVal = mw.text.nowiki(t)
end
end
end


-- Area
if type(pick) == "table" then
local areaVal = formatAreaSize(mech.Area, maxLevel, level)
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


-- Timings
sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
sourceVal  = legacyPercentAtLevel(pick, level)
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
end
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"],  maxLevel), 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)


-- Promote status duration if needed
sourceKind = "Reflect"
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
sourceVal  = legacyPercentAtLevel(pick, level)
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
elseif type(flat) == "table" and #flat > 0 and type(flat[1]) == "table" then
end
local pick = flat[1]
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


-- Cost: MP + HP
sourceKind = "Flat"
local function labeledSeries(block, label)
sourceVal  = legacyPercentAtLevel(pick, level)
local s = seriesFromValuePair(block, maxLevel)
if not s then return nil 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
end
return any and s or nil
end
end


local mpS = labeledSeries(rc["Mana Cost"], "MP")
local scalingLines = formatScalingCompactLines(scaling)
local hpS = labeledSeries(rc["Health Cost"], "HP")
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)


local costSeries = {}
if (not hasSource) and (not hasScaling) then
for lv = 1, maxLevel do
return nil
local mp = mpS and mpS[lv] or "—"
local hp = hpS and hpS[lv] or "—"
 
if mp ~= "—" and hp ~= "—" then
costSeries[lv] = mp .. " + " .. hp
elseif mp ~= "—" then
costSeries[lv] = mp
elseif hp ~= "—" then
costSeries[lv] = hp
else
costSeries[lv] = "—"
end
end
end


local costVal = displayFromSeries(costSeries, level)
local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")


local grid = mw.html.create("div")
local extra = { "skill-source-module", "module-source-type" }
grid:addClass("sv-m4-grid")
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
grid:addClass("sv-compact-root")


local function addCell(label, val)
if hasSource and (not hasScaling) then
local cell = grid:tag("div"):addClass("sv-m4-cell")
table.insert(extra, "sv-only-source")
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
elseif hasScaling and (not hasSource) then
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
table.insert(extra, "sv-only-scaling")
end
end


addCell("Range",    rangeVal)
local wrap = mw.html.create("div")
addCell("Area",      areaVal)
wrap:addClass("sv-source-grid")
addCell("Cost",      costVal)
wrap:addClass("sv-compact-root")
addCell("Cast Time", castVal)
addCell("Cooldown",  cdVal)
addCell("Duration",  durVal)


return {
if hasMod then
inner = tostring(grid),
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
classes = "module-quick-stats",
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
}
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
end
end


-- PLUGIN: SpecialMechanics (Hero Module Slot 3)
if hasSource then
-- Shows:
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
--   - Flags (deduped)
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
--   - Special mechanics (mech.Effects)
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
-- NOTE: Combo lives in SkillType (Hero Bar Slot 2).
end
function PLUGINS.SpecialMechanics(rec, ctx)
 
if hasScaling then
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")
 
local list = scalingCol:tag("div"):addClass("sv-scaling-list")
for _, line in ipairs(scalingLines) do
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
end
end
 
return {
inner = tostring(wrap),
classes = extra,
}
end
 
-- PLUGIN: QuickStats (Hero Module Slot 2) - 3x2 grid (range/area/cost/cast/cd/duration).
-- NOTE: Hits does NOT live here (it lives in SkillType).
function PLUGINS.QuickStats(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 promo = ctx.promo


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 bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}


------------------------------------------------------------------
local function dash() return "" end
-- Hits guard (we want Hits ONLY in SkillType)
------------------------------------------------------------------
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


------------------------------------------------------------------
-- Range (0 => —)
-- Flags (flat, de-duped)
local rangeVal = nil
------------------------------------------------------------------
if mech.Range ~= nil and not isNoneLike(mech.Range) then
local flagSet = {}
local n = toNum(mech.Range)
 
if n ~= nil then
local denyFlags = {
if n ~= 0 then
["self centered"] = true,
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
["self-centred"] = true,
end
["bond"] = true,
else
["combo"] = true,
local t = mw.text.trim(tostring(mech.Range))
        ["hybrid"] = true,
if t ~= "" and not isNoneLike(t) then
rangeVal = mw.text.nowiki(t)
end
end
end


-- hits variants
-- Area
["hit"] = true,
local areaVal = formatAreaSize(mech.Area, maxLevel, level)
["hits"] = true,
["hit count"] = true,
["hits count"] = true,
["hitcount"] = true,
["hitscount"] = true,
}


local function allowFlag(name)
-- Timings
if not name then return false end
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
if k == "" then return false end
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"],  maxLevel), level)
if denyFlags[k] then return false end
 
return true
-- Promote status duration if needed
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
end
end


local function addFlags(sub)
-- Cost: MP + HP
if type(sub) ~= "table" then return end
local function labeledSeries(block, label)
for k, v in pairs(sub) do
local s = seriesFromValuePair(block, maxLevel)
if v and allowFlag(k) then
if not s then return nil end
flagSet[tostring(k)] = true
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
end
end
return any and s or nil
end
end


if mods then
local mpS = labeledSeries(rc["Mana Cost"], "MP")
addFlags(mods["Movement Modifiers"])
local hpS = labeledSeries(rc["Health Cost"], "HP")
addFlags(mods["Combat Modifiers"])
 
addFlags(mods["Special Modifiers"])
local costSeries = {}
for k, v in pairs(mods) do
for lv = 1, maxLevel do
if type(v) == "boolean" and v and allowFlag(k) then
local mp = mpS and mpS[lv] or "—"
flagSet[tostring(k)] = true
local hp = hpS and hpS[lv] or "—"
end
 
if mp ~= "—" and hp ~= "" then
costSeries[lv] = mp .. " + " .. hp
elseif mp ~= "—" then
costSeries[lv] = mp
elseif hp ~= "" then
costSeries[lv] = hp
else
costSeries[lv] = "—"
end
end
end
end


local flags = {}
local costVal = displayFromSeries(costSeries, level)
for k, _ in pairs(flagSet) do table.insert(flags, k) end
table.sort(flags)


------------------------------------------------------------------
local grid = mw.html.create("div")
-- Special mechanics (name => value)
grid:addClass("sv-m4-grid")
------------------------------------------------------------------
grid:addClass("sv-compact-root")
local mechItems = {}


if effects then
local function addCell(label, val)
local keys = {}
local cell = grid:tag("div"):addClass("sv-m4-cell")
for k, _ in pairs(effects) do table.insert(keys, k) end
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
table.sort(keys)
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
end


for _, name in ipairs(keys) do
addCell("Range",     rangeVal)
-- Skip Hits completely (it belongs in SkillType)
addCell("Area",      areaVal)
if not isHitsKey(name) then
addCell("Cost",      costVal)
local block = effects[name]
addCell("Cast Time", castVal)
if type(block) == "table" then
addCell("Cooldown",  cdVal)
-- Also skip if the block's Type is "Hits" (some data may encode it that way)
addCell("Duration", durVal)
if not isHitsKey(block.Type) then
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
local t = trim(block.Type)


local value = disp
return {
inner = tostring(grid),
classes = "module-quick-stats",
}
end
 
-- PLUGIN: SpecialMechanics (Hero Module Slot 3)
-- 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


-- If Type exists and is distinct, prefix it.
local mech    = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
local effects = (type(mech.Effects) == "table") and mech.Effects or nil
if value then
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil
value = mw.text.nowiki(t) .. ": " .. value
else
value = mw.text.nowiki(t)
end
end


if value then
------------------------------------------------------------------
table.insert(mechItems, { label = tostring(name), value = value })
-- Hits guard (we want Hits ONLY in SkillType)
end
------------------------------------------------------------------
end
local function isHitsKey(name)
end
if not name then return false end
end
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
end
return (
k == "hit" or
k == "hits" or
k == "hit count" or
k == "hits count" or
k == "hitcount" or
k == "hitscount"
)
end
end


local hasFlags = (#flags > 0)
------------------------------------------------------------------
local hasMech  = (#mechItems > 0)
-- Flags (flat, de-duped)
------------------------------------------------------------------
local flagSet = {}


if (not hasFlags) and (not hasMech) then
local denyFlags = {
local root = mw.html.create("div")
["self centered"] = true,
root:addClass("sv-sm-root")
["self-centred"] = true,
root:addClass("sv-compact-root")
["bond"] = true,
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")
["combo"] = true,
        ["hybrid"] = true,
 
-- hits variants
["hit"] = true,
["hits"] = true,
["hit count"] = true,
["hits count"] = true,
["hitcount"] = true,
["hitscount"] = true,
}


return {
local function allowFlag(name)
inner = tostring(root),
if not name then return false end
classes = "module-special-mechanics",
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
}
if k == "" then return false end
if denyFlags[k] then return false end
return true
end
end


local count = 0
local function addFlags(sub)
if hasFlags then count = count + 1 end
if type(sub) ~= "table" then return end
if hasMech  then count = count + 1 end
for k, v in pairs(sub) do
if v and allowFlag(k) then
flagSet[tostring(k)] = true
end
end
end


local root = mw.html.create("div")
if mods then
root:addClass("sv-sm-root")
addFlags(mods["Movement Modifiers"])
root:addClass("sv-compact-root")
addFlags(mods["Combat Modifiers"])
 
addFlags(mods["Special Modifiers"])
local layout = root:tag("div"):addClass("sv-sm-layout")
for k, v in pairs(mods) do
layout:addClass("sv-sm-count-" .. tostring(count))
if type(v) == "boolean" and v and allowFlag(k) then
 
flagSet[tostring(k)] = true
-- Column 1: Flags
end
if hasFlags then
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
for _, f in ipairs(flags) do
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
end
end
end
end


-- Column 2: Special Mechanics (stacked)
local flags = {}
if hasMech then
for k, _ in pairs(flagSet) do table.insert(flags, k) end
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech")
table.sort(flags)
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


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


-- PLUGIN: LevelSelector (Hero Module Slot 4) - JS level slider.
if effects then
function PLUGINS.LevelSelector(rec, ctx)
local keys = {}
local level = ctx.level or 1
for k, _ in pairs(effects) do table.insert(keys, k) end
local maxLevel = ctx.maxLevel or 1
table.sort(keys)


local inner = mw.html.create("div")
for _, name in ipairs(keys) do
inner:addClass("sv-level-ui")
-- Skip Hits completely (it belongs in SkillType)
if not isHitsKey(name) then
local block = effects[name]
if type(block) == "table" then
-- Also skip if the block's Type is "Hits" (some data may encode it that way)
if not isHitsKey(block.Type) then
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
local t = trim(block.Type)


inner:tag("div")
local value = disp
:addClass("sv-level-label")
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))


local slider = inner:tag("div"):addClass("sv-level-slider")
-- If Type exists and is distinct, prefix it.
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
if value then
value = mw.text.nowiki(t) .. ": " .. value
else
value = mw.text.nowiki(t)
end
end


if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
if value then
slider:tag("input")
table.insert(mechItems, { label = tostring(name), value = value })
:attr("type", "range")
end
:attr("min", "1")
end
:attr("max", tostring(maxLevel))
end
:attr("value", tostring(level))
end
:addClass("sv-level-range")
end
:attr("aria-label", "Skill level select")
else
inner:addClass("sv-level-ui-single")
slider:addClass("sv-level-slider-single")
end
end


return {
local hasFlags = (#flags > 0)
inner = tostring(inner),
local hasMech  = (#mechItems > 0)
classes = "module-level-selector",
}
end


----------------------------------------------------------------------
if (not hasFlags) and (not hasMech) then
-- Generic slot renderers
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")


-- normalizeResult: normalize plugin return values into {inner, classes}.
return {
local function normalizeResult(res)
inner = tostring(root),
if res == nil then return nil end
classes = "module-special-mechanics",
if type(res) == "string" then
}
return { inner = res, classes = nil }
end
end
if type(res) == "table" then
local inner = res.inner
if type(inner) ~= "string" then
inner = (inner ~= nil) and tostring(inner) or ""
end
return { inner = inner, classes = res.classes }
end
return { inner = tostring(res), classes = nil }
end


-- safeCallPlugin: pcall wrapper to prevent infobox failure on plugin errors.
local count = 0
local function safeCallPlugin(name, rec, ctx)
if hasFlags then count = count + 1 end
local fn = PLUGINS[name]
if hasMech  then count = count + 1 end
if type(fn) ~= "function" then
return nil
end
local ok, out = pcall(fn, rec, ctx)
if not ok then
return nil
end
return normalizeResult(out)
end


-- renderHeroBarSlot: render a hero-bar slot by plugin assignment.
local root = mw.html.create("div")
local function renderHeroBarSlot(slotIndex, rec, ctx)
root:addClass("sv-sm-root")
local pluginName = HERO_BAR_SLOT_ASSIGNMENT[slotIndex]
root:addClass("sv-compact-root")
if not pluginName then
return heroBarBox(slotIndex, nil, "", true)
end


local res = safeCallPlugin(pluginName, rec, ctx)
local layout = root:tag("div"):addClass("sv-sm-layout")
if not res or not res.inner or res.inner == "" then
layout:addClass("sv-sm-count-" .. tostring(count))
return heroBarBox(slotIndex, nil, "", true)
end


return heroBarBox(slotIndex, res.classes, res.inner, false)
-- Column 1: Flags
end
if hasFlags then
 
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
-- renderModuleSlot: render a hero-module slot by plugin assignment.
for _, f in ipairs(flags) do
local function renderModuleSlot(slotIndex, rec, ctx)
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
local pluginName = HERO_MODULE_SLOT_ASSIGNMENT[slotIndex]
end
if not pluginName then
return moduleBox(slotIndex, nil, "", true)
end
end


local res = safeCallPlugin(pluginName, rec, ctx)
-- Column 2: Special Mechanics (stacked)
if not res or not res.inner or res.inner == "" then
if hasMech then
return moduleBox(slotIndex, nil, "", true)
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
end


return moduleBox(slotIndex, res.classes, res.inner, false)
return {
inner = tostring(root),
classes = "module-special-mechanics",
}
end
end


----------------------------------------------------------------------
-- PLUGIN: LevelSelector (Hero Module Slot 4) - JS level slider.
-- UI builders
function PLUGINS.LevelSelector(rec, ctx)
----------------------------------------------------------------------
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1
 
local inner = mw.html.create("div")
inner:addClass("sv-level-ui")


-- buildHeroBarUI: build the top hero bar (2 slots).
inner:tag("div")
local function buildHeroBarUI(rec, ctx)
:addClass("sv-level-label")
local bar = mw.html.create("div")
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))
bar:addClass("hero-bar-grid")
bar:wikitext(renderHeroBarSlot(1, rec, ctx))
bar:wikitext(renderHeroBarSlot(2, rec, ctx))
return tostring(bar)
end


-- buildHeroModulesUI: build the 2x2 module grid row (4 slots).
local slider = inner:tag("div"):addClass("sv-level-slider")
local function buildHeroModulesUI(rec, ctx)
local grid = mw.html.create("div")
grid:addClass("hero-modules-grid")
for slot = 1, 4 do
grid:wikitext(renderModuleSlot(slot, rec, ctx))
end
return tostring(grid)
end


-- addHeroModulesRow: add the hero-modules row into the infobox table.
if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
local function addHeroModulesRow(tbl, modulesUI)
slider:tag("input")
if not modulesUI or modulesUI == "" then
:attr("type", "range")
return
: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


local row = tbl:tag("tr")
return {
row:addClass("hero-modules-row")
inner = tostring(inner),
 
classes = "module-level-selector",
local cell = row:tag("td")
}
cell:attr("colspan", 2)
cell:addClass("hero-modules-cell")
cell:wikitext(modulesUI)
end
end


----------------------------------------------------------------------
----------------------------------------------------------------------
-- Infobox builder
-- Generic slot renderers
----------------------------------------------------------------------
----------------------------------------------------------------------


-- buildInfobox: render a single skill infobox.
-- normalizeResult: normalize plugin return values into {inner, classes}.
local function buildInfobox(rec, opts)
local function normalizeResult(res)
opts = opts or {}
if res == nil then return nil end
local showUsers = (opts.showUsers ~= false)
if type(res) == "string" then
return { inner = res, classes = nil }
end
if type(res) == "table" then
local inner = res.inner
if type(inner) ~= "string" then
inner = (inner ~= nil) and tostring(inner) or ""
end
return { inner = inner, classes = res.classes }
end
return { inner = tostring(res), classes = nil }
end
 
-- safeCallPlugin: pcall wrapper to prevent infobox failure on plugin errors.
local function safeCallPlugin(name, rec, ctx)
        local fn = PLUGINS[name]
        if type(fn) ~= "function" then
                return nil
        end
        local ok, out = pcall(fn, rec, ctx)
        if not ok then
                return nil
        end
        return normalizeResult(out)
end


local maxLevel = tonumber(rec["Max Level"]) or 1
-- isEmptySlotContent: true when a slot has no meaningful content.
if maxLevel < 1 then maxLevel = 1 end
-- NOTE: JS placeholders (sv-dyn spans, slider markup) are considered content.
local level = clamp(maxLevel, 1, maxLevel)
local function isEmptySlotContent(inner)
        if inner == nil then return true end


local ctx = {
        local raw = tostring(inner)
maxLevel = maxLevel,
 
level = level,
        -- Guard rails for JS-injected regions.
nonDamaging = false,
        for _, pat in ipairs({ "sv%-dyn", "data%-series", "sv%-level%-range", "sv%-level%-slider", "sv%-level%-ui" }) do
promo = nil,
                if mw.ustring.find(raw, pat) then
}
                        return false
                end
        end


-- Non-damaging hides Damage/Element/Hits in SkillType
        local trimmed = mw.text.trim(raw)
do
        if trimmed == "" or trimmed == "" then
local dmgVal = nil
                return true
if type(rec.Type) == "table" then
        end
dmgVal = rec.Type.Damage or rec.Type["Damage Type"]
if type(dmgVal) == "table" then
dmgVal = dmgVal.Name or dmgVal.ID or dmgVal.Value
end
end
ctx.nonDamaging = isNoneLike(dmgVal) or (not skillHasAnyDamage(rec, maxLevel))
end


ctx.promo = computeDurationPromotion(rec, maxLevel)
        local withoutTags = mw.text.trim(mw.ustring.gsub(trimmed, "<[^>]+>", ""))
        return (withoutTags == "" or withoutTags == "—")
end


local root = mw.html.create("table")
-- renderHeroSlot: render a standardized hero slot by plugin assignment.
root:addClass("spiritvale-skill-infobox")
local function renderHeroSlot(slotIndex, rec, ctx)
root:addClass("sv-skill-card")
        local pluginName = HERO_SLOT_ASSIGNMENT[slotIndex]
root:attr("data-max-level", tostring(maxLevel))
        if not pluginName then
root:attr("data-level", tostring(level))
                return nil
        end


if opts.inList then
        local res = safeCallPlugin(pluginName, rec, ctx)
root:addClass("sv-skill-inlist")
        if not res or isEmptySlotContent(res.inner) then
end
                return nil
        end


local internalId = trim(rec["Internal Name"] or rec.InternalID or rec.ID)
        return {
if internalId then
                inner = res.inner,
root:attr("data-skill-id", internalId)
                classes = res.classes,
end
        }
end


local desc  = rec.Description or ""
----------------------------------------------------------------------
-- UI builders
----------------------------------------------------------------------


-- Hero Title Bar
-- buildHeroSlotsUI: build the standardized 4-row slot grid (2 columns).
local heroRow = root:tag("tr")
local function buildHeroSlotsUI(rec, ctx)
heroRow:addClass("spiritvale-infobox-main")
        local grid = mw.html.create("div")
heroRow:addClass("sv-hero-title-row")
        grid:addClass("sv-slot-grid")
heroRow:addClass("hero-title-bar")


local heroCell = heroRow:tag("th")
        local slots = {}
heroCell:attr("colspan", 2)
        for slot = 1, 8 do
heroCell:addClass("sv-hero-title-cell")
                slots[slot] = renderHeroSlot(slot, rec, ctx)
heroCell:wikitext(buildHeroBarUI(rec, ctx))
        end


-- Description Bar
        local hasSlots = false
if desc ~= "" then
        for _, pair in ipairs({ { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }) do
local descRow = root:tag("tr")
                local left  = slots[pair[1]]
descRow:addClass("spiritvale-infobox-main")
                local right = slots[pair[2]]
descRow:addClass("sv-hero-desc-row")
descRow:addClass("hero-description-bar")


local descCell = descRow:tag("td")
                if left or right then
descCell:attr("colspan", 2)
                        hasSlots = true
descCell:addClass("sv-hero-desc-cell")


local descInner = descCell:tag("div")
                        if left and right then
descInner:addClass("spiritvale-infobox-main-right-inner")
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isEmpty = false }))
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isEmpty = false }))
                        elseif left then
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isFull = true }))
                        elseif right then
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isFull = true }))
                        end
                end
        end


descInner:tag("div")
        if not hasSlots then
:addClass("spiritvale-infobox-description")
                return ""
:wikitext(string.format("''%s''", desc))
        end
end


-- Modules row
        return tostring(grid)
addHeroModulesRow(root, buildHeroModulesUI(rec, ctx))
end


-- Users (hide on direct skill page)
-- addHeroSlotsRow: add the standardized slot grid into the infobox table.
if showUsers then
local function addHeroSlotsRow(tbl, slotsUI)
local users = rec.Users or {}
        if not slotsUI or slotsUI == "" then
addRow(root, "Classes",  listToText(users.Classes),  "sv-row-users", "Users.Classes")
                return
addRow(root, "Summons",  listToText(users.Summons),  "sv-row-users", "Users.Summons")
        end
addRow(root, "Monsters", listToText(users.Monsters), "sv-row-users", "Users.Monsters")
addRow(root, "Events",  listToText(users.Events),  "sv-row-users", "Users.Events")
end


-- Requirements
        local row = tbl:tag("tr")
local req = rec.Requirements or {}
        row:addClass("sv-slot-row")
local hasReq =
(type(req["Required Skills"]) == "table" and #req["Required Skills"] > 0) or
(type(req["Required Weapons"]) == "table" and #req["Required Weapons"] > 0) or
(type(req["Required Stances"]) == "table" and #req["Required Stances"] > 0)


if hasReq then
        local cell = row:tag("td")
if type(req["Required Skills"]) == "table" and #req["Required Skills"] > 0 then
        cell:attr("colspan", 2)
local skillParts = {}
        cell:addClass("sv-slot-cell")
for _, rs in ipairs(req["Required Skills"]) do
        cell:wikitext(slotsUI)
local nameReq = rs["Skill External Name"] or rs["Skill Internal Name"] or "Unknown"
end
local lvlReq  = rs["Required Level"]
if lvlReq then
table.insert(skillParts, string.format("%s (Lv.%s)", nameReq, lvlReq))
else
table.insert(skillParts, nameReq)
end
end
addRow(root, "Required Skills", table.concat(skillParts, ", "), "sv-row-req", "Requirements.Required Skills")
end


addRow(root, "Required Weapons", listToText(req["Required Weapons"]), "sv-row-req", "Requirements.Required Weapons")
----------------------------------------------------------------------
addRow(root, "Required Stances", listToText(req["Required Stances"]), "sv-row-req", "Requirements.Required Stances")
-- Infobox builder
end
----------------------------------------------------------------------


-- Mechanics (keep small extras only)
-- buildInfobox: render a single skill infobox.
local mech = rec.Mechanics or {}
local function buildInfobox(rec, opts)
if next(mech) ~= nil then
opts = opts or {}
if mech["Autocast Multiplier"] ~= nil then
local showUsers = (opts.showUsers ~= false)
addRow(root, "Autocast Multiplier", tostring(mech["Autocast Multiplier"]), "sv-row-mech", "Mechanics.Autocast Multiplier")
 
end
local maxLevel = tonumber(rec["Max Level"]) or 1
end
if maxLevel < 1 then maxLevel = 1 end
local level = clamp(maxLevel, 1, maxLevel)
 
local ctx = {
maxLevel = maxLevel,
level = level,
nonDamaging = false,
promo = nil,
}
 
-- Non-damaging hides Damage/Element/Hits in SkillType
do
local dmgVal = nil
if type(rec.Type) == "table" then
dmgVal = rec.Type.Damage or rec.Type["Damage Type"]
if type(dmgVal) == "table" then
dmgVal = dmgVal.Name or dmgVal.ID or dmgVal.Value
end
end
ctx.nonDamaging = isNoneLike(dmgVal) or (not skillHasAnyDamage(rec, maxLevel))
end
 
ctx.promo = computeDurationPromotion(rec, maxLevel)
 
local root = mw.html.create("table")
root:addClass("spiritvale-skill-infobox")
root:addClass("sv-skill-card")
root:attr("data-max-level", tostring(maxLevel))
root:attr("data-level", tostring(level))
 
if opts.inList then
root:addClass("sv-skill-inlist")
end
 
local internalId = trim(rec["Internal Name"] or rec.InternalID or rec.ID)
if internalId then
root:attr("data-skill-id", internalId)
end
 
-- Standardized slot grid
addHeroSlotsRow(root, buildHeroSlotsUI(rec, ctx))
 
-- Users (hide on direct skill page)
        if showUsers then
                local users = rec.Users or {}
                addRow(root, "Classes",  listToText(users.Classes),  "sv-row-users", "Users.Classes")
                addRow(root, "Summons",  listToText(users.Summons),  "sv-row-users", "Users.Summons")
                addRow(root, "Monsters", listToText(users.Monsters), "sv-row-users", "Users.Monsters")
                do
                        local eventsList = {}
                        if type(users.Events) == "table" then
                                for _, ev in ipairs(users.Events) do
                                        local name = resolveEventName(ev) or ev
                                        if name ~= nil then
                                                table.insert(eventsList, mw.text.nowiki(tostring(name)))
                                        end
                                end
                        end
                        addRow(root, "Events", listToText(eventsList), "sv-row-users", "Users.Events")
                end
        end
 
        -- Mechanics (keep small extras only)
        local mech = rec.Mechanics or {}
        if next(mech) ~= nil then
                if mech["Autocast Multiplier"] ~= nil then
                        addRow(root, "Autocast Multiplier", tostring(mech["Autocast Multiplier"]), "sv-row-mech", "Mechanics.Autocast Multiplier")
                end
        end


-- Legacy damage breakdown (only when Source absent)
-- Legacy damage breakdown (only when Source absent)
Line 1,878: Line 2,074:
end
end


-- Events
        -- Events
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
local parts = {}
                local parts = {}
for _, ev in ipairs(list) do
                for _, ev in ipairs(list) do
if type(ev) == "table" then
                        if type(ev) == "table" then
local action = ev.Action or "On event"
                                local action = resolveDisplayName(ev.Action, "event") or ev.Action or "On event"
local name  = ev["Skill Internal Name"] or ev["Skill External Name"] or "Unknown skill"
                                local name  = resolveSkillNameFromEvent(ev)
table.insert(parts, string.format("%s → %s", action, name))
                                table.insert(parts, string.format("%s → %s", mw.text.nowiki(action), mw.text.nowiki(name)))
end
                        end
end
                end
return (#parts > 0) and table.concat(parts, "<br />") or nil
                return (#parts > 0) and table.concat(parts, "<br />") or nil
end
        end


local eventsText = formatEvents(rec.Events)
local eventsText = formatEvents(rec.Events)
Line 1,897: Line 2,093:
end
end


-- Notes
return tostring(root)
if type(rec.Notes) == "table" and #rec.Notes > 0 then
addRow(root, "Notes", table.concat(rec.Notes, "<br />"), "sv-row-meta", "Notes")
end
 
return tostring(root)
end
end


Line 1,934: Line 2,125:
end
end


local root = mw.html.create("div")
local out = {}
root:addClass("sv-skill-collection")


for _, rec in ipairs(matches) do
for _, rec in ipairs(matches) do
local item = root:tag("div"):addClass("sv-skill-item")
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"
item:wikitext(buildInfobox(rec, { showUsers = false, inList = true }))
 
-- List mode: emit a raw H3 heading before each standalone card so TOC/anchors work.
table.insert(out, string.format("=== %s ===", title))
 
-- List mode cards are independent (no single wrapper container).
table.insert(out, buildInfobox(rec, { showUsers = false, inList = true }))
end
end


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