implement PartialEq so we can compare tiles without comparing IDs
This commit is contained in:
parent
9ece613a95
commit
eef37898f7
11
src/mock.rs
11
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 {
|
||||
|
|
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue