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
m Protected "Module:GamePassives" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) [cascading]
No edit summary
Line 250: Line 250:
     local notesText = formatNotes(rec.Notes)
     local notesText = formatNotes(rec.Notes)
     addRow(root, "Notes", notesText)
     addRow(root, "Notes", notesText)
    return tostring(root)
end
local function passiveMatchesUser(rec, userName)
    if type(rec) ~= "table" or not userName or userName == "" then
        return false
    end
    local users = rec.Users
    if type(users) ~= "table" then
        return false
    end
    local userLower = mw.ustring.lower(userName)
    local function listHas(list)
        if type(list) ~= "table" then
            return false
        end
        for _, v in ipairs(list) do
            if type(v) == "string" and mw.ustring.lower(v) == userLower then
                return true
            end
        end
        return false
    end
    -- Adjust this if you *only* want Classes.
    if listHas(users.Classes)  then return true end
    if listHas(users.Summons)  then return true end
    if listHas(users.Monsters) then return true end
    if listHas(users.Events)  then return true end
    return false
end
function p.listForUser(frame)
    local args = getArgs(frame)
    -- Preferred 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)
     return tostring(root)
Line 281: Line 353:
     end
     end


    -- 3) If still no record, decide: list mode or unknown passive?
     if not rec then
     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 "?"
         local label = name or id or "?"
         return string.format(
         return string.format(
Line 290: Line 382:
     end
     end


    -- Normal single-passive behavior
     return buildInfobox(rec)
     return buildInfobox(rec)
end
end


return p
return p