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

From SpiritVale Wiki
No edit summary
No edit summary
Line 5: Line 5:
--  Module:Definitions/Definitions.json
--  Module:Definitions/Definitions.json
--
--
-- JSON shape (dynamic):
-- JSON shape:
-- {
-- {
--  "Schema": 1,
--  "Schema": 1,
Line 17: Line 17:
-- - Domains + keys are discovered from JSON (no hardcoded domain lists).
-- - Domains + keys are discovered from JSON (no hardcoded domain lists).
-- - CSS namespace: ONLY "sv-def" (plus sv-def--* modifiers).
-- - CSS namespace: ONLY "sv-def" (plus sv-def--* modifiers).
-- - For TemplateStyles compatibility: use simple classes (sv-def-icon / sv-def-text)
-- - Output classes: sv-def, sv-def-icon, sv-def-icon-img, sv-def-text.
--   instead of attribute selectors.


local p = {}
local p = {}
Line 25: Line 24:


-- =============================================================================
-- =============================================================================
-- Small helpers
-- Helpers
-- =============================================================================
-- =============================================================================


Line 103: Line 102:
end
end


-- Case-insensitive match across top-level keys, skipping meta keys
-- Case-insensitive match across top-level keys that are tables
local want = lc(domain)
local want = lc(domain)
for k, v in pairs(db) do
for k, v in pairs(db) do
if type(v) == "table" and lc(k) == want then
if type(v) == "table" and lc(k) == want then
if k ~= "Schema" and k ~= "UpdatedAt" then
return k
return k
end
end
end
end
end
Line 124: Line 121:
-- =============================================================================
-- =============================================================================
-- Icon rendering
-- Icon rendering
-- - Blank icon: show "i" (generic info icon for v1)
-- - Blank icon: render nothing (no generic dot/circle)
-- - Missing file: show "?" (missing asset)
-- - Missing file: render "?" badge (no redlink image)
-- =============================================================================
-- =============================================================================


Line 131: Line 128:
icon = trim(icon)
icon = trim(icon)


-- v1 default: no icon when blank
if icon == "" then
if icon == "" then
return ""
return ""
Line 143: Line 139:
local t = mw.title.new(fileTitle)
local t = mw.title.new(fileTitle)
if not t or not t.exists then
if not t or not t.exists then
-- Missing file: show '?' badge (no redlink image)
return '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>'
return '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>'
end
end


-- Real file icon (no pill/circle wrapping)
return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|16px|link=]]</span>'
return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|16px|link=]]</span>'
end
end
Line 179: Line 173:


local d_lc = lc(domain)
local d_lc = lc(domain)
-- Missing record: show a visible hint but NO tooltip/link data.
if rec == nil then
return
'<span class="sv-def sv-def--missing sv-def--' .. enc_attr(d_lc) .. '"' ..
' data-sv-def-domain="' .. enc_attr(domain) .. '"' ..
' data-sv-def-key="' .. enc_attr(key) .. '"' ..
'>' ..
'<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>' ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'</span>'
end


local attrs = {
local attrs = {
Line 186: Line 192:
}
}


-- Only include tooltip/link attributes when populated.
if defn ~= "" then
if defn ~= "" then
attrs[#attrs + 1] = 'data-sv-def-tip="' .. enc_attr(defn) .. '"'
attrs[#attrs + 1] = 'data-sv-def-tip="' .. enc_attr(defn) .. '"'
Line 195: Line 202:
local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or ""
local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or ""


local html =
return
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
icon_html(icon) ..
icon_html(icon) ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'</span>'
'</span>'
if rec == nil then
html =
'<span class="sv-def sv-def--missing" data-sv-def-domain="' .. enc_attr(domain) ..
'" data-sv-def-key="' .. enc_attr(key) .. '">?</span>'
end
return html
end
end


Line 214: Line 213:
-- =============================================================================
-- =============================================================================


-- Template entrypoint: {{#invoke:Definitions|def|Domain|Key}}
function p.def(frame)
function p.def(frame)
local a = frame.args or {}
local a = frame.args or {}
Line 220: Line 218:
end
end


-- Programmatic: require('Module:Definitions').render('Stat', 'Vit')
function p.render(domain, key)
function p.render(domain, key)
return render(domain, key)
return render(domain, key)