Skip to main content

wowlab_engine_combat/state/combat_state/
config_access.rs

1use super::{CombatState, SpecConfig, SpecRuntime};
2
3impl CombatState {
4    /// Downcast the opaque per-spec config to `T`, or `None` if it is a different type.
5    #[inline]
6    #[must_use]
7    pub fn spec_config<T>(&self) -> Option<&T>
8    where
9        T: SpecConfig,
10    {
11        self.config
12            .spec_config
13            .as_ref()
14            .as_any()
15            .downcast_ref::<T>()
16    }
17
18    /// Downcast the mutable per-spec runtime state to `T`.
19    #[inline]
20    #[must_use]
21    pub fn spec_runtime<T>(&self) -> Option<&T>
22    where
23        T: SpecRuntime,
24    {
25        self.runtime
26            .spec_runtime
27            .as_ref()
28            .as_any()
29            .downcast_ref::<T>()
30    }
31
32    /// Mutable downcast of the per-spec runtime state to `T`.
33    #[inline]
34    pub fn spec_runtime_mut<T>(&mut self) -> Option<&mut T>
35    where
36        T: SpecRuntime,
37    {
38        self.runtime
39            .spec_runtime
40            .as_mut()
41            .as_any_mut()
42            .downcast_mut::<T>()
43    }
44
45    /// Replace the immutable per-spec configuration.
46    #[inline]
47    pub fn set_spec_config<T>(&mut self, config: T)
48    where
49        T: SpecConfig,
50    {
51        self.config.spec_config = Box::new(config);
52    }
53
54    /// Whether a registered live-game bug is modeled in this run.
55    #[inline]
56    #[must_use]
57    pub fn bug_enabled(&self, bug: &wowlab_engine_ports::GameBug) -> bool {
58        self.config.bugs.enabled(bug)
59    }
60
61    /// Replace the resettable per-spec runtime state.
62    #[inline]
63    pub fn set_spec_runtime<T>(&mut self, runtime: T)
64    where
65        T: SpecRuntime,
66    {
67        self.runtime.spec_runtime = Box::new(runtime);
68    }
69}