diff options
| -rw-r--r-- | content/encyclopediae/default_encyclopedia.json | 38 | ||||
| -rw-r--r-- | src/assemblage.rs | 36 | ||||
| -rw-r--r-- | todo.md | 2 |
3 files changed, 36 insertions, 40 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json index 3d7adae..bf5a1b2 100644 --- a/content/encyclopediae/default_encyclopedia.json +++ b/content/encyclopediae/default_encyclopedia.json @@ -86,13 +86,7 @@ "height": 0.3 }, "stone": { - "components": [ - ["Item", { - "ent": ["self", null], - "name": ["string", "stone"], - "action": ["action", ["build", "builtwall"]] - }] - ], + "item": ["build", "builtwall"], "sprite": "stone", "height": 0.4 }, @@ -198,13 +192,7 @@ "sprite": "seed", "height": 0.2, "name": "radishseed", - "components": [ - ["Item", { - "ent": ["self", null], - "name": ["string", "radishseed"], - "action": ["action", ["build", "plantedradishseed"]] - }] - ] + "item": ["build", "plantedradishseed"] }, "plantedradishseed": { "sprite": "seed", @@ -221,27 +209,15 @@ "sprite": "food", "height": 0.3, "name": "radishes", - "components": [ - ["Item", { - "ent": ["self", null], - "name": ["string", "radishes"], - "action": ["action", ["eat", 3]] - }] - ] + "item": ["eat", 3] }, "sword": { "sprite": "sword", "height": 0.5, - "components": [ - ["Item", { - "ent": ["self", null], - "name": ["string", "sword"], - "action": ["action", ["equip", { - "slot": "hand", - "stats": {"strength": 50} - }]] - }] - ] + "item": ["equip", { + "slot": "hand", + "stats": {"strength": 50} + }] } } } diff --git a/src/assemblage.rs b/src/assemblage.rs index 93d89a0..adf1ba5 100644 --- a/src/assemblage.rs +++ b/src/assemblage.rs @@ -80,21 +80,43 @@ impl Assemblage { components: Self::parse_definition_components(val.get("components").unwrap_or(&json!([])))?, save: val.get("save").unwrap_or(&json!(true)).as_bool().ok_or(aerr!("assemblage save not a bool"))? }; + let name = if let Some(nameval) = val.get("name") { + Some(nameval.as_str().ok_or(aerr!("name not a string"))?.to_string()) + } else {None}; // visible component is so common that shortcuts are very helpful if let Some(spritename) = val.get("sprite") { - let height = val.get("height").ok_or(aerr!("defining a sprite requires also defining a height"))?; - let name = val.get("name").unwrap_or(spritename); + let sprite = spritename.as_str().ok_or(aerr!("sprite not a string"))?.to_string(); + let height = val + .get("height").ok_or(aerr!("defining a sprite requires also defining a height"))? + .as_f64().ok_or(aerr!("height not a float"))?; assemblage.components.push(( ComponentType::Visible, hashmap!( + "name".to_string() => ComponentParameter::Constant( + Parameter::String(name.clone().unwrap_or(sprite.clone())) + ), "sprite".to_string() => ComponentParameter::Constant( - Parameter::String(spritename.as_str().ok_or(aerr!("sprite not a string"))?.to_string()) + Parameter::String(sprite) ), "height".to_string() => ComponentParameter::Constant( - Parameter::Float(height.as_f64().ok_or(aerr!("height not a float"))?) - ), - "name".to_string() => ComponentParameter::Constant( - Parameter::String(name.as_str().ok_or(aerr!("name not a string"))?.to_string()) + Parameter::Float(height) + ) + ) + )); + } + // item component is common too + if let Some(action) = val.get("item") { + assemblage.components.push(( + ComponentType::Item, + hashmap!( + "ent".to_string() => ComponentParameter::TemplateSelf, + "name".to_string() => if let Some(n) = name { + ComponentParameter::Constant(Parameter::String(n)) + } else { + ComponentParameter::TemplateName + }, + "action".to_string() => ComponentParameter::Constant( + Parameter::from_typed_json(ParameterType::Action, action).ok_or(aerr!("invalid item action"))? ) ) )); @@ -1,7 +1,6 @@ # TODO -- save equipment - save time - save variable arguments (health etc) - timer resource @@ -9,7 +8,6 @@ - draw new entities - room unloading - relative room locations -- shortcuts for defining items - improve error handling - doors |
