From e7c43905adae32335bf0f58a40206d374450e375 Mon Sep 17 00:00:00 2001 From: est31 Date: Wed, 14 Aug 2019 04:58:30 +0200 Subject: [PATCH] Add function that extends an existing name id map --- mehlon-server/game_params.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mehlon-server/game_params.rs b/mehlon-server/game_params.rs index 28e16c5..0cbe398 100644 --- a/mehlon-server/game_params.rs +++ b/mehlon-server/game_params.rs @@ -118,6 +118,20 @@ impl NameIdMap { pub fn names(&self) -> &[String] { &self.id_to_name } + pub fn extend_existing(mut other :Self, + names :Vec>) -> Self { + let mut id = other.first_invalid_id; + + for name in names.into_iter() { + let name = name.into(); + other.id_to_name.push(name.clone()); + let mb = MapBlock::from_id_unchecked(id); + other.name_to_id.insert(name.clone(), mb); + id += 1; + } + other.first_invalid_id = id; + other + } pub fn mb_from_id(&self, id :u8) -> Option { if id >= self.first_invalid_id { return None;