refactoring/optimisation
This commit is contained in:
parent
586573c86a
commit
9fcf3a996d
31
src/game.rs
31
src/game.rs
|
@ -448,21 +448,15 @@ impl Game {
|
|||
|
||||
if room.palette_id.is_some() {
|
||||
let key = room.palette_id.clone().unwrap();
|
||||
if palette_id_changes.contains_key(&key) {
|
||||
let new_id = palette_id_changes.get(&key).unwrap();
|
||||
room.palette_id = Some(new_id.clone());
|
||||
let change = palette_id_changes.get(&key);
|
||||
if change.is_some() {
|
||||
room.palette_id = Some(change.unwrap().clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut tiles = Vec::new();
|
||||
for tile_id in &room.tiles {
|
||||
tiles.push(if tile_id_changes.contains_key(tile_id) {
|
||||
tile_id_changes.get(tile_id).unwrap()
|
||||
} else {
|
||||
tile_id
|
||||
}.clone());
|
||||
}
|
||||
room.tiles = tiles;
|
||||
room.tiles = room.tiles.iter().map(|tile_id|
|
||||
tile_id_changes.get(tile_id).unwrap_or(tile_id).clone()
|
||||
).collect();
|
||||
|
||||
room.items = room.items.iter().map(|instance|
|
||||
if item_id_changes.contains_key(&instance.id) {
|
||||
|
@ -672,7 +666,9 @@ impl Game {
|
|||
#[inline]
|
||||
pub fn add_palette(&mut self, mut palette: Palette) -> String {
|
||||
let new_id = try_id(self.palette_ids(), palette.id.clone());
|
||||
if new_id != palette.id {
|
||||
palette.id = new_id.clone();
|
||||
}
|
||||
self.palettes.push(palette);
|
||||
new_id
|
||||
}
|
||||
|
@ -680,17 +676,24 @@ impl Game {
|
|||
/// adds a tile safely and returns the new tile ID
|
||||
#[inline]
|
||||
pub fn add_tile(&mut self, mut tile: Tile) -> String {
|
||||
if self.tile_ids().contains(&tile.id) {
|
||||
let new_id = self.new_tile_id();
|
||||
tile.id = new_id.clone();
|
||||
if new_id != tile.id {
|
||||
tile.id = new_id;
|
||||
}
|
||||
}
|
||||
let id = tile.id.clone();
|
||||
self.tiles.push(tile);
|
||||
new_id
|
||||
id
|
||||
}
|
||||
|
||||
/// adds a sprite safely and returns the new sprite ID
|
||||
#[inline]
|
||||
pub fn add_sprite(&mut self, mut sprite: Sprite) -> String {
|
||||
let new_id = try_id(self.sprite_ids(), sprite.id.clone());
|
||||
if new_id != sprite.id {
|
||||
sprite.id = new_id.clone();
|
||||
}
|
||||
self.sprites.push(sprite);
|
||||
new_id
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue