Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kiliankoe/d20
🎲 Evaluate dice notation in Swift
https://github.com/kiliankoe/d20
cli dice dice-notation dice-roller dnd tabletop
Last synced: 18 days ago
JSON representation
🎲 Evaluate dice notation in Swift
- Host: GitHub
- URL: https://github.com/kiliankoe/d20
- Owner: kiliankoe
- License: mit
- Created: 2019-09-10T08:40:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-24T13:41:28.000Z (almost 5 years ago)
- Last Synced: 2024-09-16T17:20:05.623Z (about 2 months ago)
- Topics: cli, dice, dice-notation, dice-roller, dnd, tabletop
- Language: Swift
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
D20
Need to evaluate [dice notation](https://en.wikipedia.org/wiki/Dice_notation) in Swift? This package is for you.
### Examples
```swift
let roll = Roll("1d20")!.roll()
roll.result
// $R0: Int = 18let 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. `D`ice and `Roll`s 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.
```bash
$ 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.
```bash
$ swift build -c release
$ cp .build/release/d20 /usr/local/bin/d20
```#### Logo Credits
[D20](https://thenounproject.com/search/?q=d20&i=2453700) by Lonnie Tapscott from the Noun Project