fn load_texture_anim<F, T>(
    factory: &mut F,
    cache: &mut HashMap<String, Rc<[Rc<T>]>>,
    dir: &path::Path,
    default_dir: &path::Path,
    names: &(&'static str, String),
    texture_settings: &TextureSettings,
) -> Result<Rc<[Rc<T>]>, ParseError>
where
    T: CreateTexture<F>,
    T::Error: ToString,
{
    let mut textures = Vec::new();
    let mut path;

    macro_rules! repetitive_code {
        // $dir should be a path::Path
        ($(($dir:ident, $name:expr)),*) => {$(

            // Check the cache
            if let Some(texture) = cache.get(&$name) {
                return Ok(Rc::clone(texture));
            }

            // TODO can these join's be optimized? how much time does it take to allocate the pathbuf?

            // Check for an animation sequence
            path = $dir.join($name + "-0.png");
            if path.exists() {
                textures.push(Rc::new(texture_from_path(factory, &path, texture_settings)?));
                let mut n = 1;
                loop {
                    path = $dir.join(format!("{}-{}.png", $name, n));
                    if !path.exists() { break; }
                    textures.push(Rc::new(texture_from_path(factory, &path, texture_settings)?));
                    n += 1;
                }
                let anim = Rc::from(textures);
                cache.insert($name, Rc::clone(&anim));
                return Ok(anim);
            }

            // Check for static image
            path = $dir.join($name + ".png");
            if path.exists() {
                // help
                let texture = Rc::new(texture_from_path(factory, &path, texture_settings)?);
                let anim = Rc::from(&[texture][..]);
                cache.insert($name, Rc::clone(&anim));
                return Ok(anim);
            }
        )*}
    }

    // Check the skin directory, then the default skin directory
    repetitive_code!((dir, names.1.clone()), (default_dir, names.0.to_owned()));

    Err(OsuSkinParseError::NoDefaultTexture(String::from(names.0)).into())
}
/// Load an animatable skin element's textures
///
/// This function takes the basename and tries different paths until it finds one that exists
Load an animatable skin element's textures
This function takes the basename and tries different paths until it finds one that exists
Load an animatable skin element ' s textures This function takes the basename and tries different paths until it finds one that exists
fn load_texture_anim<F, T>(
    factory: &mut F,
    cache: &mut HashMap<String, Rc<[Rc<T>]>>,
    dir: &path::Path,
    default_dir: &path::Path,
    names: &(&'static str, String),
    texture_settings: &TextureSettings,
) -> Result<Rc<[Rc<T>]>, ParseError>
where
    T: CreateTexture<F>,
    T::Error: ToString,
{
    let mut textures = Vec::new();
    let mut path;
    macro_rules! repetitive_code {
        // $dir should be a path::Path
        ($(($dir:ident, $name:expr)),*) => {$(
            // Check the cache
            if let Some(texture) = cache.get(&$name) {
                return Ok(Rc::clone(texture));
            }
            // TODO can these join's be optimized? how much time does it take to allocate the pathbuf?
            // Check for an animation sequence
            path = $dir.join($name + "-0.png");
            if path.exists() {
                textures.push(Rc::new(texture_from_path(factory, &path, texture_settings)?));
                let mut n = 1;
                loop {
                    path = $dir.join(format!("{}-{}.png", $name, n));
                    if !path.exists() { break; }
                    textures.push(Rc::new(texture_from_path(factory, &path, texture_settings)?));
                    n += 1;
                }
                let anim = Rc::from(textures);
                cache.insert($name, Rc::clone(&anim));
                return Ok(anim);
            }
            // Check for static image
            path = $dir.join($name + ".png");
            if path.exists() {
                // help
                let texture = Rc::new(texture_from_path(factory, &path, texture_settings)?);
                let anim = Rc::from(&[texture][..]);
                cache.insert($name, Rc::clone(&anim));
                return Ok(anim);
            }
        )*}
    }
    // Check the skin directory, then the default skin directory
    repetitive_code!((dir, names.1.clone()), (default_dir, names.0.to_owned()));
    Err(OsuSkinParseError::NoDefaultTexture(String::from(names.0)).into())
}
fn load_texture_anim < F , T > ( factory : & mut F , cache : & mut HashMap < String , Rc < [ Rc < T > ] > > , dir : & path :: Path , default_dir : & path :: Path , names : & ( & ' static str , String ) , texture_settings : & TextureSettings , ) -> Result < Rc < [ Rc < T > ] > , ParseError > where T : CreateTexture < F > , T :: Error : ToString , { let mut textures = Vec :: new ( ) ; let mut path ; macro_rules! repetitive_code { // $dir should be a path::Path ( $ ( ( $dir : ident $name : expr ) ) * ) => { $ ( // Check the cache if let Some ( texture ) cache get ( $name ) { return Ok ( Rc clone ( texture ) ) } // TODO can these join's be optimized? how much time does it take to allocate the pathbuf? // Check for an animation sequence path $dir join ( $name " " ) if path exists ( ) { textures push ( Rc new ( texture_from_path ( factory path texture_settings ) ) ) let mut n 1 loop { path $dir join ( format ( " " $name n ) ) if path exists ( ) { break } textures push ( Rc new ( texture_from_path ( factory path texture_settings ) ) ) n 1 } let anim Rc from ( textures ) cache insert ( $name Rc clone ( anim ) ) return Ok ( anim ) } // Check for static image path $dir join ( $name " " ) if path exists ( ) { // help let texture Rc new ( texture_from_path ( factory path texture_settings ) ) let anim Rc from ( [ texture ] [ ] ) cache insert ( $name Rc clone ( anim ) ) return Ok ( anim ) } ) * } } // Check the skin directory, then the default skin directory repetitive_code ! ( ( dir names 1 clone ( ) ) ( default_dir names 0 to_owned ( ) ) ) ; Err ( OsuSkinParseError :: NoDefaultTexture ( String :: from ( names . 0 ) ) . into ( ) ) }
Load an animatable skin element's textures
This function takes the basename and tries different paths until it finds one that exists
Load an animatable skin element ' s textures This function takes the basename and tries different paths until it finds one that exists
factory
&mut F
cache
&mut HashMap<String, Rc<[Rc<T>]>>
dir
&path::Path
default_dir
&path::Path
names
&(&'static str, String)
texture_settings
&TextureSettings
factory
&mut F
cache
&mut HashMap<String, Rc<[Rc<T>]>>
dir
&path::Path
default_dir
&path::Path
names
&(&'static str, String)
texture_settings
&TextureSettings