Skip to main content

dreamwell_engine/physics/
materials.rs

1use serde::{Deserialize, Serialize};
2
3/// Material class — determines visual and interaction behavior.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum MaterialClass {
6    Organic,
7    Wood,
8    Stone,
9    Metal,
10    Glass,
11    Liquid,
12    Gas,
13    Energy,
14    Synthetic,
15    Dreammatter,
16    CorruptMatter,
17}
18
19impl MaterialClass {
20    /// All material classes.
21    pub const ALL: &[MaterialClass] = &[
22        Self::Organic,
23        Self::Wood,
24        Self::Stone,
25        Self::Metal,
26        Self::Glass,
27        Self::Liquid,
28        Self::Gas,
29        Self::Energy,
30        Self::Synthetic,
31        Self::Dreammatter,
32        Self::CorruptMatter,
33    ];
34
35    /// Display name.
36    pub fn name(&self) -> &'static str {
37        match self {
38            Self::Organic => "Organic",
39            Self::Wood => "Wood",
40            Self::Stone => "Stone",
41            Self::Metal => "Metal",
42            Self::Glass => "Glass",
43            Self::Liquid => "Liquid",
44            Self::Gas => "Gas",
45            Self::Energy => "Energy",
46            Self::Synthetic => "Synthetic",
47            Self::Dreammatter => "Dreammatter",
48            Self::CorruptMatter => "Corrupt Matter",
49        }
50    }
51
52    /// Default flammability (0.0 = not flammable, 1.0 = highly flammable).
53    pub fn default_flammability(&self) -> f32 {
54        match self {
55            Self::Organic => 0.7,
56            Self::Wood => 0.9,
57            Self::Stone => 0.0,
58            Self::Metal => 0.0,
59            Self::Glass => 0.0,
60            Self::Liquid => 0.1,
61            Self::Gas => 0.5,
62            Self::Energy => 0.0,
63            Self::Synthetic => 0.3,
64            Self::Dreammatter => 0.0,
65            Self::CorruptMatter => 0.0,
66        }
67    }
68
69    /// Default conductivity.
70    pub fn default_conductivity(&self) -> f32 {
71        match self {
72            Self::Metal => 1.0,
73            Self::Liquid => 0.5,
74            Self::Organic => 0.1,
75            _ => 0.0,
76        }
77    }
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn material_class_all_count() {
86        assert_eq!(MaterialClass::ALL.len(), 11);
87    }
88
89    #[test]
90    fn material_class_serde_roundtrip() {
91        for &mat in MaterialClass::ALL {
92            let json = serde_json::to_string(&mat).unwrap();
93            let restored: MaterialClass = serde_json::from_str(&json).unwrap();
94            assert_eq!(mat, restored);
95        }
96    }
97
98    #[test]
99    fn material_class_name() {
100        assert_eq!(MaterialClass::Stone.name(), "Stone");
101        assert_eq!(MaterialClass::CorruptMatter.name(), "Corrupt Matter");
102    }
103}