Module:AbilityTable/ComplexRenderers: Difference between revisions

Vergir (talk | contribs)
add RenderBarrier for the barrier list: running totals of barrier value and Spirit scaling per upgrade tier (with help from vergir-bot LLM)
Vergir (talk | contribs)
RenderBarrier: use the compact {{Ss}} form and keep one decimal on scaling totals (with help from vergir-bot LLM)
Line 81: Line 81:
end
end


-- Formats one barrier step. Spirit scaling goes through {{Ss}}, expanded via
-- Pads a whole-number scaling out to one decimal, so a running total of 2
-- the frame the surrounding #invoke is already running under: module return
-- reads "2.0" next to its "1.5" neighbours instead of "2". Values that already
-- values are not re-expanded, so a literal "{{Ss|0.8}}" would reach the page
-- carry decimals are left alone, which keeps precision on things like 0.75.
-- as text. The plain fallback covers a nil frame (module console).
local function format_scale(scale)
    local text = tostring(scale)
    if not text:find(".", 1, true) then text = text .. ".0" end
    return text
end
 
-- Formats one barrier step. Spirit scaling goes through the compact {{Ss}}
-- form, expanded via the frame the surrounding #invoke is already running
-- under: module return values are not re-expanded, so a literal "{{Ss|0.8}}"
-- would reach the page as text. The plain fallback covers a nil frame
-- (module console).
local function format_barrier(value, scale)
local function format_barrier(value, scale)
     local out = tostring(value)
     local out = tostring(value)
     if scale and scale ~= 0 then
     if scale and scale ~= 0 then
        local scale_text = format_scale(scale)
         local frame = mw.getCurrentFrame()
         local frame = mw.getCurrentFrame()
         if frame then
         if frame then
             out = out .. " " .. frame:expandTemplate{ title = "Ss", args = { scale } }
             out = out .. " " .. frame:expandTemplate{
                title = "Ss",
                args = { scale_text, compact = "1", show_value = "1" },
            }
         else
         else
             out = out .. " ×" .. scale
             out = out .. " ×" .. scale_text
         end
         end
     end
     end