1use crate::prelude::*;
2pub use rusterix::map::*;
3use theframework::prelude::*;
4
5fn default_editing_look_at_3d() -> Vec3<f32> {
6 Vec3::new(2.0, 0.0, 0.0)
7}
8
9#[derive(Serialize, Deserialize, Clone, Debug)]
10pub struct Region {
11 pub id: Uuid,
12
13 pub name: String,
14 pub map: Map,
15
16 #[serde(default)]
17 pub config: String,
18
19 pub characters: IndexMap<Uuid, Character>,
20 pub items: IndexMap<Uuid, Item>,
21
22 pub editing_position_3d: Vec3<f32>,
23 #[serde(default = "default_editing_look_at_3d")]
24 pub editing_look_at_3d: Vec3<f32>,
25
26 #[serde(default)]
28 pub editing_position_iso_3d: Option<Vec3<f32>>,
29 #[serde(default)]
30 pub editing_look_at_iso_3d: Option<Vec3<f32>>,
31 #[serde(default)]
32 pub editing_position_orbit_3d: Option<Vec3<f32>>,
33 #[serde(default)]
34 pub editing_look_at_orbit_3d: Option<Vec3<f32>>,
35 #[serde(default)]
36 pub editing_position_firstp_3d: Option<Vec3<f32>>,
37 #[serde(default)]
38 pub editing_look_at_firstp_3d: Option<Vec3<f32>>,
39 #[serde(default)]
40 pub editing_iso_scale: Option<f32>,
41 #[serde(default)]
42 pub editing_orbit_distance: Option<f32>,
43}
44
45impl Default for Region {
46 fn default() -> Self {
47 Self::new()
48 }
49}
50
51impl PartialEq for Region {
52 fn eq(&self, other: &Self) -> bool {
53 self.id == other.id
54 }
55}
56
57impl Region {
58 pub fn new() -> Self {
59 Self {
60 id: Uuid::new_v4(),
61 name: "New Region".to_string(),
62
63 map: Map::default(),
64 config: String::new(),
65
66 characters: IndexMap::default(),
67 items: IndexMap::default(),
68
69 editing_position_3d: Vec3::zero(),
70 editing_look_at_3d: Vec3::zero(),
71 editing_position_iso_3d: None,
72 editing_look_at_iso_3d: None,
73 editing_position_orbit_3d: None,
74 editing_look_at_orbit_3d: None,
75 editing_position_firstp_3d: None,
76 editing_look_at_firstp_3d: None,
77 editing_iso_scale: None,
78 editing_orbit_distance: None,
79 }
80 }
81
82 pub fn from_json(json: &str) -> Self {
84 serde_json::from_str(json).unwrap_or(Region::new())
85 }
86
87 pub fn to_json(&self) -> String {
89 serde_json::to_string(&self).unwrap_or_default()
90 }
91}