Module:GameInfo/Skills: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 178: | Line 178: | ||
end | end | ||
return wrap | return wrap | ||
end | |||
-- ----------------------------------------------------------------------------- | |||
-- Keyword pills: render "Domain|Key" as {{def|Domain|Key}} safely | |||
-- ----------------------------------------------------------------------------- | |||
local function _render_keyword_pill(frame, pill_text) | |||
pill_text = _trim(pill_text) | |||
if pill_text == "" then | |||
return nil | |||
end | |||
local bar = pill_text:find("|", 1, true) | |||
if bar then | |||
local domain = _trim(pill_text:sub(1, bar - 1)) | |||
local key = _trim(pill_text:sub(bar + 1)) | |||
if domain ~= "" and key ~= "" then | |||
return frame:expandTemplate{ title = "def", args = { domain, key } } | |||
end | |||
end | |||
return mw.text.nowiki(pill_text) | |||
end | end | ||
| Line 369: | Line 391: | ||
local function _build_level(level_obj) | local function _build_level(level_obj) | ||
level_obj = _safe_tbl(level_obj) | |||
local default = _to_int(level_obj.default, 1) | |||
local max = _to_int(level_obj.max, _to_int(level_obj.base_max, 1)) | |||
if max < 1 then max = 1 end | |||
if default < 1 then default = 1 end | |||
if default > max then default = max end | |||
local root = mw.html.create("div"):addClass("sv-skill-level") | |||
local ui = root:tag("div"):addClass("sv-level-ui") | |||
ui:tag("div") | |||
:addClass("sv-level-label") | |||
:wikitext("Level ") | |||
:tag("span"):addClass("sv-level-num"):wikitext(tostring(default)) | |||
ui:tag("div"):addClass("sv-level-label"):wikitext(" / " .. tostring(max)) | |||
local slider_wrap = root:tag("div"):addClass("sv-level-slider") | |||
-- Phase 4.1-safe slider (no <input>) | |||
local slider = slider_wrap:tag("span") | |||
:addClass("sv-level-range") | |||
:addClass("sv-level-range--custom") | |||
:attr("data-sv-slider", "1") | |||
:attr("role", "slider") | |||
:attr("tabindex", "0") | |||
:attr("aria-label", "Skill level select") | |||
:attr("aria-valuemin", "1") | |||
:attr("aria-valuemax", tostring(max)) | |||
:attr("aria-valuenow", tostring(default)) | |||
:attr("data-min", "1") | |||
:attr("data-max", tostring(max)) | |||
:attr("data-value", tostring(default)) | |||
local track = slider:tag("span"):addClass("sv-level-track"):attr("aria-hidden", "true") | |||
track:tag("span"):addClass("sv-level-fill"):attr("aria-hidden", "true") | |||
slider:tag("span"):addClass("sv-level-thumb"):attr("aria-hidden", "true") | |||
slider_wrap:tag("div"):addClass("sv-level-ticklabels"):attr("aria-hidden", "true") | |||
return root, default, max | |||
end | end | ||
| Line 475: | Line 497: | ||
end | end | ||
local function _build_tabs(root_id, tabs_obj, level) | local function _build_tabs(frame, root_id, tabs_obj, level) | ||
tabs_obj = _safe_tbl(tabs_obj) | tabs_obj = _safe_tbl(tabs_obj) | ||
| Line 545: | Line 567: | ||
local pills = panel:tag("div"):addClass("sv-tab-pills") | local pills = panel:tag("div"):addClass("sv-tab-pills") | ||
for _, kw in ipairs(_safe_tbl(keywords.pills)) do | for _, kw in ipairs(_safe_tbl(keywords.pills)) do | ||
local | local wt = _render_keyword_pill(frame, kw) | ||
if | if wt then | ||
pills:tag("span"):addClass("sv-pill"):wikitext(wt) | |||
end | end | ||
end | end | ||
| Line 688: | Line 704: | ||
box.bottom:node(_build_scaling_top(payload.scaling_top, actual_default)) | box.bottom:node(_build_scaling_top(payload.scaling_top, actual_default)) | ||
box.bottom:node(_build_core_stats(payload.core_stats, actual_default)) | box.bottom:node(_build_core_stats(payload.core_stats, actual_default)) | ||
box.bottom:node(_build_tabs(root_id, payload.tabs, actual_default)) | box.bottom:node(_build_tabs(frame, root_id, payload.tabs, actual_default)) | ||
return tostring(box.root) | return tostring(box.root) | ||