use std::collections::HashMap; use serde_json::{json, Value}; use crate::{ Pos, Template, Result, aerr }; #[derive(Debug, Clone)] pub struct RoomTemplate { pub size: (i64, i64), pub spawn: Pos, pub field: Vec>, pub places: HashMap } impl RoomTemplate { pub fn from_json(jsonroom: &Value) -> Result{ let size = ( jsonroom.get("width").ok_or("no with")?.as_i64().ok_or("with not a number")?, jsonroom.get("height").ok_or("no height")?.as_i64().ok_or("height not a number")? ); let spawn = Pos::from_json(jsonroom.get("spawn").ok_or("no spawn")?).ok_or("spawn not a pos")?; let mut mapping = HashMap::new(); for (key, value) in jsonroom.get("mapping").ok_or("no mapping")?.as_object().ok_or("mapping not a json object")?.iter() { let mut templates: Vec