Module:GameSkills: Difference between revisions
From SpiritVale Wiki
More actions
m Protected "Module:GameSkills" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) [cascading] |
No edit summary |
||
| Line 292: | Line 292: | ||
local statusApps = formatStatusApplications(rec["Status Applications"]) | local statusApps = formatStatusApplications(rec["Status Applications"]) | ||
addRow(root, "Status applications", statusApps) | addRow(root, "Status applications", statusApps) | ||
return tostring(root) | |||
end | |||
local function skillMatchesUser(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 want summons/monsters/events included too | |||
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 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 | |||
-- Container for all skill boxes | |||
local root = mw.html.create("div") | |||
root:addClass("spiritvale-skill-list") | |||
-- Optional heading; comment this out if you prefer to handle headings in wikitext | |||
-- root:tag("h3"):wikitext("Skills: " .. userName):done() | |||
for _, rec in ipairs(matches) do | |||
-- Reuse the existing infobox for each skill | |||
root:wikitext(buildInfobox(rec)) | |||
end | |||
return tostring(root) | return tostring(root) | ||
| Line 323: | Line 400: | ||
end | end | ||
-- 3) If we still don't have a record, decide whether this is: | |||
-- - a class/user page call (list mode), or | |||
-- - genuinely an unknown skill. | |||
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: called with *no* args at all – treat as "list skills for this page". | |||
-- e.g. {{Skill}} on the "Acolyte" page | |||
if noExplicitArgs then | |||
return p.listForUser(frame) | |||
end | |||
-- Case B: called with a name that matches the page name, and no ID: | |||
-- e.g. {{Skill|Acolyte}} on the "Acolyte" page | |||
if name and name ~= "" and name == pageName and (not id or id == "") then | |||
return p.listForUser(frame) | |||
end | |||
-- Otherwise, this really looks like "unknown skill". | |||
local label = name or id or "?" | local label = name or id or "?" | ||
return string.format( | return string.format( | ||
| Line 332: | Line 433: | ||
end | end | ||
-- Normal single-skill behavior | |||
return buildInfobox(rec) | return buildInfobox(rec) | ||
end | end | ||
return p | return p | ||