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:GamePassives: Difference between revisions

From SpiritVale Wiki
No edit summary
No edit summary
Line 333: Line 333:
     root:addClass("wikitable spiritvale-passive-infobox")
     root:addClass("wikitable spiritvale-passive-infobox")


     -- Header: icon + name
     -- ==========================================================
    -- Top "hero" row: icon + name (left), description (right)
    -- ==========================================================
     local icon  = rec.Icon
     local icon  = rec.Icon
     local title = rec.Name or rec["Internal Name"] or "Unknown Passive"
     local title = rec.Name or rec["Internal Name"] or "Unknown Passive"
    local desc  = rec.Description or ""


     local header = root:tag("tr")
     local headerRow = root:tag("tr")
     local headerCell = header:tag("th")
    headerRow:addClass("spiritvale-infobox-main")
     headerCell:attr("colspan", 2)
 
    -- Left cell: icon + name
     local leftCell = headerRow:tag("th")
     leftCell:addClass("spiritvale-infobox-main-left")
 
    local leftInner = leftCell:tag("div")
    leftInner:addClass("spiritvale-infobox-main-left-inner")


    local titleText = ""
     if icon and icon ~= "" then
     if icon and icon ~= "" then
         titleText = string.format("[[File:%s|64px|link=]] ", icon)
         leftInner:wikitext(string.format("[[File:%s|80px|link=]]", icon))
    end
 
    leftInner:tag("div")
        :addClass("spiritvale-infobox-title")
        :wikitext(title)
 
    -- Right cell: italic description
    local rightCell = headerRow:tag("td")
    rightCell:addClass("spiritvale-infobox-main-right")
 
    local rightInner = rightCell:tag("div")
    rightInner:addClass("spiritvale-infobox-main-right-inner")
 
    if desc ~= "" then
        rightInner:tag("div")
            :addClass("spiritvale-infobox-description")
            :wikitext(string.format("''%s''", desc))
     end
     end
    titleText = titleText .. title
    headerCell:wikitext(titleText)


     ------------------------------------------------------------------
     ------------------------------------------------------------------
Line 352: Line 375:
     ------------------------------------------------------------------
     ------------------------------------------------------------------
     addSectionHeader(root, "General")
     addSectionHeader(root, "General")
     addRow(root, "Description", rec.Description)
 
     -- Description is now in the hero row; don't repeat it here.
    -- addRow(root, "Description", rec.Description)
 
     addRow(root, "Max level", rec["Max Level"] and tostring(rec["Max Level"]))
     addRow(root, "Max level", rec["Max Level"] and tostring(rec["Max Level"]))


Line 437: Line 463:
     return tostring(root)
     return tostring(root)
end
end
----------------------------------------------------------------------
-- Public: list all passives for a given user/class
----------------------------------------------------------------------
function p.listForUser(frame)
    local args = getArgs(frame)
    -- Prefer explicit param, then unnamed, then fall back to the current page name.
    local userName = args.user or args[1]
    if not userName or userName == "" then
        userName = mw.title.getCurrentTitle().text
    end
    if not userName or userName == "" then
        return "<strong>No user name provided to Passive list.</strong>"
    end
    local dataset = getPassives()
    local matches = {}
    for _, rec in ipairs(dataset.records or {}) do
        if passiveMatchesUser(rec, userName) then
            table.insert(matches, rec)
        end
    end
    if #matches == 0 then
        return string.format(
            "<strong>No passives found for:</strong> %s",
            mw.text.nowiki(userName)
        )
    end
    local root = mw.html.create("div")
    root:addClass("spiritvale-passive-list")
    for _, rec in ipairs(matches) do
        root:wikitext(buildInfobox(rec))
    end
    return tostring(root)
end
----------------------------------------------------------------------
-- Public: single-passive or auto-list dispatcher
----------------------------------------------------------------------
function p.infobox(frame)
    local args = getArgs(frame)
    -- Allow:
    --  {{Passive|Honed Blade}}          -> args[1] = "Honed Blade" (Name)
    --  {{Passive|name=Honed Blade}}      -> args.name
    --  {{Passive|id=CritMastery}}        -> args.id (Internal Name)
    local raw1 = args[1]
    local name = args.name or raw1
    local id  = args.id
    local rec
    -- 1) Prefer display Name
    if name and name ~= "" then
        rec = findPassiveByName(name)
    end
    -- 2) Fallback: internal ID
    if not rec and id and id ~= "" then
        rec = getPassiveById(id)
    end
    -- 3) If still nothing, decide if this is "list mode" or truly unknown.
    if not rec then
        local pageTitle = mw.title.getCurrentTitle()
        local pageName  = pageTitle and pageTitle.text or ""
        local noExplicitArgs =
            (not raw1 or raw1 == "") and
            (not args.name or args.name == "") and
            (not id or id == "")
        -- Case A: {{Passive}} with no parameters on a page → list for that page name.
        if noExplicitArgs then
            return p.listForUser(frame)
        end
        -- Case B: {{Passive|Acolyte}} on the "Acolyte" page and no id → treat as list.
        if name and name ~= "" and name == pageName and (not id or id == "") then
            return p.listForUser(frame)
        end
        -- Otherwise, genuinely unknown passive.
        local label = name or id or "?"
        return string.format(
            "<strong>Unknown passive:</strong> %s[[Category:Pages with unknown passive|%s]]",
            mw.text.nowiki(label),
            label
        )
    end
    -- Normal single-passive behavior
    return buildInfobox(rec)
end
return p