目录
目录README.md

D20

Need to evaluate dice notation in Swift? This package is for you.

Examples

let roll = Roll("1d20")!.roll()
roll.result
// $R0: Int = 18

let roll = Roll("3d8+1d6")!.roll()
roll.result
// $R0: Int = 19
roll.expression
// $R1: String = "1+6+7+5"

// Percentage die shorthand is also supported.
let roll = Roll("d%")

D(20).average
// $R0: Double = 10.5

The rest of the API is pretty self-explanatory. Dice and Rolls have attributes for accessing the max, half and average values of their rolls. Use the roll() function to actually throw the dice on both of these types and get some random values.

CLI

This package also includes a small CLI to roll the dice directly in your terminal.

$ d20 2d6+4
# 14 (6+4)+4

$ alias dagger='d20 1d4+2'
$ dagger
# 6 (4)+2
# CRIT!

# Invoke it without an argument to enter REPL mode.
$ d20
> d4
3 (3)
> 2d4
6 (2+4)

Installing it is easy. Just run the following after cloning the repo.

$ swift build -c release
$ cp .build/release/d20 /usr/local/bin/d20

D20 by Lonnie Tapscott from the Noun Project

关于
76.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号