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
Tags: Manual revert Mobile edit Mobile web edit
No edit summary
Tags: Mobile edit Mobile web edit
Line 4: Line 4:
-- Data source (static):
-- Data source (static):
--  Module:Definitions/Definitions.json
--  Module:Definitions/Definitions.json
--
-- JSON shape:
-- {
--  "Schema": 1,
--  "UpdatedAt": "YYYY-MM-DD",
--  "Stat":  { "Vit": { "Name":"...", "Definition":"...", "Icon":"", "Link":"" }, ... },
--  "Target": { ... },
--  ...
-- }
--
--
-- Notes:
-- Notes:
Line 34: Line 25:
local function lc(s)
local function lc(s)
return string.lower(tostring(s or ""))
return string.lower(tostring(s or ""))
end
local function truthy(v)
v = lc(mw.text.trim(tostring(v or "")))
return v == "1" or v == "true" or v == "yes" or v == "y"
end
end


Line 149: Line 145:
-- =============================================================================
-- =============================================================================


local function render(domain, key)
local function render(domain, key, opts)
opts = opts or {}
local noicon = truthy(opts.noicon)
 
local db = load_db()
local db = load_db()
domain = norm_domain(db, domain)
domain = norm_domain(db, domain)
Line 176: Line 175:
-- Missing record: show a visible hint but NO tooltip/link data.
-- Missing record: show a visible hint but NO tooltip/link data.
if rec == nil then
if rec == nil then
local miss_icon = noicon and "" or '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>'
return
return
'<span class="sv-def sv-def--missing sv-def--' .. enc_attr(d_lc) .. '"' ..
'<span class="sv-def sv-def--missing sv-def--' .. enc_attr(d_lc) .. '"' ..
Line 181: Line 181:
' data-sv-def-key="' .. enc_attr(key) .. '"' ..
' data-sv-def-key="' .. enc_attr(key) .. '"' ..
'>' ..
'>' ..
'<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>' ..
miss_icon ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'</span>'
'</span>'
end
local classes = 'sv-def sv-def--' .. enc_attr(d_lc)
if noicon then
classes = classes .. ' sv-def--noicon'
end
end


local attrs = {
local attrs = {
'class="sv-def sv-def--' .. enc_attr(d_lc) .. '"',
'class="' .. classes .. '"',
'data-sv-def-domain="' .. enc_attr(domain) .. '"',
'data-sv-def-domain="' .. enc_attr(domain) .. '"',
'data-sv-def-key="' .. enc_attr(key) .. '"',
'data-sv-def-key="' .. enc_attr(key) .. '"',
Line 201: Line 206:


local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or ""
local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or ""
local ico = noicon and "" or icon_html(icon)


return
return
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
icon_html(icon) ..
ico ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'</span>'
'</span>'
Line 215: Line 222:
function p.def(frame)
function p.def(frame)
local a = frame.args or {}
local a = frame.args or {}
return render(a[1] or a.Domain or a.domain, a[2] or a.Key or a.key)
local domain = a[1] or a.Domain or a.domain
local key    = a[2] or a.Key or a.key
local noicon = a.noicon or a.NoIcon or a[3]
return render(domain, key, { noicon = noicon })
end
end


function p.render(domain, key)
function p.render(domain, key, opts)
return render(domain, key)
return render(domain, key, opts)
end
end


return p
return p