diff --git a/examples/main.rs b/examples/main.rs index 5098995eb20d036bad64d87496ffc0e084e4b16f..e59c5880b405677a56b74628399c592e071d64a1 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -14,7 +14,7 @@ fn main() { let map = Map::parse_file(map_path, &mut cache).unwrap(); for layer in map.layers() { - print!("Layer \"{}\":\n\t", layer.name()); + print!("Layer \"{}\":\n\t", layer.name); match layer.layer_type() { tiled::LayerType::TileLayer(layer) => match layer { @@ -39,7 +39,7 @@ fn main() { tiled::LayerType::ImageLayer(layer) => { println!( "Image layer with {}", - match &layer.image() { + match &layer.image { Some(img) => format!("an image with source = {}", img.source.to_string_lossy()), None => "no image".to_owned(), diff --git a/src/image.rs b/src/image.rs index b0df041fa607bd948ad1c8df8240c312cfd3a012..0b86edc0df9ebacf29d0e7ba61eb19ffff90250b 100644 --- a/src/image.rs +++ b/src/image.rs @@ -34,7 +34,7 @@ pub struct Image { /// /// let image_layer = match map /// .layers() - /// .find(|layer| layer.name() == "image") + /// .find(|layer| layer.name == "image") /// .unwrap() /// .layer_type() /// { @@ -45,7 +45,7 @@ pub struct Image { /// // Image layer has an image with the source attribute set to "../tilesheet.png" /// // Given the information we gave to the `parse_file` function, the image source should be /// // "assets/folder/../tilesheet.png". The filepath is not canonicalized. - /// let image_source = &image_layer.image().unwrap().source; + /// let image_source = &image_layer.image.as_ref().unwrap().source; /// /// assert_eq!( /// image_source, diff --git a/src/layers/group.rs b/src/layers/group.rs index 0a4d8d25f6b936165f066c9ebdafc7fc8cacd64e..91a529bd0dd21d7153a317f45313f6d2b973d43d 100644 --- a/src/layers/group.rs +++ b/src/layers/group.rs @@ -10,8 +10,9 @@ use crate::{ Layer, Map, }; +/// The raw data of a [`GroupLayer`]. Does not include a reference to its parent [`Map`](crate::Map). #[derive(Debug, PartialEq, Clone)] -pub(crate) struct GroupLayerData { +pub struct GroupLayerData { layers: Vec<LayerData>, } diff --git a/src/layers/image.rs b/src/layers/image.rs index d8c8ae8d515e5fa4c3b0a34615f6bd84bd914cb2..75c40c1479ac681be300d102aa4069226d91ee6b 100644 --- a/src/layers/image.rs +++ b/src/layers/image.rs @@ -6,9 +6,11 @@ use crate::{ Image, Properties, TiledError, }; +/// The raw data of an [`ImageLayer`]. Does not include a reference to its parent [`Map`](crate::Map). #[derive(Debug, PartialEq, Clone)] -pub(crate) struct ImageLayerData { - image: Option<Image>, +pub struct ImageLayerData { + /// The single image this layer contains, if it exists. + pub image: Option<Image>, } impl ImageLayerData { @@ -40,11 +42,3 @@ map_wrapper!( #[doc = "\nAlso see the [TMX docs](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#imagelayer)."] ImageLayer => ImageLayerData ); - -impl<'map> ImageLayer<'map> { - /// Get a reference to the image layer's image. - #[inline] - pub fn image(&self) -> Option<&Image> { - self.data.image.as_ref() - } -} diff --git a/src/layers/mod.rs b/src/layers/mod.rs index 5ce61b25504a3cf81e7416ee985808a342b6a6dd..ebe9cdb89002b50089181b441ff9ad92469bc295 100644 --- a/src/layers/mod.rs +++ b/src/layers/mod.rs @@ -29,22 +29,39 @@ pub(crate) enum LayerTag { GroupLayer, } +/// The raw data of a [`Layer`]. Does not include a reference to its parent [`Map`](crate::Map). #[derive(Clone, PartialEq, Debug)] -pub(crate) struct LayerData { - name: String, +pub struct LayerData { + /// The layer's name, set arbitrarily by the user. + pub name: String, id: u32, - visible: bool, - offset_x: f32, - offset_y: f32, - parallax_x: f32, - parallax_y: f32, - opacity: f32, - tint_color: Option<Color>, - properties: Properties, + /// Whether this layer should be visible or not. + pub visible: bool, + /// The layer's x offset (in pixels). + pub offset_x: f32, + /// The layer's y offset (in pixels). + pub offset_y: f32, + /// The layer's x parallax factor. + pub parallax_x: f32, + /// The layer's y parallax factor. + pub parallax_y: f32, + /// The layer's opacity. + pub opacity: f32, + /// The layer's tint color. + pub tint_color: Option<Color>, + /// The layer's custom properties, as arbitrarily set by the user. + pub properties: Properties, layer_type: LayerDataType, } impl LayerData { + /// Get the layer's id. Unique within the parent map. Valid only if greater than 0. Defaults to + /// 0 if the layer was loaded from a file that didn't have the attribute present. + #[inline] + pub fn id(&self) -> u32 { + self.id + } + pub(crate) fn new( parser: &mut impl Iterator<Item = XmlEventResult>, attrs: Vec<OwnedAttribute>, @@ -109,66 +126,6 @@ map_wrapper!( ); impl<'map> Layer<'map> { - /// Get a reference to the layer's name. - #[inline] - pub fn name(&self) -> &str { - self.data.name.as_ref() - } - - /// Get the layer's id. - #[inline] - pub fn id(&self) -> u32 { - self.data.id - } - - /// Whether this layer should be visible or not. - #[inline] - pub fn visible(&self) -> bool { - self.data.visible - } - - /// Get the layer's x offset (in pixels). - #[inline] - pub fn offset_x(&self) -> f32 { - self.data.offset_x - } - - /// Get the layer's y offset (in pixels). - #[inline] - pub fn offset_y(&self) -> f32 { - self.data.offset_y - } - - /// Get the layer's x parallax factor. - #[inline] - pub fn parallax_x(&self) -> f32 { - self.data.parallax_x - } - - /// Get the layer's y parallax factor. - #[inline] - pub fn parallax_y(&self) -> f32 { - self.data.parallax_y - } - - /// Get the layer's opacity. - #[inline] - pub fn opacity(&self) -> f32 { - self.data.opacity - } - - /// Get the layer's tint color. - #[inline] - pub fn tint_color(&self) -> Option<Color> { - self.data.tint_color - } - - /// Get a reference to the layer's properties. - #[inline] - pub fn properties(&self) -> &Properties { - &self.data.properties - } - /// Get the layer's type. #[inline] pub fn layer_type(&self) -> LayerType<'map> { diff --git a/src/layers/object.rs b/src/layers/object.rs index 5939bfaebb4b648071dd2dd86bd7d16166a952d5..8cfbbb3f97ee1fe251374b7a64862d4ac53df677 100644 --- a/src/layers/object.rs +++ b/src/layers/object.rs @@ -11,8 +11,7 @@ use crate::{ /// Raw data referring to a map object layer or tile collision data. #[derive(Debug, PartialEq, Clone)] pub struct ObjectLayerData { - /// The objects present in this layer. - pub objects: Vec<ObjectData>, + objects: Vec<ObjectData>, /// The color used in the editor to display objects in this layer. pub colour: Option<Color>, } @@ -45,6 +44,13 @@ impl ObjectLayerData { }); Ok((ObjectLayerData { objects, colour: c }, properties)) } + + /// Returns the data belonging to the objects contained within the layer, in the order they were + /// declared in the TMX file. + #[inline] + pub fn object_data(&self) -> &[ObjectData] { + self.objects.as_ref() + } } map_wrapper!( @@ -62,14 +68,10 @@ impl<'map> ObjectLayer<'map> { /// Returns an iterator over the objects present in this layer, in the order they were declared /// in in the TMX file. + #[inline] pub fn objects(&self) -> Objects<'map> { Objects::new(self.map, self.data) } - - /// Get a reference to the object layer's colour. - pub fn colour(&self) -> Option<Color> { - self.data.colour - } } /// An iterator that iterates over all the objects in an object layer, obtained via [`ObjectLayer::objects`]. @@ -81,6 +83,7 @@ pub struct Objects<'map> { } impl<'map> Objects<'map> { + #[inline] fn new(map: &'map Map, data: &'map ObjectLayerData) -> Self { Self { map, diff --git a/src/layers/tile/finite.rs b/src/layers/tile/finite.rs index ca6f768c4654aa5ef07604b75830bd3d58f54e57..df36f12a1d45e4e442ed2f20d1a048f6b93e1fa7 100644 --- a/src/layers/tile/finite.rs +++ b/src/layers/tile/finite.rs @@ -7,8 +7,9 @@ use crate::{ use super::util::parse_data_line; +/// The raw data of a [`FiniteTileLayer`]. Does not include a reference to its parent [`Map`](crate::Map). #[derive(PartialEq, Clone, Default)] -pub(crate) struct FiniteTileLayerData { +pub struct FiniteTileLayerData { width: u32, height: u32, /// The tiles are arranged in rows. @@ -25,6 +26,18 @@ impl std::fmt::Debug for FiniteTileLayerData { } impl FiniteTileLayerData { + /// Get the tile layer's width in tiles. + #[inline] + pub fn width(&self) -> u32 { + self.width + } + + /// Get the tile layer's height in tiles. + #[inline] + pub fn height(&self) -> u32 { + self.height + } + pub(crate) fn new( parser: &mut impl Iterator<Item = XmlEventResult>, attrs: Vec<OwnedAttribute>, @@ -65,23 +78,11 @@ map_wrapper!( impl<'map> FiniteTileLayer<'map> { /// Obtains the tile present at the position given. - /// + /// /// If the position given is invalid or the position is empty, this function will return [`None`]. pub fn get_tile(&self, x: i32, y: i32) -> Option<LayerTile> { self.data .get_tile(x, y) .and_then(|data| Some(LayerTile::new(self.map(), data))) } - - /// Get the tile layer's width in tiles. - #[inline] - pub fn width(&self) -> u32 { - self.data.width - } - - /// Get the tile layer's height in tiles. - #[inline] - pub fn height(&self) -> u32 { - self.data.height - } } diff --git a/src/layers/tile/infinite.rs b/src/layers/tile/infinite.rs index 39f5715a38fc61cfd8d0775d818511c39fa4fa6b..674e1986efec8276894b9dc52de7cdacbdbb7ca2 100644 --- a/src/layers/tile/infinite.rs +++ b/src/layers/tile/infinite.rs @@ -9,8 +9,9 @@ use crate::{ use super::util::parse_data_line; +/// The raw data of a [`InfiniteTileLayer`]. Does not include a reference to its parent [`Map`](crate::Map). #[derive(PartialEq, Clone)] -pub(crate) struct InfiniteTileLayerData { +pub struct InfiniteTileLayerData { chunks: HashMap<(i32, i32), Chunk>, } diff --git a/src/layers/tile/mod.rs b/src/layers/tile/mod.rs index c9746d72b19b401b3f14a1b22f362c7f0e9687c1..d497e555bea60b0befe32f7499ea3e761aa504c7 100644 --- a/src/layers/tile/mod.rs +++ b/src/layers/tile/mod.rs @@ -17,19 +17,39 @@ pub use infinite::*; /// Stores the internal tile gid about a layer tile, along with how it is flipped. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) struct LayerTileData { +pub struct LayerTileData { /// The index of the tileset this tile's in, relative to the tile's map. Guaranteed to be a /// valid index of the map tileset container, but **isn't guaranteed to actually contain /// this tile**. tileset_index: usize, /// The local ID of the tile in the tileset it's in. id: TileId, - flip_h: bool, - flip_v: bool, - flip_d: bool, + /// Whether this tile is flipped on its Y axis (horizontally). + pub flip_h: bool, + /// Whether this tile is flipped on its X axis (vertically). + pub flip_v: bool, + /// Whether this tile is flipped diagonally. + pub flip_d: bool, } impl LayerTileData { + /// Get the layer tile's tileset index. Guaranteed to be a + /// valid index of the map tileset container, but **isn't guaranteed to actually contain + /// this tile**. + /// + /// Use [`LayerTile::get_tile`] if you want to obtain the [`Tile`] that this layer tile is + /// referencing. + #[inline] + pub fn tileset_index(&self) -> usize { + self.tileset_index + } + + /// Get the layer tile's local id within its parent tileset. + #[inline] + pub fn id(&self) -> u32 { + self.id + } + const FLIPPED_HORIZONTALLY_FLAG: u32 = 0x80000000; const FLIPPED_VERTICALLY_FLAG: u32 = 0x40000000; const FLIPPED_DIAGONALLY_FLAG: u32 = 0x20000000; @@ -111,49 +131,16 @@ map_wrapper!( impl<'map> LayerTile<'map> { /// Get a reference to the layer tile's referenced tile, if it exists. + #[inline] pub fn get_tile(&self) -> Option<Tile<'map>> { self.get_tileset().get_tile(self.data.id) } /// Get a reference to the layer tile's referenced tileset. + #[inline] pub fn get_tileset(&self) -> &'map Tileset { // SAFETY: `tileset_index` is guaranteed to be valid &self.map.tilesets()[self.data.tileset_index] } - - /// Get the layer tile's tileset index. Guaranteed to be a - /// valid index of the map tileset container, but **isn't guaranteed to actually contain - /// this tile**. - /// - /// Use [`LayerTile::get_tile`] if you want to obtain the [`Tile`] that this layer tile is - /// referencing. - #[inline] - pub fn tileset_index(&self) -> usize { - self.data.tileset_index - } - - /// Get the layer tile's local id within its parent tileset. - #[inline] - pub fn id(&self) -> u32 { - self.data.id - } - - /// Whether this tile is flipped on its Y axis (horizontally). - #[inline] - pub fn flip_h(&self) -> bool { - self.data.flip_h - } - - /// Whether this tile is flipped on its X axis (vertically). - #[inline] - pub fn flip_v(&self) -> bool { - self.data.flip_v - } - - /// Whether this tile is flipped diagonally. - #[inline] - pub fn flip_d(&self) -> bool { - self.data.flip_d - } } /// A map layer containing tiles in some way. May be finite or infinite. @@ -174,7 +161,7 @@ impl<'map> TileLayer<'map> { } /// Obtains the tile present at the position given. - /// + /// /// If the position given is invalid or the position is empty, this function will return [`None`]. pub fn get_tile(&self, x: i32, y: i32) -> Option<LayerTile> { match self { diff --git a/src/lib.rs b/src/lib.rs index 306008646a16dba8e897ee78d70c0349c0d7c338..951c971bf951c4362ee7c0a5317d2b14386ee08d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![doc = include_str!("../README.md")] -#![deny(missing_docs)] +#![warn(missing_docs)] #![deny(rustdoc::broken_intra_doc_links)] #![deny(unsafe_code)] #![deny(missing_copy_implementations)] diff --git a/src/map.rs b/src/map.rs index 17504b9b5ce6b0f24816da0a5e209682303523bc..10780b26f7e361fc6afa4c86db2ebe04637de629 100644 --- a/src/map.rs +++ b/src/map.rs @@ -21,17 +21,32 @@ pub(crate) struct MapTilesetGid { /// All Tiled map files will be parsed into this. Holds all the layers and tilesets. #[derive(PartialEq, Clone, Debug)] pub struct Map { - /// The TMX format version this map was saved to. - pub version: String, + version: String, /// The way tiles are laid out in the map. pub orientation: Orientation, /// Width of the map, in tiles. + /// + /// ## Note + /// There is no guarantee that this value will be the same as the width from its tile layers. pub width: u32, /// Height of the map, in tiles. + /// + /// ## Note + /// There is no guarantee that this value will be the same as the height from its tile layers. pub height: u32, /// Tile width, in pixels. + /// + /// ## Note + /// This value along with [`Self::tile_height`] determine the general size of the map, and + /// individual tiles may have different sizes. As such, there is no guarantee that this value + /// will be the same as the one from the tilesets the map is using. pub tile_width: u32, /// Tile height, in pixels. + /// + /// ## Note + /// This value along with [`Self::tile_width`] determine the general size of the map, and + /// individual tiles may have different sizes. As such, there is no guarantee that this value + /// will be the same as the one from the tilesets the map is using. pub tile_height: u32, /// The tilesets present on this map. tilesets: Vec<Arc<Tileset>>, @@ -41,9 +56,7 @@ pub struct Map { pub properties: Properties, /// The background color of this map, if any. pub background_color: Option<Color>, - /// Whether this map is infinite. An infinite map has no fixed size and can grow in all - /// directions. Its layer data is stored in chunks. - pub infinite: bool, + infinite: bool, } impl Map { @@ -101,15 +114,30 @@ impl Map { })?; Self::parse_reader(reader, path.as_ref(), cache) } + + /// The TMX format version this map was saved to. Equivalent to the map file's `version` + /// attribute. + pub fn version(&self) -> &str { + self.version.as_ref() + } + + /// Whether this map is infinite. An infinite map has no fixed size and can grow in all + /// directions. Its layer data is stored in chunks. This value determines whether the map's + /// tile layers are [`FiniteTileLayer`](crate::FiniteTileLayer)s or [`crate::InfiniteTileLayer`](crate::InfiniteTileLayer)s. + pub fn infinite(&self) -> bool { + self.infinite + } } impl Map { /// Get a reference to the map's tilesets. + #[inline] pub fn tilesets(&self) -> &[Arc<Tileset>] { self.tilesets.as_ref() } /// Get an iterator over all the layers in the map in ascending order of their layer index. + #[inline] pub fn layers(&self) -> MapLayerIter { MapLayerIter::new(self) } diff --git a/src/objects.rs b/src/objects.rs index f59df80baa98463a2b8ec879594a952b80d6bf8d..8c06a2903f7f5affe6b04666b8e7693eb7747bce 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -27,10 +27,7 @@ pub enum ObjectShape { /// Also see the [TMX docs](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tmx-object). #[derive(Debug, PartialEq, Clone)] pub struct ObjectData { - /// ID of the object, which is unique per map since Tiled 0.11. - /// - /// On older versions this value is defaulted to 0. - pub id: u32, + id: u32, tile: Option<LayerTileData>, /// The name of the object, which is arbitrary and set by the user. pub name: String, @@ -56,10 +53,26 @@ pub struct ObjectData { pub visible: bool, /// The object's shape. pub shape: ObjectShape, - /// The object's custom properties set by the user. + /// The object's custom properties as set by the user. pub properties: Properties, } +impl ObjectData { + /// ID of the object, which is unique per map since Tiled 0.11. + /// + /// On older versions this value is defaulted to 0. + #[inline] + pub fn id(&self) -> u32 { + self.id + } + + /// Returns the data of the tile that this object is referencing, if it exists. + #[inline] + pub fn tile_data(&self) -> Option<LayerTileData> { + self.tile + } +} + impl ObjectData { /// If it is known that the object has no tile images in it (i.e. collision data) /// then we can pass in [`None`] as the tilesets @@ -199,14 +212,6 @@ map_wrapper!( ); impl<'map> Object<'map> { - /// ID of the object, which is unique per map since Tiled 0.11. - /// - /// On older versions this value is defaulted to 0. - #[inline] - pub fn id(&self) -> u32 { - self.data.id - } - /// Returns the tile that the object is using as image, if any. pub fn get_tile(&self) -> Option<LayerTile<'map>> { self.data @@ -214,72 +219,4 @@ impl<'map> Object<'map> { .as_ref() .map(|tile| LayerTile::new(self.map, tile)) } - - /// The name of the object, which is arbitrary and set by the user. - #[inline] - pub fn name(&self) -> &str { - self.data.name.as_ref() - } - - /// The type of the object, which is arbitrary and set by the user. - #[inline] - pub fn obj_type(&self) -> &str { - self.data.obj_type.as_ref() - } - - /// The width of the object, if applicable. This refers to the attribute in `object`. - /// Since it is duplicate or irrelevant information in all cases, use the equivalent - /// member in [`ObjectShape`] instead. - #[deprecated(since = "0.10.0", note = "Use [`ObjectShape`] members instead")] - #[inline] - pub fn width(&self) -> f32 { - #[allow(deprecated)] - self.data.width - } - - /// The height of the object, if applicable. This refers to the attribute in `object`. - /// Since it is duplicate or irrelevant information in all cases, use the equivalent - /// member in [`ObjectShape`] instead. - #[deprecated(since = "0.10.0", note = "Use [`ObjectShape`] members instead")] - #[inline] - pub fn height(&self) -> f32 { - #[allow(deprecated)] - self.data.height - } - - /// The X coordinate of this object in pixels. - #[inline] - pub fn x(&self) -> f32 { - self.data.x - } - - /// The Y coordinate of this object in pixels. - #[inline] - pub fn y(&self) -> f32 { - self.data.y - } - - /// The clockwise rotation of this object around (x,y) in degrees. - #[inline] - pub fn rotation(&self) -> f32 { - self.data.rotation - } - - /// Whether the object is shown or hidden. - #[inline] - pub fn visible(&self) -> bool { - self.data.visible - } - - /// The object's shape. - #[inline] - pub fn shape(&self) -> &ObjectShape { - &self.data.shape - } - - /// The object's custom properties set by the user. - #[inline] - pub fn properties(&self) -> &Properties { - &self.data.properties - } } diff --git a/src/util.rs b/src/util.rs index aca93cdf1f47579e3eb306ab5262435e3f220552..0949ee3ce93cfc0baa8d6445acef60de0e7fa11f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -98,6 +98,15 @@ macro_rules! map_wrapper { self.map } } + + impl<'map> std::ops::Deref for $name<'map> { + type Target = $data_ty; + + #[inline] + fn deref(&self) -> &'map Self::Target { + self.data + } + } }; } diff --git a/tests/lib.rs b/tests/lib.rs index 01b2d0f0ae69ce07e13230a11c22d3c168c0af91..99eaf2713e7250d934b09f4987b4a86e314cf7ca 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -33,7 +33,7 @@ fn as_group_layer<'map>(layer: Layer<'map>) -> GroupLayer<'map> { } fn compare_everything_but_tileset_sources(r: &Map, e: &Map) { - assert_eq!(r.version, e.version); + assert_eq!(r.version(), e.version()); assert_eq!(r.orientation, e.orientation); assert_eq!(r.width, e.width); assert_eq!(r.height, e.height); @@ -41,7 +41,7 @@ fn compare_everything_but_tileset_sources(r: &Map, e: &Map) { assert_eq!(r.tile_height, e.tile_height); assert_eq!(r.properties, e.properties); assert_eq!(r.background_color, e.background_color); - assert_eq!(r.infinite, e.infinite); + assert_eq!(r.infinite(), e.infinite()); // TODO: Also compare layers /* r.layers() @@ -163,20 +163,21 @@ fn test_image_layers() { }); { let first = image_layers.next().unwrap(); - assert_eq!(first.1.name(), "Image Layer 1"); + assert_eq!(first.1.name, "Image Layer 1"); assert!( - first.0.image().is_none(), + first.0.image.is_none(), "{}'s image should be None", - first.1.name() + first.1.name ); } { let second = image_layers.next().unwrap(); - assert_eq!(second.1.name(), "Image Layer 2"); + assert_eq!(second.1.name, "Image Layer 2"); let image = second .0 - .image() - .expect(&format!("{}'s image shouldn't be None", second.1.name())); + .image + .as_ref() + .expect(&format!("{}'s image shouldn't be None", second.1.name)); assert_eq!(image.source, PathBuf::from("assets/tilesheet.png")); assert_eq!(image.width, 448); assert_eq!(image.height, 192); @@ -207,7 +208,7 @@ fn test_layer_property() { let r = Map::parse_file("assets/tiled_base64.tmx", &mut cache).unwrap(); let prop_value: String = if let Some(&PropertyValue::StringValue(ref v)) = - r.get_layer(0).unwrap().properties().get("prop3") + r.get_layer(0).unwrap().properties.get("prop3") { v.clone() } else { @@ -225,7 +226,7 @@ fn test_object_group_property() { let group_layer = as_group_layer(group_layer); let sub_layer = group_layer.get_layer(0).unwrap(); let prop_value: bool = if let Some(&PropertyValue::BoolValue(ref v)) = - sub_layer.properties().get("an object group property") + sub_layer.properties.get("an object group property") { *v } else { @@ -262,18 +263,18 @@ fn test_flipped() { assert_eq!(t1.id(), t2.id()); assert_eq!(t2.id(), t3.id()); assert_eq!(t3.id(), t4.id()); - assert!(t1.flip_d()); - assert!(t1.flip_h()); - assert!(t1.flip_v()); - assert!(!t2.flip_d()); - assert!(!t2.flip_h()); - assert!(t2.flip_v()); - assert!(!t3.flip_d()); - assert!(t3.flip_h()); - assert!(!t3.flip_v()); - assert!(t4.flip_d()); - assert!(!t4.flip_h()); - assert!(!t4.flip_v()); + assert!(t1.flip_d); + assert!(t1.flip_h); + assert!(t1.flip_v); + assert!(!t2.flip_d); + assert!(!t2.flip_h); + assert!(t2.flip_v); + assert!(!t3.flip_d); + assert!(t3.flip_h); + assert!(!t3.flip_v); + assert!(t4.flip_d); + assert!(!t4.flip_h); + assert!(!t4.flip_v); } #[test] @@ -298,19 +299,19 @@ fn test_parallax_layers() { for (i, layer) in r.layers().enumerate() { match i { 0 => { - assert_eq!(layer.name(), "Background"); - assert_eq!(layer.parallax_x(), 0.5); - assert_eq!(layer.parallax_y(), 0.75); + assert_eq!(layer.name, "Background"); + assert_eq!(layer.parallax_x, 0.5); + assert_eq!(layer.parallax_y, 0.75); } 1 => { - assert_eq!(layer.name(), "Middle"); - assert_eq!(layer.parallax_x(), 1.0); - assert_eq!(layer.parallax_y(), 1.0); + assert_eq!(layer.name, "Middle"); + assert_eq!(layer.parallax_x, 1.0); + assert_eq!(layer.parallax_y, 1.0); } 2 => { - assert_eq!(layer.name(), "Foreground"); - assert_eq!(layer.parallax_x(), 2.0); - assert_eq!(layer.parallax_y(), 2.0); + assert_eq!(layer.name, "Foreground"); + assert_eq!(layer.parallax_x, 2.0); + assert_eq!(layer.parallax_y, 2.0); } _ => panic!("unexpected layer"), } @@ -326,7 +327,7 @@ fn test_object_property() { let prop_value = if let Some(PropertyValue::ObjectValue(v)) = as_object_layer(layer) .get_object(0) .unwrap() - .properties() + .properties .get("object property") { *v @@ -342,7 +343,7 @@ fn test_tint_color() { let r = Map::parse_file("assets/tiled_image_layers.tmx", &mut cache).unwrap(); assert_eq!( - r.get_layer(0).unwrap().tint_color(), + r.get_layer(0).unwrap().tint_color, Some(Color { alpha: 0x12, red: 0x34, @@ -351,7 +352,7 @@ fn test_tint_color() { }) ); assert_eq!( - r.get_layer(1).unwrap().tint_color(), + r.get_layer(1).unwrap().tint_color, Some(Color { alpha: 0xFF, red: 0x12, @@ -374,7 +375,7 @@ fn test_group_layers() { assert_eq!( Some(&PropertyValue::StringValue("value1".to_string())), - layer_tile_1.properties().get("key") + layer_tile_1.properties.get("key") ); assert_eq!( Some(&PropertyValue::ColorValue(Color { @@ -383,11 +384,11 @@ fn test_group_layers() { green: 0x56, blue: 0x78 })), - layer_group_1.properties().get("key") + layer_group_1.properties.get("key") ); assert_eq!( Some(&PropertyValue::StringValue("value5".to_string())), - layer_group_2.properties().get("key") + layer_group_2.properties.get("key") ); // Depth = 1 @@ -397,11 +398,11 @@ fn test_group_layers() { let layer_group_3 = layer_group_2.get_layer(0).unwrap(); assert_eq!( Some(&PropertyValue::StringValue("value2".to_string())), - layer_tile_2.properties().get("key") + layer_tile_2.properties.get("key") ); assert_eq!( Some(&PropertyValue::StringValue("value6".to_string())), - layer_group_3.properties().get("key") + layer_group_3.properties.get("key") ); // Depth = 2 @@ -409,6 +410,6 @@ fn test_group_layers() { let layer_tile_3 = layer_group_3.get_layer(0).unwrap(); assert_eq!( Some(&PropertyValue::StringValue("value3".to_string())), - layer_tile_3.properties().get("key") + layer_tile_3.properties.get("key") ); }