implement PartialEq so we can compare tiles without comparing IDs
This commit is contained in:
22
src/tile.rs
22
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<String>,
|
||||
@@ -10,6 +10,18 @@ pub struct Tile {
|
||||
pub colour_id: Option<u64>,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user