Editing Module:Sandbox/Vergir

Jump to navigation Jump to search
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 65: Line 65:
local function format_spirit(v)
local function format_spirit(v)
     return string.format("%.3g", v)
     return string.format("%.3g", v)
end
-- Formats one Spirit scaling for the table cell through the compact {{Ss}}
-- form, the same way RenderBarrier does. The template is expanded via the
-- frame the surrounding #invoke runs under, since module return values are
-- not re-expanded; the plain "×N" fallback covers a nil frame (module
-- console).
local function format_spirit_badge(v)
    local text  = format_spirit(v)
    local frame = mw.getCurrentFrame()
    if frame then
        return frame:expandTemplate{
            title = "Ss",
            args  = { text, compact = "1", show_value = "1" },
        }
    end
    return "×" .. text
end
end


Line 91: Line 74:


-- Renders Spirit Power scaling.
-- Renders Spirit Power scaling.
-- Lists every prop that scales with Spirit at base, one per line as an {{Ss}}
-- Lists every prop that scales with Spirit at base, one per line, labelled
-- badge labelled with the prop's name from the ability card:
-- with the prop's name from the ability card: "×0.55 (Base Damage)". Two
-- "x0.55 (Base Damage)". Two
-- props sharing a name are told apart by the card's Title
-- props sharing a name are told apart by the card's Title
-- ("Damage: Cost of Stay"); props the card does not list show their raw key.
-- ("Damage: Cost of Stay"); props the card does not list show their raw key.
Line 104: Line 86:


     local base  = spirit_scalings(ability, labels)
     local base  = spirit_scalings(ability, labels)
     local tiers = {}   -- { tier = i, list = ... } in tier order
     local tiers = {}
     local upgrades = ability["Upgrades"]
     local upgrades = ability["Upgrades"]
     if type(upgrades) == "table" then
     if type(upgrades) == "table" then
        -- ipairs rather than #: mw.loadJsonData tables have no length.
         for i, tier in ipairs(upgrades) do
         for i, tier in ipairs(upgrades) do
             if type(tier) == "table" then
             if type(tier) == "table" then tiers[i] = spirit_scalings(tier, labels) end
                table.insert(tiers, { tier = i, list = spirit_scalings(tier, labels) })
            end
         end
         end
     end
     end
Line 128: Line 107:
     end
     end
     note_keys(base)
     note_keys(base)
     for _, t in ipairs(tiers) do note_keys(t.list) end
     for _, list in pairs(tiers) do note_keys(list) end


     local function label_of(key)
     local function label_of(key)
Line 145: Line 124:
         local lines = {}
         local lines = {}
         for _, prop in ipairs(base) do
         for _, prop in ipairs(base) do
             table.insert(lines, format_spirit_badge(prop.value) .. " (" .. label_of(prop.key) .. ")")
             table.insert(lines, "×" .. format_spirit(prop.value) .. " (" .. label_of(prop.key) .. ")")
             running[prop.key] = prop.value
             running[prop.key] = prop.value
         end
         end
Line 152: Line 131:


     local notes = {}
     local notes = {}
     for _, t in ipairs(tiers) do
     for i = 1, (type(upgrades) == "table" and #upgrades or 0) do
         local i, list = t.tier, t.list
         local list = tiers[i]
        local groups, group_order = {}, {}  -- Multiply upgrades, grouped by multiplier
        if list then
        for _, up in ipairs(list) do
            local groups, group_order = {}, {}  -- Multiply upgrades, grouped by multiplier
            local label  = label_of(up.key)
            for _, up in ipairs(list) do
            local current = running[up.key]
                local label  = label_of(up.key)
            if up.multiply then
                local current = running[up.key]
                local group = groups[up.value]
                if up.multiply then
                if not group then
                    local group = groups[up.value]
                    group = { labels = {}, totals = {} }
                    if not group then
                    groups[up.value] = group
                        group = { labels = {}, totals = {} }
                    table.insert(group_order, up.value)
                        groups[up.value] = group
                end
                        table.insert(group_order, up.value)
                table.insert(group.labels, label)
                    end
                if current then
                    table.insert(group.labels, label)
                    running[up.key] = current * up.value
                    if current then
                     table.insert(group.totals, "×" .. format_spirit(running[up.key]))
                        running[up.key] = current * up.value
                        table.insert(group.totals, "×" .. format_spirit(running[up.key]))
                     else
                        table.insert(group.totals, "?")
                    end
                elseif current then
                    running[up.key] = current + up.value
                    table.insert(notes, "T" .. i .. " upgrade adds +×" .. format_spirit(up.value)
                        .. " " .. label .. " scaling (total ×" .. format_spirit(running[up.key]) .. ")")
                 else
                 else
                     table.insert(group.totals, "?")
                    running[up.key] = up.value
                     table.insert(notes, "T" .. i .. " upgrade grants ×" .. format_spirit(up.value)
                        .. " " .. label .. " scaling")
                 end
                 end
            elseif current then
                running[up.key] = current + up.value
                table.insert(notes, "T" .. i .. " upgrade adds +×" .. format_spirit(up.value)
                    .. " " .. label .. " scaling (total ×" .. format_spirit(running[up.key]) .. ")")
            else
                running[up.key] = up.value
                table.insert(notes, "T" .. i .. " upgrade grants ×" .. format_spirit(up.value)
                    .. " " .. label .. " scaling")
             end
             end
        end
            for _, m in ipairs(group_order) do
        for _, m in ipairs(group_order) do
                local group = groups[m]
            local group = groups[m]
                table.insert(notes, "T" .. i .. " upgrade multiplies " .. join_names(group.labels)
            table.insert(notes, "T" .. i .. " upgrade multiplies " .. join_names(group.labels)
                    .. " scaling by " .. format_spirit(m)
                .. " scaling by " .. format_spirit(m)
                    .. " (total " .. table.concat(group.totals, ", ") .. ")")
                .. " (total " .. table.concat(group.totals, ", ") .. ")")
            end
         end
         end
     end
     end
Line 675: Line 656:
     table.insert(out, "|}")
     table.insert(out, "|}")
     return table.concat(out, "\n")
     return table.concat(out, "\n")
end
-- TEST ONLY: plain-text dump of a list for review, one line per ability.
function p.dump(frame)
    local stat = mw.text.trim(frame.args[1] or ""):lower()
    local views, order = build_views()
    local spec = extra_columns[stat]
    local get_cells = spec and spec.get_cells or function() return {} end
    local out = {}
    for _, key in ipairs(order) do
        if p.is_member(stat, key) then
            local entry = views[key]
            local extra = get_cells(entry.view, entry.cardprops)
            local cell = extra["Spirit Scaling"] or "—"
            cell = mw.text.killMarkers(cell):gsub("<br>", " / "):gsub("<[^>]+>", "")
            table.insert(out, entry.heroName .. " | " .. entry.view["Name"] .. " | " .. cell .. " | " .. (extra["Notes"] or "—"))
        end
    end
    return "<pre>" .. mw.text.nowiki(table.concat(out, "\n")) .. "</pre>"
end
end


return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: