From 92ca2ea5c37735ff1fe393434562911f8ffb8569 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Wed, 1 Jul 2020 14:22:23 +0100 Subject: [PATCH] add change_tile_ids() function --- src/game.rs | 4 +--- src/room.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/game.rs b/src/game.rs index aaebc13..3a54f00 100644 --- a/src/game.rs +++ b/src/game.rs @@ -456,9 +456,7 @@ impl Game { } } - room.tiles = room.tiles.iter().map(|tile_id| - tile_id_changes.get(tile_id).unwrap_or(tile_id).clone() - ).collect(); + room.change_tile_ids(&tile_id_changes); room.items = room.items.iter().map(|instance| if item_id_changes.contains_key(&instance.id) { diff --git a/src/room.rs b/src/room.rs index 973bf16..1207ae5 100644 --- a/src/room.rs +++ b/src/room.rs @@ -2,6 +2,7 @@ use crate::{optional_data_line, Exit, ExitInstance, Instance, Position}; use crate::game::{RoomType, RoomFormat}; use crate::exit::Transition; use std::str::FromStr; +use std::collections::HashMap; #[derive(Clone, Debug, Eq, PartialEq)] pub struct Room { @@ -223,6 +224,14 @@ impl Room { self.palette_line() ) } + + /// "changes" is a hash of old -> new tile IDs + #[inline] + pub fn change_tile_ids(&mut self, changes: &HashMap) { + self.tiles = self.tiles.iter().map(|tile_id| + changes.get(tile_id).unwrap_or(tile_id).clone() + ).collect(); + } } #[cfg(test)]