blob: 8745bf43f7ce9906fc84b258e0c530f08f4ac593 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
use std::path::PathBuf;
use std::fs;
use serde_json;
use serde_json::Value;
use crate::{
RoomId,
roomtemplate::RoomTemplate,
util::Result
};
pub struct WorldLoader {
pub directory: PathBuf
}
impl WorldLoader {
pub fn new(path: PathBuf) -> Self {
Self {
directory: path
}
}
pub fn load_room(&self, id: RoomId) -> Result<RoomTemplate> {
let mut path = self.directory.clone();
let fname = id.to_string() + ".json";
path.push(fname);
println!("PATH: {:?}", path);
let text = fs::read_to_string(path)?;
let json: Value = serde_json::from_str(&text)?;
let template = RoomTemplate::from_json(&json)?;
Ok(template)
}
}
|