5 releases (breaking)
0.5.0 | Jul 30, 2021 |
---|---|
0.4.0 | Jul 12, 2021 |
0.3.0 | Jul 12, 2021 |
0.2.0 | Jul 12, 2021 |
0.1.0 | Jul 11, 2021 |
#1760 in Game dev
45KB
962 lines
Gurgle
Gurgle is yet another dice rolling crate using TRPG-like syntax.
Have a Taste
let attack = "3d6+2d4+1";
println!("roll your attack({}), result: {}", attack, gurgle::roll(attack).unwrap());
// output: roll your attack(3d6+2d4+1), result: 16
use gurgle::Gurgle;
let attack = "3d6+2d4+1>15";
let dice = Gurgle::compile(attack).unwrap();
let result = dice.roll();
println!("roll your attack({}), result: {}", attack, result);
// output: roll your attack(3d6+2d4+1>15), result: (4+3+1) + (1+3) + 1 = 15, target is >15, failed
Notice: Display
trait for rolling result is implemented only if feature detail
(which is enabled by default) is enabled.
But you can always use result.value()
to get rolling result value(i64), and result.success()
to get if it's a success.
Gurgle also support multiply and parentheses, see docs for full syntax and example.
License
BSD 3-Clause Clear License, See LICENSE.
Dependencies
~2.1–2.9MB
~58K SLoC