Module:Sandbox/Aurelain/HeroClassSkills: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary
No edit summary
Line 6: Line 6:
local function dump(target)
local function dump(target)
     return '<pre>' .. mw.dumpObject(target) .. '</pre>'
     return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end
------------------------------------------------------------------------------------------------------------------------
local function collectChances(target)
    return {}
end
------------------------------------------------------------------------------------------------------------------------
local function computeTotal(chances)
    return 1000
end
------------------------------------------------------------------------------------------------------------------------
local function formatChances(chances)
    return ''
end
end


Line 12: Line 27:
     local lang = frame.args.lang
     local lang = frame.args.lang
     local id = frame.args.id;
     local id = frame.args.id;
     local total = 1000;
 
    local chances = collectChances();
     local total = computeTotal(chances);
    local formattedChances = formatChances(chances);
 
     local cleanTitle = frame:getTitle():gsub('Module:', '')
     local cleanTitle = frame:getTitle():gsub('Module:', '')
     return frame:preprocess(mw.ustring.format([[
     return frame:preprocess(mw.ustring.format([[
Line 18: Line 37:
         | lang = %s
         | lang = %s
         | id = %s
         | id = %s
        | total = %s
         | total = %s
         | total = %s
         }}
         }}
     ]], cleanTitle, lang, id, total))
     ]], cleanTitle, lang, id, total, formattedChances))
end
end



Revision as of 09:22, 8 August 2026

Documentation for this module may be created at Module:Sandbox/Aurelain/HeroClassSkills/doc

-- This module is intended as a supporting muscle for the HeroClassSkills template.
local p = {}

-- Displays a variable
------------------------------------------------------------------------------------------------------------------------
local function dump(target)
    return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end

------------------------------------------------------------------------------------------------------------------------
local function collectChances(target)
    return {}
end

------------------------------------------------------------------------------------------------------------------------
local function computeTotal(chances)
    return 1000
end

------------------------------------------------------------------------------------------------------------------------
local function formatChances(chances)
    return ''
end

------------------------------------------------------------------------------------------------------------------------
function p.populate(frame)
    local lang = frame.args.lang
    local id = frame.args.id;

    local chances = collectChances();
    local total = computeTotal(chances);
    local formattedChances = formatChances(chances);

    local cleanTitle = frame:getTitle():gsub('Module:', '')
    return frame:preprocess(mw.ustring.format([[
        {{%s/base
        | lang = %s
        | id = %s
        | total = %s
        | total = %s
        }}
    ]], cleanTitle, lang, id, total, formattedChances))
end

------------------------------------------------------------------------------------------------------------------------
function p.percent(frame)
    local a = frame.args[1]
    local b = frame.args[2]
    return string.format("%.2f", 100 * a / b)
end

return p