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

From SpiritVale Wiki
No edit summary
No edit summary
Tags: Mobile edit Mobile web edit
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:GameInfo
-- Phase 4.1 (Refactor): stable entrypoint + strict routing + shared scaffolding.
--
-- Contract (new, strict):
-- - Pages are generated/updated by SVWT + pywikibot (compiled artifacts).
-- - No legacy wrappers: read args from frame.args ONLY.
-- - Submodules are pure renderers:
--    return require("Module:GameInfo/Skills").render(frame)
--  Optional:
--    return require("Module:GameInfo/Skills").STYLE_SRC = "Module:GameInfo/skills.css"
--
-- Entry points:
--  {{#invoke:GameInfo|Skills|id=...|index=...|notes=...|data=...}}
--  {{#invoke:GameInfo|Category|name=Skills|...}}  -- allowlist only
local p = {}
local p = {}


-- Default TemplateStyles source (may be overridden by submodules via STYLE_SRC).
-- Sitewide color/system ownership now lives in Common.css + Citizen.css.
-- This module still loads its scoped TemplateStyles entrypoint, but that
-- stylesheet should defer to shared sitewide tokens/components whenever possible.
local DEFAULT_STYLE_SRC = "Module:GameInfo/styles.css"
local DEFAULT_STYLE_SRC = "Module:GameInfo/styles.css"


-- Allowlist routes (no dynamic require by user input).
local ROUTES = {
local ROUTES = {
Skills = "Module:GameInfo/Skills",
Skills = "Module:GameInfo/Skills",
-- Future:
-- Monsters = "Module:GameInfo/Monsters",
-- Equips  = "Module:GameInfo/Equips",
}
}
-- -----------------------------------------------------------------------------
-- Small utils
-- -----------------------------------------------------------------------------


local function _trim(v)
local function _trim(v)
Line 50: Line 29:
and type(x.tag) == "function"
and type(x.tag) == "function"
and type(x.wikitext) == "function"
and type(x.wikitext) == "function"
end
local function _append_content(node, value)
if value == nil then return end
if _is_html_node(value) then
node:node(value)
else
node:wikitext(tostring(value))
end
end
end


local function _error_box(msg)
local function _error_box(msg)
-- Keep obvious + wiki-friendly (TemplateStyles will still load).
return tostring(
return tostring(
mw.html.create("div")
mw.html.create("div")
:addClass("sv-card")
:addClass("sv-gi-error")
:addClass("sv-gi-error")
:wikitext(tostring(msg))
:wikitext(tostring(msg))
)
)
end
end
-- -----------------------------------------------------------------------------
-- Args (strict: frame.args only)
-- -----------------------------------------------------------------------------


function p.arg(frame, key, fallback)
function p.arg(frame, key, fallback)
Line 87: Line 71:
return fallback
return fallback
end
end
-- -----------------------------------------------------------------------------
-- TemplateStyles
-- -----------------------------------------------------------------------------


function p.styles(frame, src)
function p.styles(frame, src)
Line 98: Line 78:
end
end


-- -----------------------------------------------------------------------------
-- Shared container builder
-- -----------------------------------------------------------------------------
-- Canonical builder: returns { root=<div>, top=<div>, bottom=<div> }.
-- Submodules fill top/bottom and tostring(root).
function p.box(opts)
function p.box(opts)
opts = opts or {}
opts = opts or {}
Line 116: Line 90:


local root = mw.html.create("div")
local root = mw.html.create("div")
:addClass("sv-card")
:addClass("sv-gi-card")
:addClass("sv-gi-card")
:attr("data-gi", "1")
:attr("data-gi", "1")
:attr("data-sv-card", "1")
:attr("data-gi-phase", "4.1")
:attr("data-gi-phase", "4.1")
:attr("data-level", tostring(level))
:attr("data-level", tostring(level))
Line 128: Line 104:
if opts.variant and tostring(opts.variant) ~= "" then
if opts.variant and tostring(opts.variant) ~= "" then
root:addClass("sv-gi--" .. tostring(opts.variant))
root:addClass("sv-gi--" .. tostring(opts.variant))
root:attr("data-sv-card-variant", tostring(opts.variant))
end
end


local top = root:tag("div"):addClass("sv-gi-top")
local top = root:tag("div"):addClass("sv-gi-top")
local bottom = root:tag("div"):addClass("sv-gi-bottom")
local bottom = root:tag("div")
:addClass("sv-gi-bottom")
:attr("data-sv-level-scope", "1")


return { root = root, top = top, bottom = bottom }
return { root = root, top = top, bottom = bottom }
end
end


-- Backward-friendly alias for your own codebase (not “reverse wiki compat”).
p.new_box = p.box
p.new_box = p.box


function p.render_box(opts)
function p.render_box(opts)
local box = p.box(opts)
local box = p.box(opts)
if opts and opts.top ~= nil then
if opts then
if _is_html_node(opts.top) then box.top:node(opts.top) else box.top:wikitext(tostring(opts.top)) end
_append_content(box.top, opts.top)
end
_append_content(box.bottom, opts.bottom)
if opts and opts.bottom ~= nil then
if _is_html_node(opts.bottom) then box.bottom:node(opts.bottom) else box.bottom:wikitext(tostring(opts.bottom)) end
end
end
return tostring(box.root)
return tostring(box.root)
end
end
-- -----------------------------------------------------------------------------
-- Dispatch
-- -----------------------------------------------------------------------------


local function _require_submodule(module_title)
local function _require_submodule(module_title)
Line 183: Line 155:
return p.styles(frame, style_src) .. tostring(out or "")
return p.styles(frame, style_src) .. tostring(out or "")
end
end
-- -----------------------------------------------------------------------------
-- Public entrypoints
-- -----------------------------------------------------------------------------


function p.Skills(frame)
function p.Skills(frame)
Line 208: Line 176:
end
end


-- Optional: sanity test for box + CSS wiring
-- {{#invoke:GameInfo|skeleton|id=sv-gi-test-1|level=1|max=10|variant=skills}}
function p.skeleton(frame)
function p.skeleton(frame)
frame = frame or mw.getCurrentFrame()
frame = frame or mw.getCurrentFrame()
Line 226: Line 192:
max_level = max_level,
max_level = max_level,
variant = variant,
variant = variant,
top = tostring(top),
top = top,
bottom = tostring(bottom),
bottom = bottom,
})
})
end
end


return p
return p