Skip to main content

eldiron_shared/
character.rs

1use codegridfx::Module;
2use num_traits::zero;
3use rusterix::Map;
4use theframework::prelude::*;
5
6/// The data for a character instance.
7#[derive(Serialize, Deserialize, Clone, Debug)]
8pub struct Character {
9    pub id: Uuid,
10    pub name: String,
11
12    /// The character map model.
13    pub map: Map,
14
15    /// The module source
16    #[serde(default)]
17    pub module: Module,
18
19    /// The instance initialization or template code.
20    pub source: String,
21
22    /// The instance initialization or template debug code.
23    #[serde(default)]
24    pub source_debug: String,
25
26    /// The attributes toml data.
27    #[serde(default)]
28    pub data: String,
29
30    /// Authoring metadata used for look/description style presentation.
31    #[serde(default)]
32    pub authoring: String,
33
34    /// Editor-only rigging preview TOML data.
35    #[serde(default)]
36    pub preview_rigging: String,
37
38    /// The initial position.
39    pub position: Vec3<f32>,
40
41    /// Initial facing direction in XZ (cardinal/editor-driven).
42    #[serde(default = "default_orientation")]
43    pub orientation: Vec2<f32>,
44
45    /// The id of the character template.
46    pub character_id: Uuid,
47}
48
49impl Default for Character {
50    fn default() -> Self {
51        Self::new()
52    }
53}
54
55impl Character {
56    pub fn new() -> Self {
57        Self {
58            id: Uuid::new_v4(),
59            name: "NewCharacter".to_string(),
60
61            module: Module::as_type(codegridfx::ModuleType::CharacterTemplate),
62
63            map: Map::default(),
64            source: String::new(),
65            source_debug: String::new(),
66            data: String::new(),
67            authoring: String::new(),
68            preview_rigging: String::new(),
69            position: zero(),
70            orientation: default_orientation(),
71
72            character_id: Uuid::new_v4(),
73        }
74    }
75}
76
77fn default_orientation() -> Vec2<f32> {
78    Vec2::new(1.0, 0.0)
79}