Module:GameSkills: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 729: | Line 729: | ||
-- formatAreaSize: human readable area sizing for QuickStats. | -- formatAreaSize: human readable area sizing for QuickStats. | ||
local function formatAreaSize(area) | -- Shows: "<Area Size> (<number>)" e.g. "Medium (4)" | ||
local function formatAreaSize(area, maxLevel, level) | |||
if type(area) ~= "table" then | if type(area) ~= "table" then | ||
return nil | return nil | ||
end | end | ||
local | -- Helper: pull a number from scalar/unit/valuepair-ish things. | ||
local function extractNumber(v) | |||
if v == nil then return nil end | |||
-- Unit block {Value, Unit} | |||
if type(v) == "table" and v.Value ~= nil then | |||
local n = toNum(v.Value) | |||
return n | |||
end | |||
-- ValuePair {Base, Per Level} -> prefer Base at current level if series exists | |||
if type(v) == "table" and (v.Base ~= nil or v["Per Level"] ~= nil) then | |||
local s = seriesFromValuePair(v, maxLevel or 1) | |||
if type(s) == "table" and #s > 0 then | |||
local idx = clamp(level or 1, 1, #s) | |||
local txt = s[idx] | |||
if txt and txt ~= "—" then | |||
-- try parse numeric from string (e.g. "4 tiles" -> 4) | |||
local num = tonumber((mw.ustring.gsub(tostring(txt), "[^0-9%.%-]", ""))) | |||
return num | |||
end | |||
end | |||
return nil | |||
end | |||
-- Plain scalar | |||
if type(v) == "number" then return v end | |||
if type(v) == "string" then | |||
local num = tonumber((mw.ustring.gsub(mw.text.trim(v), "[^0-9%.%-]", ""))) | |||
return num | |||
end | |||
return nil | return nil | ||
end | end | ||
local | -- 1) Read Area Size label/name | ||
local rawSize = area["Area Size"] | |||
if rawSize == nil then | |||
return nil | |||
end | |||
if type( | local sizeName = nil | ||
if type(rawSize) == "table" then | |||
num | sizeName = rawSize.Name or rawSize.ID or rawSize.Value | ||
if | elseif type(rawSize) == "string" then | ||
sizeName = rawSize | |||
elseif type(rawSize) == "number" then | |||
-- uncommon; treat as numeric-only label | |||
sizeName = tostring(rawSize) | |||
end | |||
sizeName = sizeName and mw.text.trim(tostring(sizeName)) or nil | |||
if not sizeName or sizeName == "" or isNoneLike(sizeName) then | |||
return nil | |||
end | |||
-- 2) Find the numeric “exact number” to append | |||
-- Prefer the explicit Area Distance block, then fall back to other known numeric keys. | |||
local num = nil | |||
local dist = area["Area Distance"] | |||
if type(dist) == "table" then | |||
-- Prefer Effective Distance if present and non-zero, else Base | |||
num = extractNumber(dist["Effective Distance"]) or extractNumber(dist.Effective) or extractNumber(dist["Effective"]) | |||
if not num or num == 0 then | |||
num = extractNumber(dist.Base) or extractNumber(dist["Base"]) | |||
end | end | ||
end | end | ||
if num == | if not num or num == 0 then | ||
num = | num = | ||
extractNumber(area["Area Value"]) or | |||
extractNumber(area["Area Size Value"]) or | |||
extractNumber(area["Area Number"]) or | |||
extractNumber(area["Area Radius"]) | |||
end | end | ||
-- 3) Render | |||
-- If size already contains parentheses, assume it already includes the numeric. | |||
if mw.ustring.find(sizeName, "%(") then | |||
return mw.text.nowiki(sizeName) | |||
return mw.text.nowiki( | |||
end | end | ||
if num | if num and num ~= 0 then | ||
return mw.text.nowiki(string.format("(%s)", fmtNum(num))) | return mw.text.nowiki(string.format("%s (%s)", sizeName, fmtNum(num))) | ||
end | end | ||
return | return mw.text.nowiki(sizeName) | ||
end | end | ||
| Line 1,230: | Line 1,277: | ||
-- Area | -- Area | ||
local areaVal = formatAreaSize(mech.Area, maxLevel, level) | |||
-- Timings | -- Timings | ||