er, stripping .json vs not...

This commit is contained in:
Dustin Carlino 2018-10-08 15:12:37 -07:00
parent 307318a62e
commit fcf0366e90
2 changed files with 10 additions and 3 deletions

View File

@ -124,14 +124,20 @@ pub fn list_all_objects(dir: &str, map_name: &str) -> Vec<(String, String)> {
results.into_iter().collect()
}
// Load all serialized things from a directory, return sorted by name.
// Load all serialized things from a directory, return sorted by name, with file extension removed.
pub fn load_all_objects<T: DeserializeOwned>(dir: &str, map_name: &str) -> Vec<(String, T)> {
let mut tree: BTreeMap<String, T> = BTreeMap::new();
match std::fs::read_dir(format!("../data/{}/{}/", dir, map_name)) {
Ok(iter) => {
for entry in iter {
let name = entry.unwrap().file_name().into_string().unwrap();
let load: T = read_json(&format!("../data/{}/{}/{}", dir, map_name, name)).unwrap();
let name = Path::new(&entry.unwrap().file_name())
.file_stem()
.unwrap()
.to_os_string()
.into_string()
.unwrap();
let load: T =
read_json(&format!("../data/{}/{}/{}.json", dir, map_name, name)).unwrap();
tree.insert(name, load);
}
}

View File

@ -43,6 +43,7 @@ impl ABTestManager {
ABTestManager::ManageABTest(test, ref mut scroller) => {
if input.key_pressed(Key::R, "run this A/B test") {
new_ui = Some(launch_test(test, kml));
new_state = Some(ABTestManager::Inactive);
}
if scroller.event(input) {
new_state = Some(ABTestManager::Inactive);