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
Line 541: Line 541:
     addSectionHeader(root, "General")
     addSectionHeader(root, "General")


     -- Description is now in the hero row; don't repeat it here.
     -- Description now lives in the hero row.
     -- addRow(root, "Description", rec.Description)
     -- addRow(root, "Description", rec.Description)


Line 698: Line 698:


     return tostring(root)
     return tostring(root)
end
----------------------------------------------------------------------
-- Public: list all skills 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 Skill list.</strong>"
    end
    local dataset = getSkills()
    local matches = {}
    for _, rec in ipairs(dataset.records or {}) do
        if skillMatchesUser(rec, userName) then
            table.insert(matches, rec)
        end
    end
    if #matches == 0 then
        return string.format(
            "<strong>No skills found for:</strong> %s",
            mw.text.nowiki(userName)
        )
    end
    local root = mw.html.create("div")
    root:addClass("spiritvale-skill-list")
    for _, rec in ipairs(matches) do
        root:wikitext(buildInfobox(rec))
    end
    return tostring(root)
end
----------------------------------------------------------------------
-- Public: single-skill or auto-list dispatcher
----------------------------------------------------------------------
function p.infobox(frame)
    local args = getArgs(frame)
    -- Allow three styles:
    --  {{Skill|Bash}}              -> args[1] = "Bash"  (Name)
    --  {{Skill|name=Bash}}        -> args.name = "Bash"
    --  {{Skill|id=Bash_Internal}}  -> args.id = "Bash_Internal"
    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 = findSkillByName(name)
    end
    -- 2) Fallback: internal ID
    if not rec and id and id ~= "" then
        rec = getSkillById(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: {{Skill}} with no parameters on a page → list for that page name.
        if noExplicitArgs then
            return p.listForUser(frame)
        end
        -- Case B: {{Skill|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 skill.
        local label = name or id or "?"
        return string.format(
            "<strong>Unknown skill:</strong> %s[[Category:Pages with unknown skill|%s]]",
            mw.text.nowiki(label),
            label
        )
    end
    -- Normal single-skill behavior
    return buildInfobox(rec)
end
end


return p
return p