Skip to content

Commit

Permalink
Rename project to Tyche
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawdl3y committed Apr 24, 2024
1 parent e4c1967 commit 4596490
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: cargo doc --no-deps

- name: Add redirect
run: echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=dicey/index.html"></head><body><p>Redirecting to <a href="./dicey/index.html">./dicey/index.html</a>...</p></body></html>' > target/doc/index.html
run: echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=tyche/index.html"></head><body><p>Redirecting to <a href="./tyche/index.html">./tyche/index.html</a>...</p></body></html>' > target/doc/index.html

- name: Remove lock file
run: rm target/doc/.lock
Expand Down
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "dicey"
name = "tyche"
version = "0.1.0"
description = "Dice rolling and dice expression (with a syntax similar to FoundryVTT) parsing library"
authors = ["Schuyler Cebulskie <[email protected]>"]
Expand All @@ -11,7 +11,7 @@ categories = [
"parser-implementations",
]
license = "LGPL-3.0-or-later"
repository = "https://github.com/Gawdl3y/dicey-rs"
repository = "https://github.com/Gawdl3y/tyche-rs"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -29,5 +29,5 @@ chumsky = { version = "1.0.0-alpha.7", optional = true, features = ["label"] }
ariadne = { version = "0.4", optional = true }

[[bin]]
name = "dicey"
name = "tyche"
required-features = ["build-binary"]
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dicey
# Tyche

Dicey is a library for parsing, rolling, and explaining the results of tabletop dice.
Tyche is a library for parsing, rolling, and explaining the results of tabletop dice.
It also has a simple CLI app binary that evaluates a given expression.

