diff --git a/src/mock.rs b/src/mock.rs index 35efcc1..89bf0e9 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -127,6 +127,17 @@ pub fn tile_default() -> Tile { } } +#[inline] +pub fn tile_background() -> Tile { + Tile { + id: "0".to_string(), + name: None, + wall: None, + animation_frames: vec![Image {pixels: vec![0; 64]}], + colour_id: None + } +} + #[inline] pub fn sprite() -> Sprite { Sprite { diff --git a/src/tile.rs b/src/tile.rs index 5a1a5aa..7545ac5 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,7 +1,7 @@ use crate::{optional_data_line, AnimationFrames, Image}; use crate::image::animation_frames_from_string; -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq)] pub struct Tile { pub id: String, pub name: Option, @@ -10,6 +10,18 @@ pub struct Tile { pub colour_id: Option, } +impl PartialEq for Tile { + fn eq(&self, other: &Self) -> bool { + self.name == other.name + && + self.wall == other.wall + && + self.animation_frames == other.animation_frames + && + self.colour_id == other.colour_id + } +} + impl Tile { #[inline] fn name_line(&self) -> String { @@ -130,4 +142,12 @@ mod test { assert_eq!(output, expected); } + + #[test] + fn test_partial_eq() { + let tile_a = crate::mock::tile_default(); + let mut tile_b = crate::mock::tile_default(); + tile_b.id = "0".to_string(); + assert_eq!(tile_a, tile_b); + } }