pub struct ResolvedStat {
pub stat_id: StatId,
pub value: StatValue,
pub sources: Vec<(String, StatValue)>,
pub transforms: Vec<(String, StatValue)>,
}Expand description
A resolved stat value with full breakdown information.
This is read-only, copyable, network-safe, and replay-safe. Contains the final value along with a complete breakdown of all sources and transforms that contributed to it.
§Examples
use zzstat::ResolvedStat;
use zzstat::StatId;
let mut resolved = ResolvedStat::new(StatId::from("HP"), 150.0);
resolved.add_source("Base", 100.0);
resolved.add_source("Item", 50.0);
resolved.add_transform("Multiplier 1.5x", 150.0);
assert_eq!(resolved.value, 150.0);
assert_eq!(resolved.sources.len(), 2);
assert_eq!(resolved.transforms.len(), 1);Fields§
§stat_id: StatIdThe stat identifier.
value: StatValueThe final resolved value.
sources: Vec<(String, StatValue)>Breakdown of all contributing sources.
Each entry is (source_description, value).
Sources are listed in the order they were registered.
transforms: Vec<(String, StatValue)>Breakdown of all applied transforms.
Each entry is (transform_description, value_after_transform).
Transforms are listed in the order they were applied.
Implementations§
Source§impl ResolvedStat
impl ResolvedStat
Sourcepub fn new(stat_id: StatId, value: StatValue) -> Self
pub fn new(stat_id: StatId, value: StatValue) -> Self
Create a new ResolvedStat with the given stat ID and value.
The sources and transforms vectors start empty and can be
populated using add_source() and add_transform().
§Examples
use zzstat::ResolvedStat;
use zzstat::StatId;
let resolved = ResolvedStat::new(StatId::from("HP"), 100.0);
assert_eq!(resolved.value, 100.0);Sourcepub fn add_source(&mut self, description: impl Into<String>, value: StatValue)
pub fn add_source(&mut self, description: impl Into<String>, value: StatValue)
Add a source contribution to the breakdown.
This is typically called by the resolver during stat resolution to build up the breakdown information.
§Arguments
description- Human-readable description of the sourcevalue- The value contributed by this source
§Examples
use zzstat::ResolvedStat;
use zzstat::StatId;
let mut resolved = ResolvedStat::new(StatId::from("HP"), 150.0);
resolved.add_source("Base HP", 100.0);
resolved.add_source("Item Bonus", 50.0);Sourcepub fn add_transform(
&mut self,
description: impl Into<String>,
value: StatValue,
)
pub fn add_transform( &mut self, description: impl Into<String>, value: StatValue, )
Add a transform application to the breakdown.
This is typically called by the resolver during stat resolution to build up the breakdown information.
§Arguments
description- Human-readable description of the transformvalue- The value after applying this transform
§Examples
use zzstat::ResolvedStat;
use zzstat::StatId;
let mut resolved = ResolvedStat::new(StatId::from("ATK"), 150.0);
resolved.add_transform("Multiplier 1.5x", 150.0);Trait Implementations§
Source§impl Clone for ResolvedStat
impl Clone for ResolvedStat
Source§fn clone(&self) -> ResolvedStat
fn clone(&self) -> ResolvedStat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more