commonlibsse_ng\re\a\Actor/
local_map.rs

1use crate::re::ActorValues::{ACTOR_VALUE_MODIFIER_CEnum, ActorValue};
2use crate::re::BSFixedString::BSFixedString;
3
4#[commonlibsse_ng_derive_internal::ffi_enum]
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6#[repr(u32)]
7pub enum ACTOR_CRITICAL_STAGE {
8    None = 0,
9    GooStart = 1,
10    GooEnd = 2,
11    DisintegrateStart = 3,
12    DisintegrateEnd = 4,
13}
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct Modifiers {
17    pub modifiers: [f32; ACTOR_VALUE_MODIFIER_CEnum::count()],
18}
19const _: () = assert!(core::mem::size_of::<Modifiers>() == 0xC);
20
21#[derive(Debug, Clone, PartialEq)]
22pub struct ActorValueStorage {
23    pub base_values: LocalMap<f32>,
24    pub modifiers: LocalMap<Modifiers>,
25}
26
27#[derive(Debug, Clone, PartialEq)]
28pub struct LocalMap<T> {
29    pub actor_values: BSFixedString,
30    pub entries: *mut T,
31}
32
33impl<T> LocalMap<T> {
34    pub fn get(&self, actor_value: ActorValue) -> Option<&T> {
35        let ak_vals = self.actor_values.as_bytes_with_null();
36
37        if ak_vals.is_empty() && self.entries.is_null() {
38            return None;
39        }
40
41        let mut idx = 0;
42        while idx < ak_vals.len() && ak_vals[idx] != b'\0' {
43            if ak_vals[idx] == actor_value as u8 {
44                return unsafe { self.entries.add(idx).as_ref() };
45            }
46            idx += 1;
47        }
48
49        None
50    }
51
52    pub fn get_mut(&self, actor_value: ActorValue) -> Option<&mut T> {
53        let ak_vals = self.actor_values.as_bytes_with_null();
54
55        if ak_vals.is_empty() && self.entries.is_null() {
56            return None;
57        }
58
59        let mut idx = 0;
60        while idx < ak_vals.len() && ak_vals[idx] != b'\0' {
61            if ak_vals[idx] == actor_value as u8 {
62                return unsafe { self.entries.add(idx).as_mut() };
63            }
64            idx += 1;
65        }
66
67        None
68    }
69}
70
71impl<T> core::ops::Index<ActorValue> for LocalMap<T> {
72    type Output = T;
73
74    fn index(&self, actor_value: ActorValue) -> &Self::Output {
75        self.get(actor_value).expect("ActorValue not found")
76    }
77}
78
79impl<T> core::ops::IndexMut<ActorValue> for LocalMap<T> {
80    fn index_mut(&mut self, actor_value: ActorValue) -> &mut Self::Output {
81        self.get_mut(actor_value).expect("ActorValue not found")
82    }
83}