/// Saves all occurences of every object id as a `json` file to the folder `out/data/rs3/locations`.
Saves all occurences of every object id as a `json` file to the folder `out/data/rs3/locations`.
Saves all occurences of every object id as a ` json ` file to the folder ` out / data / rs3 / locations ` .
pub fn export_locations_by_id(config: &crate::cli::Config) -> CacheResult<()> {
    let out = path_macro::path!(config.output / "locations");
    fs::create_dir_all(&out)?;
    let last_id = {
        let squares = MapSquares::new(config)?.into_iter();
        squares
            .filter_map(|sq| sq.expect("error deserializing mapsquare").take_locations().ok())
            .filter(|locs| !locs.is_empty())
            .map(|locs| locs.last().expect("locations stopped existing").id)
            .max()
            .unwrap()
    };
    let squares = MapSquares::new(config)?.into_iter();
    let mut locs: Vec<_> = squares
        .filter_map(|sq| sq.expect("error deserializing mapsquare").take_locations().ok())
        .map(|locs| locs.into_iter().peekable())
        .collect();
    // Here we exploit the fact that the mapsquare file yields its locations by id in ascending order.
    (0..=last_id)
        .map(|id| {
            (
                id,
                locs.iter_mut()
                    .flat_map(|iterator| std::iter::repeat_with(move || iterator.next_if(|loc| loc.id == id)).take_while(|item| item.is_some()))
                    .flatten()
                    .collect::<Vec<Location>>(),
            )
        })
        .par_bridge()
        .for_each(|(id, id_locs)| {
            if !id_locs.is_empty() && id != 83 {
                let mut file = File::create(path!(&out / f!("{id}.json"))).unwrap();
                let data = serde_json::to_string_pretty(&id_locs).unwrap();
                file.write_all(data.as_bytes()).unwrap();
            }
        });
    Ok(())
}
pub fn export_locations_by_id ( config : & crate :: cli :: Config ) -> CacheResult < ( ) > { let out = path_macro :: path ! ( config output " " ) ; fs :: create_dir_all ( & out ) ? ; let last_id = { let squares = MapSquares :: new ( config ) ? . into_iter ( ) ; squares . filter_map ( | sq | sq . expect ( " " ) . take_locations ( ) . ok ( ) ) . filter ( | locs | ! locs . is_empty ( ) ) . map ( | locs | locs . last ( ) . expect ( " " ) . id ) . max ( ) . unwrap ( ) } ; let squares = MapSquares :: new ( config ) ? . into_iter ( ) ; let mut locs : Vec < _ > = squares . filter_map ( | sq | sq . expect ( " " ) . take_locations ( ) . ok ( ) ) . map ( | locs | locs . into_iter ( ) . peekable ( ) ) . collect ( ) ; // Here we exploit the fact that the mapsquare file yields its locations by id in ascending order. ( 0 ..= last_id ) . map ( | id | { ( id , locs . iter_mut ( ) . flat_map ( | iterator | std :: iter :: repeat_with ( move | | iterator . next_if ( | loc | loc . id == id ) ) . take_while ( | item | item . is_some ( ) ) ) . flatten ( ) . collect :: < Vec < Location > > ( ) , ) } ) . par_bridge ( ) . for_each ( | ( id , id_locs ) | { if ! id_locs . is_empty ( ) && id != 83 { let mut file = File :: create ( path ! ( out f ( " " ) ) ) . unwrap ( ) ; let data = serde_json :: to_string_pretty ( & id_locs ) . unwrap ( ) ; file . write_all ( data . as_bytes ( ) ) . unwrap ( ) ; } } ) ; Ok ( ( ) ) }
Saves all occurences of every object id as a `json` file to the folder `out/data/rs3/locations`.
Saves all occurences of every object id as a ` json ` file to the folder ` out / data / rs3 / locations ` .
config
&crate::cli::Config