diff options
| author | troido <troido@protonmail.com> | 2020-02-06 20:17:15 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-06 20:17:15 +0100 |
| commit | 837d5b3a2c70d240b053644ef2e5c3264d453756 (patch) | |
| tree | 2969edf1f46176d9e0c0cd0db02def0fda062e8f /src/main.rs | |
| parent | a9b9e5876a93bd2ba701ab7c766746856df83820 (diff) | |
refactored type validation out of parseing
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index cff91a9..5b79849 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,16 +64,8 @@ fn main() { fn gen_room<'a, 'b>(width: i32, height: i32) -> Room<'a, 'b> { let mut room = Room::new((width, height)); - let wall = Template::from_json(json!({ - "arguments": [], - "components": [ - ["Blocking", {}], - ["Visible", { - "sprite": ["const", "wall"], - "height": ["const", 1.0] - }] - ] - })).unwrap().instantiate(Vec::new(), HashMap::new()).unwrap(); + let assemblages = default_assemblages(); + let wall = assemblages["wall"].instantiate(Vec::new(), HashMap::new()).unwrap(); for x in 0..width { room.add_complist(&wall, (x, 0)); room.add_complist(&wall, (x, height - 1)); @@ -90,7 +82,29 @@ fn gen_room<'a, 'b>(width: i32, height: i32) -> Room<'a, 'b> { room } -// fn default_assemblages() -> Hashmap<&str, Template> { -// hashmap!( -// +fn default_assemblages() -> HashMap<String, Template> { + json!({ + "wall": { + "arguments": [], + "components": [ + ["Blocking", {}], + ["Visible", { + "sprite": ["string", "wall"], + "height": ["float", 1.0] + }] + ] + }, + "grass": { + "arguments": [ + ["sprite", "string", "grass1"] + ], + "components": [ + ["Visible", { + "sprite": ["arg", "sprite"], + "height": ["float", 0.1] + }] + ] + } + }).as_object().unwrap().into_iter().map(|(k, v)| (k.clone(), Template::from_json(v).unwrap())).collect() +} |
