~starkingdoms/starkingdoms

ref: 16ef421ba4cdf5ba7be055945b9e4ddb1e4759b8 starkingdoms/client/src/textures/mod.rs -rw-r--r-- 1.4 KiB
16ef421b — c0repwn3r merge 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!("You cannot use both texture loaders. Please only enable one of the textures-fast or textures-slow feature.");
#[cfg(not(any(feature = "textures-fast", feature = "textures-slow")))]
compile_error!("You need to enable a texture loader. Please enable one of the textures-fast, textures-slow feature.");

#[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(())
        }
    }
}