Skip to content

Commit

Permalink
Add function that extends an existing name id map
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Aug 14, 2019
1 parent 3155856 commit e7c4390
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mehlon-server/game_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ impl NameIdMap {
pub fn names(&self) -> &[String] {
&self.id_to_name
}
pub fn extend_existing(mut other :Self,
names :Vec<impl Into<String>>) -> 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<MapBlock> {
if id >= self.first_invalid_id {
return None;
Expand Down

0 comments on commit e7c4390

Please sign in to comment.