summaryrefslogtreecommitdiff
path: root/src/assemblage.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-03-09 16:54:26 +0100
committertroido <troido@protonmail.com>2020-03-09 16:54:26 +0100
commit69ac6eb6153b016c39bbe55c85f15e3478032182 (patch)
tree31a0a5cf3d768688c7600902364446d55e3f4395 /src/assemblage.rs
parenta1f45d1b40b23cb7e9f0b277f24ad66880b0bc56 (diff)
can now include variables (like health) in serialisation
Diffstat (limited to 'src/assemblage.rs')
-rw-r--r--src/assemblage.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/assemblage.rs b/src/assemblage.rs
index adf1ba5..8e3a349 100644
--- a/src/assemblage.rs
+++ b/src/assemblage.rs
@@ -18,7 +18,8 @@ type ArgumentDef = (String, ParameterType, Option<Parameter>);
pub struct Assemblage {
pub arguments: Vec<ArgumentDef>,
pub components: Vec<(ComponentType, HashMap<String, ComponentParameter>)>,
- pub save: bool
+ pub save: bool,
+ pub extract: Vec<(String, ComponentType, String)>
}
impl Assemblage {
@@ -78,7 +79,26 @@ impl Assemblage {
let mut assemblage = Self {
arguments: Self::parse_definition_arguments(val.get("arguments").unwrap_or(&json!([])))?,
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"))?
+ save: val.get("save").unwrap_or(&json!(true)).as_bool().ok_or(aerr!("assemblage save not a bool"))?,
+ extract: val
+ .get("extract")
+ .unwrap_or(&json!({}))
+ .as_object().ok_or(aerr!("assemblage extract not a bool"))?
+ .into_iter()
+ .map(|(argname, val)| {
+ Ok((
+ argname.to_string(),
+ ComponentType::from_str(
+ val
+ .get(0).ok_or(aerr!("index 0 not in extract value"))?
+ .as_str().ok_or(aerr!("extract component name not a string"))?
+ ).ok_or(aerr!("extract invalid component name"))?,
+ val.get(1)
+ .ok_or(aerr!("index 1 not in extract value"))?
+ .as_str().ok_or(aerr!("extract member name not a string"))?.to_string()
+ ))
+ })
+ .collect::<Result<Vec<(String, ComponentType, String)>>>()?
};
let name = if let Some(nameval) = val.get("name") {
Some(nameval.as_str().ok_or(aerr!("name not a string"))?.to_string())
@@ -161,7 +181,7 @@ impl Assemblage {
components.push(ComponentWrapper::load_component(*comptype, compargs).ok_or(aerr!("failed to load component"))?);
}
if template.save && self.save {
- components.push(ComponentWrapper::Serialise(Serialise{template: template.clone()}));
+ components.push(ComponentWrapper::Serialise(Serialise{template: template.clone(), extract: self.extract.clone() }));
}
Ok(components)
}