screeps_pathfinding/common/data/
mod.rs

1use screeps::{LocalRoomTerrain, RoomName};
2use screeps_utils::offline_map::load_shard_map_json;
3use std::collections::HashMap;
4use std::{env, path::PathBuf};
5
6const TEST_MAPS_DIRNAME: &str = "test_maps";
7
8pub fn load_all_room_terrains_from_map(map_name: &str) -> HashMap<RoomName, LocalRoomTerrain> {
9    let mut ret_data = HashMap::new();
10
11    // Load map data
12    let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
13    let map_path = PathBuf::from(manifest_dir)
14        .join("src")
15        .join("common")
16        .join("data")
17        .join(TEST_MAPS_DIRNAME)
18        .join(map_name);
19    println!("{}", map_path.display());
20    let map_data = load_shard_map_json(map_path);
21
22    // Extract terrain data from each room
23    for (room_name, room_data) in map_data.rooms {
24        ret_data.insert(room_name, room_data.terrain);
25    }
26
27    ret_data
28}