From dc25e66031fc0a1fbdb15579ad346bcb3903b3bb Mon Sep 17 00:00:00 2001 From: troido Date: Sat, 16 May 2020 12:03:49 +0200 Subject: encyclopedia can be split over different files --- src/encyclopedia.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/encyclopedia.rs') diff --git a/src/encyclopedia.rs b/src/encyclopedia.rs index 54fa82b..e100cad 100644 --- a/src/encyclopedia.rs +++ b/src/encyclopedia.rs @@ -37,7 +37,7 @@ impl Encyclopedia { let items = val .get("items") - .ok_or(perr!("no items in encyclopedia json"))? + .unwrap_or(&json!({})) .as_object() .ok_or(perr!("encyclopedia items not a json object"))? .into_iter() @@ -105,7 +105,6 @@ impl Encyclopedia { assemblages, items }) - } pub fn validate(&self) -> Result<()> { @@ -125,5 +124,11 @@ impl Encyclopedia { pub fn get_item(&self, id: &ItemId) -> Option { self.items.get(id).map(|item| item.clone()) } + + pub fn merge(mut self, mut other: Encyclopedia) -> Encyclopedia { + self.assemblages.extend(other.assemblages.drain()); + self.items.extend(other.items.drain()); + self + } } -- cgit