The eventual goal is full compatibility with [FoundryVTT's dice syntax](https://foundryvtt.com/article/dice/) with some
Expand Down Expand Up @@ -39,21 +39,21 @@ convenient extensions.

### Library

Run `cargo add dicey` or add the following to your project's Cargo.toml file:
Run `cargo add tyche` or add the following to your project's Cargo.toml file:

```toml
[dependencies]
dicey = "0.1.0"
tyche = "0.1.0"
```

### Binary (CLI app)

Run `cargo install dicey --features build-binary`.
Assuming Cargo's bin directory is in your `$PATH`, use the app with `dicey` or `dicey <dice expression>`.
Run `cargo install tyche --features build-binary`.
Assuming Cargo's bin directory is in your `$PATH`, use the app with `tyche` or `tyche <dice expression>`.

## Library usage

There are three main types that you'll start with while using Dicey:
There are three main types that you'll start with while using Tyche:

- `Dice`: a struct containing a dice count, number of sides for each die, and modifiers that should be applied to any
resulting rolls, representing a set of dice, e.g. `4d8x`.
Expand All @@ -70,15 +70,15 @@ There are three main types that you'll start with while using Dicey:

All parsing requires the `parse` feature of the crate to be enabled (which it is by default).

Dicey uses the [chumsky](https://github.com/zesterer/chumsky) parser generator to parse all strings in a
Tyche uses the [chumsky](https://github.com/zesterer/chumsky) parser generator to parse all strings in a
_nearly_ zero-copy and wicked fast fashion.

Most conveniently, parsing can be done by utilizing the standard
[`FromStr`](https://doc.rust-lang.org/std/str/trait.FromStr.html) implementations for the relevant types
(`Dice`, `Expr`, `Modifier`, and `Condition`):

```rust
use dicey::{
use tyche::{
dice::modifier::{Condition, Modifier},
Dice, Expr,
};
Expand All @@ -90,15 +90,15 @@ let cond: Condition = "<3".parse()?;
```

Alternatively, you can directly use the parsers for each type via its associated `GenParser::parser()` implementation
or the functions in the `dicey::parse` module.
or the functions in the `tyche::parse` module.

### Manually creating Dice

Programmatically constructing `Dice` to roll is painless, even with lots of chained modifiers,
thanks to its use of the builder pattern.

```rust
use dicey::{dice::modifier::Condition, Dice};
use tyche::{dice::modifier::Condition, Dice};

// Simple set of dice, no modifiers: 2d20
let d2d20 = Dice::new(2, 20);
Expand Down Expand Up @@ -126,7 +126,7 @@ The most suitable "default" roller implementation is `FastRand`, which generates
[`fastrand::Rng`](https://docs.rs/fastrand/latest/fastrand/struct.Rng.html) instance.

```rust
use dicey::dice::roller::FastRand as FastRandRoller;
use tyche::dice::roller::FastRand as FastRandRoller;

// Create a FastRand roller with the default thread-local fastrand::Rng
let mut roller = FastRandRoller::default();
Expand All @@ -139,7 +139,7 @@ let mut roller = FastRandRoller::new(rng);
Once you have a roller, you can roll a single die at a time or a whole set of `Dice` with it:

```rust
use dicey::dice::{roller::FastRand as FastRandRoller, Dice, Roller};
use tyche::dice::{roller::FastRand as FastRandRoller, Dice, Roller};

let mut roller = FastRandRoller::default();

Expand All @@ -162,7 +162,7 @@ Using a `Rolled` result, you can easily total the results of all rolled dice and
original dice set along with a list of each individual die roll.

```rust
use dicey::{
use tyche::{
dice::{roller::FastRand as FastRandRoller, Dice, Roller},
expr::Describe,
};
Expand Down Expand Up @@ -234,7 +234,7 @@ dice rolled. This separation allows for describing an expression in a detailed w
contains, in addition to a few other utilities.

```rust
use dicey::{
use tyche::{
dice::roller::FastRand as FastRandRoller,
expr::{Describe, Expr},
};
Expand Down Expand Up @@ -272,4 +272,4 @@ and word your commits descriptively.

## License

Dicey is licensed under the [LGPLv3](https://www.gnu.org/licenses/lgpl-3.0) license.
Tyche is licensed under the [LGPLv3](https://www.gnu.org/licenses/lgpl-3.0) license.
2 changes: 1 addition & 1 deletion benches/dice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::borrow::Cow;

use test::Bencher;

use dicey::{
use tyche::{
dice::{
roller::{FastRand as FastRandRoller, Roller},
Dice, DieRoll, Rolled,
Expand Down
8 changes: 4 additions & 4 deletions benches/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use test::Bencher;

use chumsky::Parser;

use dicey::dice::roller::FastRand as FastRandRoller;
use tyche::dice::roller::FastRand as FastRandRoller;

#[bench]
fn e2e_basic(b: &mut Bencher) {
let parser = dicey::parser();
let parser = tyche::parser();
let mut rng = FastRandRoller::default();
b.iter(|| parser.parse("4d8 + 4").unwrap().eval(&mut rng).unwrap().calc().unwrap());
}

#[bench]
fn e2e_complex(b: &mut Bencher) {
let parser = dicey::parser();
let parser = tyche::parser();
let mut rng = FastRandRoller::default();
b.iter(|| {
parser
Expand All @@ -32,7 +32,7 @@ fn e2e_complex(b: &mut Bencher) {

#[bench]
fn e2e_absurd(b: &mut Bencher) {
let parser = dicey::parser();
let parser = tyche::parser();
let mut rng = FastRandRoller::default();
let expr = include_str!("absurd_dice_expr.txt");
b.iter(|| parser.parse(expr).unwrap().eval(&mut rng).unwrap().calc().unwrap())
Expand Down
10 changes: 5 additions & 5 deletions benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
extern crate test;

use chumsky::Parser;
use dicey::expr::Expr;
use test::Bencher;
use tyche::expr::Expr;

const ABSURD_EXPR: &str = include_str!("absurd_dice_expr.txt");

#[bench]
fn parse_basic(b: &mut Bencher) {
let parser = dicey::parser();
let parser = tyche::parser();
b.iter(|| parser.parse("4d8 + 4").unwrap());
}

#[bench]
fn parse_complex(b: &mut Bencher) {
let parser = dicey::parser();
let parser = tyche::parser();
b.iter(|| parser.parse("4d8x + 2d10 * (-3d6 - 6 / 2 \\ 4)").unwrap());
}

#[bench]
fn parse_absurd(b: &mut Bencher) {
let parser = dicey::parser();
let parser = tyche::parser();
b.iter(|| parser.parse(ABSURD_EXPR).unwrap())
}

#[bench]
fn parser_creation(b: &mut Bencher) {
b.iter(dicey::parser);
b.iter(tyche::parser);
}

#[bench]
Expand Down
20 changes: 10 additions & 10 deletions src/dice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ impl fmt::Display for DieRoll {
///
/// # Examples
/// ```
/// use dicey::dice::DieRoll;
/// use tyche::dice::DieRoll;
///
/// let roll = DieRoll::new(4);
/// assert_eq!(roll.to_string(), "4");
/// ```
///
/// ```
/// use dicey::dice::{DieRoll, Modifier};
/// use tyche::dice::{DieRoll, Modifier};
///
/// let mut roll = DieRoll::new(16);
/// let kh_mod = Modifier::KeepHigh(1);
Expand Down Expand Up @@ -253,13 +253,13 @@ impl Rolled<'_> {
///
/// # Examples
/// ```
/// use dicey::dice::{roller::{FastRand as FastRandRoller, Roller}, Dice};
/// use tyche::dice::{roller::{FastRand as FastRandRoller, Roller}, Dice};
///
/// let dice = Dice::new(4, 8);
/// let rolled = FastRandRoller::default().roll(&dice, true)?;
/// let total = rolled.total()?;
/// assert_eq!(total, rolled.rolls.iter().map(|roll| roll.val as u16).sum());
/// # Ok::<(), dicey::dice::Error>(())
/// # Ok::<(), tyche::dice::Error>(())
/// ```
pub fn total(&self) -> Result<u16, Error> {
let mut sum: u16 = 0;
Expand Down Expand Up @@ -304,7 +304,7 @@ impl Describe for Rolled<'_> {
/// # Examples
/// ```
/// use std::borrow::Cow;
/// use dicey::{dice::{Dice, DieRoll, Rolled}, expr::Describe};
/// use tyche::{dice::{Dice, DieRoll, Rolled}, expr::Describe};
///
/// let dice = Dice::builder().count(4).sides(6).keep_high(2).build();
/// let kh_mod = dice.modifiers[0];
Expand Down Expand Up @@ -378,7 +378,7 @@ pub enum Error {
///
/// # Examples
/// ```
/// use dicey::dice::{roller::{FastRand as FastRandRoller, Roller}, Dice, Error};
/// use tyche::dice::{roller::{FastRand as FastRandRoller, Roller}, Dice, Error};
///
/// let dice = Dice::builder().count(4).sides(1).explode(None, true).build();
/// assert!(matches!(FastRandRoller::default().roll(&dice, true), Err(Error::InfiniteRolls(..))));
Expand All @@ -390,7 +390,7 @@ pub enum Error {
///
/// # Examples
/// ```
/// use dicey::dice::{modifier::Condition, Error};
/// use tyche::dice::{modifier::Condition, Error};
///
/// let cond = Condition::from_symbol_and_val("!", 4);
/// assert!(matches!(cond, Err(Error::UnknownCondition(..))));
Expand All @@ -405,15 +405,15 @@ pub enum Error {
///
/// ## Basic dice
/// ```
/// use dicey::Dice;
/// use tyche::Dice;
///
/// let dice = Dice::builder().count(2).sides(6).build();
/// assert_eq!(dice, Dice::new(2, 6));
/// ```
///
/// ## Single modifier
/// ```
/// use dicey::dice::{Dice, Modifier};
/// use tyche::dice::{Dice, Modifier};
///
/// let dice = Dice::builder().count(6).sides(8).explode(None, true).build();
/// assert_eq!(
Expand All @@ -431,7 +431,7 @@ pub enum Error {
///
/// ## Multiple modifiers
/// ```
/// use dicey::dice::{modifier::{Condition, Modifier}, Dice};
/// use tyche::dice::{modifier::{Condition, Modifier}, Dice};
///
/// let dice = Dice::builder()
/// .count(6)
Expand Down
Loading

0 comments on commit 4596490

Please sign in to comment.