fn load_slc_file(path: &Path) -> Result<Vec<Level>, error::SokobanError> {
    let mut collection = Vec::new();
    let file = try!(File::open(&path));
    let reader = BufReader::new(file);
    let parser = EventReader::new(reader);

    let mut level_title = String::new();
    let mut level_str = String::new();
    let mut reading_level = false;
    for e in parser {
        match e {
            Ok(XmlEvent::StartElement { ref name, ref attributes, .. }) => {
                if name.local_name == "L" {
                    reading_level = true;
                } else if name.local_name == "Level" {
                    if let Some(id) = attributes.iter().find(|&attr| attr.name.local_name == "Id") {
                        level_title = id.value.clone();
                    }
                }
            }
            Ok(XmlEvent::EndElement { name }) => {
                if name.local_name == "Level" {
                    let mut level = try!(Level::from_str(&level_str));
                    level.set_title(level_title.clone());
                    collection.push(level);
                    level_str.clear();
                }
            }
            Ok(XmlEvent::Characters(ref data)) => {
                if reading_level {
                    level_str.push_str(data);
                    level_str.push('\n');
                }
            }
            _ => {}
        }
    }

    Ok(collection)
}
/// Builds levels from a level collection file in the SLC format.
Builds levels from a level collection file in the SLC format.
Builds levels from a level collection file in the SLC format .
fn load_slc_file(path: &Path) -> Result<Vec<Level>, error::SokobanError> {
    let mut collection = Vec::new();
    let file = try!(File::open(&path));
    let reader = BufReader::new(file);
    let parser = EventReader::new(reader);
    let mut level_title = String::new();
    let mut level_str = String::new();
    let mut reading_level = false;
    for e in parser {
        match e {
            Ok(XmlEvent::StartElement { ref name, ref attributes, .. }) => {
                if name.local_name == "L" {
                    reading_level = true;
                } else if name.local_name == "Level" {
                    if let Some(id) = attributes.iter().find(|&attr| attr.name.local_name == "Id") {
                        level_title = id.value.clone();
                    }
                }
            }
            Ok(XmlEvent::EndElement { name }) => {
                if name.local_name == "Level" {
                    let mut level = try!(Level::from_str(&level_str));
                    level.set_title(level_title.clone());
                    collection.push(level);
                    level_str.clear();
                }
            }
            Ok(XmlEvent::Characters(ref data)) => {
                if reading_level {
                    level_str.push_str(data);
                    level_str.push('\n');
                }
            }
            _ => {}
        }
    }
    Ok(collection)
}
fn load_slc_file ( path : & Path ) -> Result < Vec < Level > , error :: SokobanError > { let mut collection = Vec :: new ( ) ; let file = try ! ( File open ( path ) ) ; let reader = BufReader :: new ( file ) ; let parser = EventReader :: new ( reader ) ; let mut level_title = String :: new ( ) ; let mut level_str = String :: new ( ) ; let mut reading_level = false ; for e in parser { match e { Ok ( XmlEvent :: StartElement { ref name , ref attributes , .. } ) => { if name . local_name == " " { reading_level = true ; } else if name . local_name == " " { if let Some ( id ) = attributes . iter ( ) . find ( | & attr | attr . name . local_name == " " ) { level_title = id . value . clone ( ) ; } } } Ok ( XmlEvent :: EndElement { name } ) => { if name . local_name == " " { let mut level = try ! ( Level from_str ( level_str ) ) ; level . set_title ( level_title . clone ( ) ) ; collection . push ( level ) ; level_str . clear ( ) ; } } Ok ( XmlEvent :: Characters ( ref data ) ) => { if reading_level { level_str . push_str ( data ) ; level_str . push ( '\n' ) ; } } _ => { } } } Ok ( collection ) }
Builds levels from a level collection file in the SLC format.
Builds levels from a level collection file in the SLC format .
path
&Path