Module:GameInfo: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 13: | Line 13: | ||
-- - This module is the stable entrypoint. Render logic lives in submodules. | -- - This module is the stable entrypoint. Render logic lives in submodules. | ||
-- - Submodules are expected to return a string of wikitext/HTML. | -- - Submodules are expected to return a string of wikitext/HTML. | ||
-- | |||
-- Compat: | |||
-- - Some call sites pass args via frame:getParent().args (template wrappers, routers). | |||
-- - Use _get_arg/_get_name to reliably read args either way. | |||
local p = {} | local p = {} | ||
| Line 53: | Line 57: | ||
:wikitext(tostring(msg)) | :wikitext(tostring(msg)) | ||
return tostring(div) | return tostring(div) | ||
end | |||
-- ----------------------------------------------------------------------------- | |||
-- COMPAT: args may live on frame.args OR frame:getParent().args | |||
-- ----------------------------------------------------------------------------- | |||
local function _get_arg(frame, key) | |||
local args = frame and frame.args or {} | |||
local v = _trim(args[key]) | |||
if v and v ~= "" then return v end | |||
local parent = frame and frame.getParent and frame:getParent() or nil | |||
local pargs = parent and parent.args or {} | |||
v = _trim(pargs[key]) | |||
if v and v ~= "" then return v end | |||
return nil | |||
end | |||
local function _get_name(frame) | |||
-- Supports |name=, |category=, or positional |1=. | |||
local v = _get_arg(frame, "name") | |||
if v and v ~= "" then return v end | |||
v = _get_arg(frame, "category") | |||
if v and v ~= "" then return v end | |||
local args = frame and frame.args or {} | |||
local p1 = _trim(args[1]) | |||
if p1 and p1 ~= "" then return p1 end | |||
local parent = frame and frame.getParent and frame:getParent() or nil | |||
local pargs = parent and parent.args or {} | |||
p1 = _trim(pargs[1]) | |||
if p1 and p1 ~= "" then return p1 end | |||
return nil | |||
end | end | ||
| Line 127: | Line 167: | ||
if type(mod.render) == "function" then return mod.render end | if type(mod.render) == "function" then return mod.render end | ||
if type(mod.Skills) == "function" then return mod.Skills end | if type(mod.Skills) == "function" then return mod.Skills end | ||
if type(mod.Category) == "function" then return mod.Category end | |||
return nil | return nil | ||
end | end | ||
| Line 162: | Line 203: | ||
function p.Category(frame) | function p.Category(frame) | ||
frame = frame or mw.getCurrentFrame() | frame = frame or mw.getCurrentFrame() | ||
local name = | local name = _get_name(frame) | ||
if not name or name == "" then | if not name or name == "" then | ||
return _error_box("GameInfo.Category: missing |name=CategoryName") | return _error_box("GameInfo.Category: missing |name=CategoryName") | ||
end | end | ||
-- First: known route table. | -- First: known route table (exact match). | ||
local module_title = ROUTES[name] | local module_title = ROUTES[name] | ||
| Line 187: | Line 227: | ||
-- Allow letters, numbers, spaces, underscores, hyphens, and slashes. | -- Allow letters, numbers, spaces, underscores, hyphens, and slashes. | ||
-- (Spaces are fine in page titles; MediaWiki normalizes.) | -- (Spaces are fine in page titles; MediaWiki normalizes.) | ||
if not name:match("^[%w %_%-/]+$") then | if not tostring(name):match("^[%w %_%-/]+$") then | ||
return _error_box("GameInfo.Category: invalid name=" .. tostring(name)) | return _error_box("GameInfo.Category: invalid name=" .. tostring(name)) | ||
end | end | ||
module_title = "Module:GameInfo/" .. name | module_title = "Module:GameInfo/" .. tostring(name) | ||
end | end | ||
| Line 200: | Line 240: | ||
function p.skeleton(frame) | function p.skeleton(frame) | ||
frame = frame or mw.getCurrentFrame() | frame = frame or mw.getCurrentFrame() | ||
local id = | local id = _get_arg(frame, "id") or "sv-gi-skeleton-1" | ||
local level = | local level = _get_arg(frame, "level") or _get_arg(frame, "data_level") or 1 | ||
local max_level = | local max_level = _get_arg(frame, "max") or _get_arg(frame, "max_level") or 10 | ||
local variant = _get_arg(frame, "variant") | |||
local top = mw.html.create("div"):wikitext("GameInfo Top (locked container)") | local top = mw.html.create("div"):wikitext("GameInfo Top (locked container)") | ||
| Line 213: | Line 253: | ||
level = level, | level = level, | ||
max_level = max_level, | max_level = max_level, | ||
variant = | variant = variant, | ||
top = tostring(top), | top = tostring(top), | ||
bottom = tostring(bottom), | bottom = tostring(bottom), | ||