Anonymous

Module:CommonFunctions: Difference between revisions

From Elwiki
no edit summary
No edit summary
No edit summary
Line 213: Line 213:
function inspect_dump(tbl, frame)
function inspect_dump(tbl, frame)
     return frame:preprocess("<pre><nowiki>" .. inspect(tbl) .. "</nowiki></pre>")
     return frame:preprocess("<pre><nowiki>" .. inspect(tbl) .. "</nowiki></pre>")
end
function sortPassives(s)
    local passives = {}
    for passive in s:gmatch("_passive%d+") do
        table.insert(passives, passive)
    end
    if #passives == 0 then
        return s
    end
    table.sort(passives)
    local base = s:gsub("_passive%d+", "")
    return base .. table.concat(passives)
end
function link(page, text)
    return '[[' .. page .. '|' .. (text or page) .. ']]'
end
local function generateCombinations(passives, n, combo, combos)
    if n == 0 then
        table.insert(combos, combo)
    else
        for i = 1, #passives do
            local newCombo = {}
            for j = 1, #combo do
                table.insert(newCombo, combo[j])
            end
            table.insert(newCombo, passives[i])
            generateCombinations(passives, n - 1, newCombo, combos)
        end
    end
end
function formatDamage(number)
    local formattedDamage = number > 0 and (formatnum(math.round(number, 2)) .. '%') or '-%'
    return formattedDamage
end
end