This commit is contained in:
Max Bradbury 2020-06-28 18:30:20 +01:00
parent beea5f8efc
commit 7c21680926
1 changed files with 17 additions and 9 deletions

View File

@ -357,8 +357,11 @@ impl Game {
// a room has a palette, so handle palettes before rooms
for palette in &game.palettes {
let new_id = self.add_palette(palette.clone());
insert_if_different(palette_id_changes.borrow_mut(), palette.id.clone(),new_id);
insert_if_different(
palette_id_changes.borrow_mut(),
palette.id.clone(),
self.add_palette(palette.clone())
);
}
// a room has tiles, so handle before room
@ -427,8 +430,11 @@ impl Game {
// to insert any new room, we need to know the new IDs of every room
// to maintain the integrity of exits and endings
for room in &game.rooms {
let new_id = try_id(self.room_ids(), room.id.clone());
insert_if_different(room_id_changes.borrow_mut(), room.id.clone(), new_id);
insert_if_different(
room_id_changes.borrow_mut(),
room.id.clone(),
try_id(self.room_ids(), room.id.clone())
);
}
// needs to be handled after palettes, tiles, items, exits, endings
@ -437,13 +443,14 @@ impl Game {
let mut room = room.clone();
if room_id_changes.contains_key(&room.id) {
room.id = room_id_changes[&room.id].clone();
room.id = room_id_changes.get(&room.id).unwrap().clone();
}
if room.palette_id.is_some() {
let key = room.palette_id.clone().unwrap();
if palette_id_changes.contains_key(&key) {
room.palette_id = Some(room_id_changes[&key].clone());
let new_id = palette_id_changes.get(&key).unwrap();
room.palette_id = Some(new_id.clone());
}
}
@ -471,7 +478,8 @@ impl Game {
room.exits = room.exits.iter().map(|exit| {
let mut exit = exit.clone();
if room_id_changes.contains_key(&exit.exit.room_id) {
exit.exit.room_id = room_id_changes[&exit.exit.room_id].clone();
let new_id = room_id_changes.get(&exit.exit.room_id).unwrap();
exit.exit.room_id = new_id.clone();
}
exit
}).collect();
@ -484,7 +492,7 @@ impl Game {
ending
}).collect();
self.add_room(room.to_owned());
self.add_room(room);
}
// a sprite has a dialogue ID, so we need to handle these after dialogues
@ -506,7 +514,7 @@ impl Game {
if sprite.room_id.is_some() {
let key = sprite.room_id.clone().unwrap();
if room_id_changes.contains_key(&key) {
sprite.room_id = Some(room_id_changes[&key].clone());
sprite.room_id = Some(room_id_changes.get(&key).unwrap().clone());
}
}