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    /// Editor-only rigging preview TOML data.
31    #[serde(default)]
32    pub preview_rigging: String,
33
34    /// The initial position.
35    pub position: Vec3<f32>,
36
37    /// Initial facing direction in XZ (cardinal/editor-driven).
38    #[serde(default = "default_orientation")]
39    pub orientation: Vec2<f32>,
40
41    /// The id of the character template.
42    pub character_id: Uuid,
43}
44
45impl Default for Character {
46    fn default() -> Self {
47        Self::new()
48    }
49}
50
51impl Character {
52    pub fn new() -> Self {
53        Self {
54            id: Uuid::new_v4(),
55            name: "NewCharacter".to_string(),
56
57            module: Module::as_type(codegridfx::ModuleType::CharacterTemplate),
58
59            map: Map::default(),
60            source: String::new(),
61            source_debug: String::new(),
62            data: String::new(),
63            preview_rigging: String::new(),
64            position: zero(),
65            orientation: default_orientation(),
66
67            character_id: Uuid::new_v4(),
68        }
69    }
70}
71
72fn default_orientation() -> Vec2<f32> {
73    Vec2::new(1.0, 0.0)
74}