From 7c216809262f84406e5b8abdcb753cedda082091 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 28 Jun 2020 18:30:20 +0100 Subject: [PATCH] tidyup --- src/game.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/game.rs b/src/game.rs index 797dd32..1327d86 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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()); } }