Module:Dice/Format

From Caves of Qud Wiki
< Module:Dice
Revision as of 17:50, 10 August 2019 by Sol (talk | contribs) (add truncated mean; minor refactoring)
Jump to navigation Jump to search

local Dice = require'Module:Dice'

local DiceFormat = {}

function DiceFormat.diceStats(frame)
    local dice = Dice.fromString(frame.args.roll)

    local templatetitle = 'Dice string'

    if (frame.args.template ~= nil and frame.args.template ~= '') then
        templatetitle = frame.args.template
    end

    local minimum = dice:minimum()
    local mean = dice:mean()
    local maximum = dice:maximum()

    return frame:expandTemplate{
        title = templatetitle,
        args = {
            minimum = minimum,
            mean = mean,
            mean_truncated = ('%d'):format(mean),
            maximum = maximum,
        },
    }
end

return DiceFormat