diff --git a/src/game.rs b/src/game.rs index 497e6d6..aaebc13 100644 --- a/src/game.rs +++ b/src/game.rs @@ -346,7 +346,7 @@ impl Game { let mut sprite_id_changes: HashMap = HashMap::new(); fn insert_if_different(map: &mut HashMap, old: String, new: String) { - if old != new { + if old != new && ! map.contains_key(&old) { map.insert(old, new); } } @@ -418,8 +418,9 @@ impl Game { if item.dialogue_id.is_some() { let key = item.dialogue_id.clone().unwrap(); - if dialogue_id_changes.contains_key(&key) { - item.dialogue_id = Some(dialogue_id_changes[&key].clone()); + let change = dialogue_id_changes.get(&key); + if change.is_some() { + item.dialogue_id = Some(change.unwrap().clone()); } } @@ -442,8 +443,9 @@ impl Game { for room in &game.rooms { let mut room = room.clone(); - if room_id_changes.contains_key(&room.id) { - room.id = room_id_changes.get(&room.id).unwrap().clone(); + let room_id_change = room_id_changes.get(&room.id); + if room_id_change.is_some() { + room.id = room_id_change.unwrap().clone(); } if room.palette_id.is_some() { @@ -955,5 +957,7 @@ mod test { game_b.add_sprite(sprite); game_a.merge(game_b); assert_eq!(game_a.get_sprite_by_id("2".to_string()).unwrap().room_id, Some(room_id)); + + } }