#[non_exhaustive]pub struct DieRoll {
pub val: u8,
pub added_by: Option<Modifier>,
pub dropped_by: Option<Modifier>,
pub changes: Vec<ValChange>,
}
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.val: u8
Value that was rolled
added_by: Option<Modifier>
Modifier that caused the addition of this die, if any
dropped_by: Option<Modifier>
Modifier that caused the drop of this die, if any
changes: Vec<ValChange>
Modifications that were made to the value of the roll
Implementations§
Source§impl DieRoll
impl DieRoll
Sourcepub fn add(&mut self, from: Modifier)
pub fn add(&mut self, from: Modifier)
Marks this die roll as added by a given modifier, setting Self::added_by
.
§Panics
Panics if Self::added_by
is already Some
.
Sourcepub fn drop(&mut self, from: Modifier)
pub fn drop(&mut self, from: Modifier)
Marks this die roll as dropped by a given modifier, setting Self::dropped_by
.
§Panics
Panics if Self::dropped_by
is already Some
.
Sourcepub fn change(&mut self, from: Modifier, new_val: u8)
pub fn change(&mut self, from: Modifier, new_val: u8)
Replaces the die roll’s value and logs the change made.
Sourcepub const fn is_original(&self) -> bool
pub const fn is_original(&self) -> bool
Indicates whether this die roll was part of the original set (not added by a modifier).
Sourcepub const fn is_additional(&self) -> bool
pub const fn is_additional(&self) -> bool
Indicates whether this die roll was added as the result of a modifier being applied.
This is the direct inverse of DieRoll::is_original()
.
Sourcepub const fn is_dropped(&self) -> bool
pub const fn is_dropped(&self) -> bool
Indicates whether this die roll has been dropped by a modifier.
Sourcepub const fn is_kept(&self) -> bool
pub const fn is_kept(&self) -> bool
Indicates whether this die roll is being kept (has not been dropped by a modifier).
This is the direct inverse of DieRoll::is_dropped()
.
Sourcepub fn is_changed(&self) -> bool
pub fn is_changed(&self) -> bool
Indicates whether this die roll’s value has been directly changed by a modifier.
Trait Implementations§
Source§impl Display for DieRoll
impl Display for DieRoll
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
The format of a die roll is simply the plain numeric value of the roll.
If the roll was dropped, it is appended with (d)
.
§Examples
use tyche::dice::DieRoll;
let roll = DieRoll::new(4);
assert_eq!(roll.to_string(), "4");
use tyche::dice::{DieRoll, Modifier};
let mut roll = DieRoll::new(16);
let kh_mod = Modifier::KeepHigh(1);
roll.drop(kh_mod);
assert_eq!(roll.to_string(), "16 (d)");