~starkingdoms/starkingdoms

ref: 63975cc0a233df1da0d741ce5e246b08059d20e4 starkingdoms/client/src/textures/mod.rs -rw-r--r-- 1.4 KiB
63975cc0 — c0repwn3r extend module system in client 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::error::Error;
use std::str::FromStr;

#[cfg(all(feature = "textures-fast", feature = "textures-slow"))]
compile_error!("Mutually exclusive modules textures-fast and textures-slow selected.");
#[cfg(not(any(feature = "textures-fast", feature = "textures-slow")))]
compile_error!("Required feature textures not specified. Please specify one of textures-fast, textures-slow");

#[cfg(feature = "textures-fast")]
#[path = "loader_fast.rs"]
pub mod loader;

#[cfg(feature = "textures-slow")]
#[path = "loader_slow.rs"]
pub mod loader;

pub trait TextureManager {
    fn load(size: TextureSize) -> Result<Self, Box<dyn Error>> where Self: Sized;
    fn get_texture(&self, texture_id: &str) -> Option<String>;
}

#[derive(Debug, Copy, Clone)]
pub enum TextureSize {
    Full,
    Scaled375,
    Scaled125
}
impl ToString for TextureSize {
    fn to_string(&self) -> String {
        match self {
            TextureSize::Full => "full".to_string(),
            TextureSize::Scaled375 => "375".to_string(),
            TextureSize::Scaled125 => "125".to_string()
        }
    }
}
impl FromStr for TextureSize {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "full" => Ok(TextureSize::Full),
            "375" => Ok(TextureSize::Scaled375),
            "125" => Ok(TextureSize::Scaled125),
            _ => Err(())
        }
    }
}