diff --git a/src/diced.gleam b/src/diced.gleam index 24f5436..3b5dd8e 100644 --- a/src/diced.gleam +++ b/src/diced.gleam @@ -37,8 +37,12 @@ const modifier_strings = [ ] pub type Dice { + /// A "normal" dice roll with an amount, value and a list of modifiers to apply Basic(amount: Int, value: Int, modifiers: List(Modifier)) + /// A fate dice roll with an amount, and a list of modifiers to apply. Fate dice are dice with 3 results, all with an + /// equal number of faces. [Learn more](https://en.wikipedia.org/wiki/Fudge_%28role-playing_game_system%29) Fate(amount: Int, modifiers: List(Modifier)) + /// A basic number and some modifiers that could be applied. Number(value: Int, modifiers: List(Modifier)) } @@ -49,6 +53,12 @@ pub type DiceError { InvalidModifier } +/// Convert a string containing algebraic dice notation into a type describing how the dice should behave when rolled. +/// +/// ```gleam +/// diced.parse("2d20kh") +/// // Ok(diced.Basic(2, 20, [KeepHighest(1)])) +/// ``` pub fn parse(string string: String) -> Result(Dice, DiceError) { let dice_splitter = splitter.new(["d", "dF"]) case splitter.split(dice_splitter, string) {