add change_tile_ids() function

This commit is contained in:
Max Bradbury 2020-07-01 14:22:23 +01:00
parent eef37898f7
commit 92ca2ea5c3
2 changed files with 10 additions and 3 deletions

View File

@ -456,9 +456,7 @@ impl Game {
} }
} }
room.tiles = room.tiles.iter().map(|tile_id| room.change_tile_ids(&tile_id_changes);
tile_id_changes.get(tile_id).unwrap_or(tile_id).clone()
).collect();
room.items = room.items.iter().map(|instance| room.items = room.items.iter().map(|instance|
if item_id_changes.contains_key(&instance.id) { if item_id_changes.contains_key(&instance.id) {

View File

@ -2,6 +2,7 @@ use crate::{optional_data_line, Exit, ExitInstance, Instance, Position};
use crate::game::{RoomType, RoomFormat}; use crate::game::{RoomType, RoomFormat};
use crate::exit::Transition; use crate::exit::Transition;
use std::str::FromStr; use std::str::FromStr;
use std::collections::HashMap;
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct Room { pub struct Room {
@ -223,6 +224,14 @@ impl Room {
self.palette_line() self.palette_line()
) )
} }
/// "changes" is a hash of old -> new tile IDs
#[inline]
pub fn change_tile_ids(&mut self, changes: &HashMap<String, String>) {
self.tiles = self.tiles.iter().map(|tile_id|
changes.get(tile_id).unwrap_or(tile_id).clone()
).collect();
}
} }
#[cfg(test)] #[cfg(test)]