glitcher_core/
asset.rs

1//! Asset type definition shared across Glitcher crates
2//!
3//! Only `AssetType` is defined here as it's shared between:
4//! - glitcher-registry (OCI distribution)
5//! - glitcher-asset (asset management)
6//! - glitcher-loader (WASM loading)
7//!
8//! All other asset-related types and traits are in glitcher-asset.
9
10use serde::{Deserialize, Serialize};
11
12/// Asset type for registry distribution and local cache
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14#[serde(rename_all = "lowercase")]
15pub enum AssetType {
16    /// MOD (WASM module)
17    Mod,
18    /// Patch (node graph configuration, .gltpatch)
19    Patch,
20    /// Setup (multi-phrase performance, .yaml)
21    Setup,
22    /// Collection (asset library, .zip)
23    Collection,
24    /// Texture (Image/Video asset)
25    ///
26    /// Note: Textures are cache-only assets, not distributed via Registry.
27    /// They are embedded in Patches or managed locally via AssetCacheIndex.
28    Texture,
29}
30
31impl AssetType {
32    /// Get path segment for this asset type (used in registry paths)
33    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    /// Get display name for UI
44    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    /// Get file extension for this asset type
55    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", // Default, actual varies
62        }
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}