fix merge issues #1 & #2; minor version bump

This commit is contained in:
Max Bradbury 2020-07-02 16:52:40 +01:00
parent 4978d263f1
commit 5d40222120
3 changed files with 19 additions and 17 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "bitsy-parser" name = "bitsy-parser"
version = "0.71.0" version = "0.71.1"
authors = ["Max Bradbury <max@tinybird.info>"] authors = ["Max Bradbury <max@tinybird.info>"]
edition = "2018" edition = "2018"
description = "A parser and utilities for working with Bitsy game data" description = "A parser and utilities for working with Bitsy game data"

View File

@ -365,7 +365,7 @@ impl Game {
for item in &game.items { for item in &game.items {
let old_id = item.id.clone(); let old_id = item.id.clone();
let new_id = try_id(self.item_ids(), item.id.clone()); let new_id = try_id(&self.item_ids(), &item.id);
insert_if_different(item_id_changes.borrow_mut(), old_id, new_id) insert_if_different(item_id_changes.borrow_mut(), old_id, new_id)
} }
@ -419,12 +419,14 @@ impl Game {
// calculate all of the new room IDs first // calculate all of the new room IDs first
// to insert any new room, we need to know the new IDs of every room // to insert any new room, we need to know the new IDs of every room
// to maintain the integrity of exits and endings // to maintain the integrity of exits and endings
let mut all_room_ids = self.room_ids().clone();
for room in &game.rooms { for room in &game.rooms {
insert_if_different( let old = room.id.clone();
room_id_changes.borrow_mut(), let new = try_id(&all_room_ids, &room.id);
room.id.clone(), insert_if_different(room_id_changes.borrow_mut(), old, new.clone());
try_id(self.room_ids(), room.id.clone()) all_room_ids.push(new);
);
} }
// needs to be handled after palettes, tiles, items, exits, endings // needs to be handled after palettes, tiles, items, exits, endings
@ -679,7 +681,7 @@ impl Game {
/// adds a palette safely and returns the ID /// adds a palette safely and returns the ID
#[inline] #[inline]
pub fn add_palette(&mut self, mut palette: Palette) -> String { pub fn add_palette(&mut self, mut palette: Palette) -> String {
let new_id = try_id(self.palette_ids(), palette.id.clone()); let new_id = try_id(&self.palette_ids(), &palette.id);
if new_id != palette.id { if new_id != palette.id {
palette.id = new_id.clone(); palette.id = new_id.clone();
} }
@ -704,7 +706,7 @@ impl Game {
/// adds a sprite safely and returns the ID /// adds a sprite safely and returns the ID
#[inline] #[inline]
pub fn add_sprite(&mut self, mut sprite: Sprite) -> String { pub fn add_sprite(&mut self, mut sprite: Sprite) -> String {
let new_id = try_id(self.sprite_ids(), sprite.id.clone()); let new_id = try_id(&self.sprite_ids(), &sprite.id);
if new_id != sprite.id { if new_id != sprite.id {
sprite.id = new_id.clone(); sprite.id = new_id.clone();
} }
@ -715,7 +717,7 @@ impl Game {
/// adds an item safely and returns the ID /// adds an item safely and returns the ID
#[inline] #[inline]
pub fn add_item(&mut self, mut item: Item) -> String { pub fn add_item(&mut self, mut item: Item) -> String {
let new_id = try_id(self.item_ids(), item.id.clone()); let new_id = try_id(&self.item_ids(), &item.id);
if new_id != item.id { if new_id != item.id {
item.id = new_id.clone(); item.id = new_id.clone();
} }
@ -726,7 +728,7 @@ impl Game {
/// adds a dialogue safely and returns the ID /// adds a dialogue safely and returns the ID
#[inline] #[inline]
pub fn add_dialogue(&mut self, mut dialogue: Dialogue) -> String { pub fn add_dialogue(&mut self, mut dialogue: Dialogue) -> String {
let new_id = try_id(self.dialogue_ids(), dialogue.id.clone()); let new_id = try_id(&self.dialogue_ids(), &dialogue.id);
if new_id != dialogue.id { if new_id != dialogue.id {
dialogue.id = new_id.clone(); dialogue.id = new_id.clone();
} }
@ -736,7 +738,7 @@ impl Game {
/// adds an ending safely and returns the ID /// adds an ending safely and returns the ID
pub fn add_ending(&mut self, mut ending: Ending) -> String { pub fn add_ending(&mut self, mut ending: Ending) -> String {
let new_id = try_id(self.ending_ids(), ending.id.clone()); let new_id = try_id(&self.ending_ids(), &ending.id);
if new_id != ending.id { if new_id != ending.id {
ending.id = new_id.clone(); ending.id = new_id.clone();
} }
@ -748,7 +750,7 @@ impl Game {
/// You will need to be mindful that the room's palette, tile, exit and ending IDs /// You will need to be mindful that the room's palette, tile, exit and ending IDs
/// will be valid after adding. /// will be valid after adding.
pub fn add_room(&mut self, mut room: Room) -> String { pub fn add_room(&mut self, mut room: Room) -> String {
let new_id = try_id(self.room_ids(), room.id.clone()); let new_id = try_id(&self.room_ids(), &room.id);
if new_id != room.id { if new_id != room.id {
room.id = new_id.clone(); room.id = new_id.clone();
} }
@ -757,7 +759,7 @@ impl Game {
} }
pub fn add_variable(&mut self, mut variable: Variable) -> String { pub fn add_variable(&mut self, mut variable: Variable) -> String {
let new_id = try_id(self.variable_ids(), variable.id.clone()); let new_id = try_id(&self.variable_ids(), &variable.id);
if new_id != variable.id { if new_id != variable.id {
variable.id = new_id.clone(); variable.id = new_id.clone();
} }

View File

@ -145,7 +145,7 @@ fn segments_from_string(string: String) -> Vec<String> {
/// tries to use an existing ID - if it is already in use, generate a new one /// tries to use an existing ID - if it is already in use, generate a new one
/// then return the ID (either original or new) /// then return the ID (either original or new)
/// todo refactor (unnecessary clones etc.) /// todo refactor (unnecessary clones etc.)
fn try_id(ids: Vec<String>, id: String) -> String { fn try_id(ids: &Vec<String>, id: &String) -> String {
let id = id.clone(); let id = id.clone();
let ids = ids.clone(); let ids = ids.clone();
if is_id_available(&ids, &id) { if is_id_available(&ids, &id) {
@ -242,12 +242,12 @@ mod test {
fn test_try_id() { fn test_try_id() {
// does a conflict generate a new ID? // does a conflict generate a new ID?
assert_eq!( assert_eq!(
try_id(vec!["0".to_string(), "1".to_string()], "1".to_string()), try_id(&vec!["0".to_string(), "1".to_string()], &"1".to_string()),
"2".to_string() "2".to_string()
); );
// with no conflict, does the ID remain the same? // with no conflict, does the ID remain the same?
assert_eq!( assert_eq!(
try_id(vec!["0".to_string(), "1".to_string()], "3".to_string()), try_id(&vec!["0".to_string(), "1".to_string()], &"3".to_string()),
"3".to_string() "3".to_string()
); );
} }