use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaterialClass {
Organic,
Wood,
Stone,
Metal,
Glass,
Liquid,
Gas,
Energy,
Synthetic,
Dreammatter,
CorruptMatter,
}
impl MaterialClass {
pub const ALL: &[MaterialClass] = &[
Self::Organic,
Self::Wood,
Self::Stone,
Self::Metal,
Self::Glass,
Self::Liquid,
Self::Gas,
Self::Energy,
Self::Synthetic,
Self::Dreammatter,
Self::CorruptMatter,
];
pub fn name(&self) -> &'static str {
match self {
Self::Organic => "Organic",
Self::Wood => "Wood",
Self::Stone => "Stone",
Self::Metal => "Metal",
Self::Glass => "Glass",
Self::Liquid => "Liquid",
Self::Gas => "Gas",
Self::Energy => "Energy",
Self::Synthetic => "Synthetic",
Self::Dreammatter => "Dreammatter",
Self::CorruptMatter => "Corrupt Matter",
}
}
pub fn default_flammability(&self) -> f32 {
match self {
Self::Organic => 0.7,
Self::Wood => 0.9,
Self::Stone => 0.0,
Self::Metal => 0.0,
Self::Glass => 0.0,
Self::Liquid => 0.1,
Self::Gas => 0.5,
Self::Energy => 0.0,
Self::Synthetic => 0.3,
Self::Dreammatter => 0.0,
Self::CorruptMatter => 0.0,
}
}
pub fn default_conductivity(&self) -> f32 {
match self {
Self::Metal => 1.0,
Self::Liquid => 0.5,
Self::Organic => 0.1,
_ => 0.0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn material_class_all_count() {
assert_eq!(MaterialClass::ALL.len(), 11);
}
#[test]
fn material_class_serde_roundtrip() {
for &mat in MaterialClass::ALL {
let json = serde_json::to_string(&mat).unwrap();
let restored: MaterialClass = serde_json::from_str(&json).unwrap();
assert_eq!(mat, restored);
}
}
#[test]
fn material_class_name() {
assert_eq!(MaterialClass::Stone.name(), "Stone");
assert_eq!(MaterialClass::CorruptMatter.name(), "Corrupt Matter");
}
}