diff options
| author | troido <troido@protonmail.com> | 2020-03-03 13:36:44 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-03 13:36:44 +0100 |
| commit | b2157791dfcaab18ec7f8ebb958341fe325cf419 (patch) | |
| tree | f94e638573878599b0ee108a0b06fbe1c8f69ef9 /src/assemblage.rs | |
| parent | a8d0e075613cc973b66c37510103108362fe7d3d (diff) | |
added spawners an not-saved assemblages/templates
Diffstat (limited to 'src/assemblage.rs')
| -rw-r--r-- | src/assemblage.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/assemblage.rs b/src/assemblage.rs index 71142f1..65c9bfa 100644 --- a/src/assemblage.rs +++ b/src/assemblage.rs @@ -15,7 +15,8 @@ type ArgumentDef = (String, ParameterType, Option<Parameter>); #[derive(Debug, PartialEq, Clone)] pub struct Assemblage { pub arguments: Vec<ArgumentDef>, - pub components: Vec<(ComponentType, HashMap<String, ComponentParameter>)> + pub components: Vec<(ComponentType, HashMap<String, ComponentParameter>)>, + pub save: bool } impl Assemblage { @@ -74,7 +75,8 @@ impl Assemblage { pub fn from_json(val: &Value) -> Result<Self, &'static str>{ let mut assemblage = Self { arguments: Self::parse_definition_arguments(val.get("arguments").unwrap_or(&json!([])))?, - components: Self::parse_definition_components(val.get("components").ok_or("property 'components' not found")?)? + components: Self::parse_definition_components(val.get("components").ok_or("property 'components' not found")?)?, + save: val.get("save").unwrap_or(&json!(true)).as_bool().ok_or("assemblage save not a bool")? }; // visible component is so common that shortcuts are very helpful if let Some(spritename) = val.get("sprite") { @@ -134,7 +136,7 @@ impl Assemblage { } components.push(ComponentWrapper::load_component(*comptype, compargs).ok_or("failed to load component")?); } - if template.save { + if template.save && self.save { components.push(ComponentWrapper::Serialise(Serialise{template: template.clone()})); } Ok(components) @@ -184,7 +186,8 @@ mod tests { "sprite".to_string() => ComponentParameter::Argument("sprite".to_string()), "height".to_string() => ComponentParameter::Constant(Parameter::Float(0.1)) )) - ] + ], + save: true }; assert_eq!(result, constructed); } @@ -294,7 +297,8 @@ mod tests { "sprite".to_string() => ComponentParameter::Argument("sprite".to_string()), "height".to_string() => ComponentParameter::Constant(Parameter::Float(0.1)) )) - ] + ], + save: true }; assert_eq!(result, constructed); } |
