1use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14#[serde(rename_all = "lowercase")]
15pub enum AssetType {
16 Mod,
18 Patch,
20 Setup,
22 Collection,
24 Texture,
29}
30
31impl AssetType {
32 pub fn path_segment(&self) -> &'static str {
34 match self {
35 AssetType::Mod => "mods",
36 AssetType::Patch => "patches",
37 AssetType::Setup => "setups",
38 AssetType::Collection => "collections",
39 AssetType::Texture => "textures",
40 }
41 }
42
43 pub fn display_name(&self) -> &'static str {
45 match self {
46 AssetType::Mod => "MOD",
47 AssetType::Patch => "Patch",
48 AssetType::Setup => "Setup",
49 AssetType::Collection => "Collection",
50 AssetType::Texture => "Texture",
51 }
52 }
53
54 pub fn extension(&self) -> &'static str {
56 match self {
57 AssetType::Mod => "wasm",
58 AssetType::Patch => "gltpatch",
59 AssetType::Setup => "yaml",
60 AssetType::Collection => "zip",
61 AssetType::Texture => "png", }
63 }
64}
65
66impl std::fmt::Display for AssetType {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 write!(f, "{}", self.display_name())
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn test_asset_type_display() {
78 assert_eq!(AssetType::Mod.display_name(), "MOD");
79 assert_eq!(AssetType::Patch.display_name(), "Patch");
80 assert_eq!(AssetType::Texture.display_name(), "Texture");
81 }
82
83 #[test]
84 fn test_asset_type_path_segment() {
85 assert_eq!(AssetType::Mod.path_segment(), "mods");
86 assert_eq!(AssetType::Patch.path_segment(), "patches");
87 assert_eq!(AssetType::Setup.path_segment(), "setups");
88 }
89}