diff --git a/CHANGELOG.md b/CHANGELOG.md index 81578ade..21ad40cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,15 +10,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Template support! Templates are loaded automatically when they are encountered, and are treated as intermediate objects. As such, `ResourceCache` has now methods for both getting and inserting them (#170). -- Text object support (#230). - VFS support (#199). +- Text object support (#230). - `cache_mut` loader property (#207). ### Changed - `LayerType` variants have been stripped from the `Layer` suffix (#203). +- `TileData::tile_type` has been renamed to `TileData::user_type`. (#253) +- `Orientation`'s `FromStr` impl now returns `OrientationParseError` as the error type. (#253) - `ResourceCache::get_or_try_insert_tileset_with` has been replaced by `ResourceCache::insert_tileset`. - `DefaultResourceCache`'s members have been made public. +### Removed +- `ObjectData::obj_type`, `ObjectData::width`, `ObjectData::height`. (#253) +- `TileData::tile_type` (which has been renamed to `TileData::user_type`) (#253) + ## [0.10.3] ### Added - Support for Wang sets. diff --git a/src/layers/object.rs b/src/layers/object.rs index 39ff4d69..e1716ea1 100644 --- a/src/layers/object.rs +++ b/src/layers/object.rs @@ -92,7 +92,7 @@ impl<'map> ObjectLayer<'map> { /// _ => None, /// }) /// .flat_map(|layer| layer.objects()) - /// .filter(|object| object.obj_type == "spawn") + /// .filter(|object| object.user_type == "spawn") /// .collect(); /// /// dbg!(spawnpoints); diff --git a/src/loader.rs b/src/loader.rs index 53ceeb3e..2faf917a 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -7,7 +7,25 @@ use crate::{DefaultResourceCache, Map, ResourceCache, Result, Tileset}; /// This trait should be implemented if you wish to load data from a virtual filesystem. /// /// ## Example -/// TODO: ResourceReader example +/// ``` +/// use std::io::Cursor; +/// +/// /// Basic example reader impl that just keeps a few resources in memory +/// struct MemoryReader; +/// +/// impl tiled::ResourceReader for MemoryReader { +/// type Resource = Cursor<&'static [u8]>; +/// type Error = std::io::Error; +/// +/// fn read_from(&mut self, path: &std::path::Path) -> std::result::Result { +/// if path == std::path::Path::new("my_map.tmx") { +/// Ok(Cursor::new(include_bytes!("../assets/tiled_xml.tmx"))) +/// } else { +/// Err(std::io::Error::new(std::io::ErrorKind::NotFound, "file not found")) +/// } +/// } +/// } +/// ``` pub trait ResourceReader { /// The type of the resource that the reader provides. For example, for /// [`FilesystemResourceReader`], this is defined as [`File`]. diff --git a/src/map.rs b/src/map.rs index c0bbabf8..dd689d19 100644 --- a/src/map.rs +++ b/src/map.rs @@ -267,9 +267,24 @@ pub enum Orientation { Hexagonal, } +#[derive(Debug)] +/// An error arising from trying to parse an [`Orientation`] that is not valid. +pub struct OrientationParseError { + /// The invalid string found. + pub str_found: String, +} + +impl std::fmt::Display for OrientationParseError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_fmt(format_args!("failed to parse orientation, valid options are `orthogonal`, `isometric`, `staggered` \ + and `hexagonal` but got `{}` instead", self.str_found)) + } +} + +impl std::error::Error for OrientationParseError {} + impl FromStr for Orientation { - // TODO(0.11): Change error type to OrientationParseErr or similar - type Err = (); + type Err = OrientationParseError; fn from_str(s: &str) -> std::result::Result { match s { @@ -277,7 +292,9 @@ impl FromStr for Orientation { "isometric" => Ok(Orientation::Isometric), "staggered" => Ok(Orientation::Staggered), "hexagonal" => Ok(Orientation::Hexagonal), - _ => Err(()), + _ => Err(OrientationParseError { + str_found: s.to_owned(), + }), } } } diff --git a/src/objects.rs b/src/objects.rs index bcd80d5f..db3ed16c 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -182,19 +182,6 @@ pub struct ObjectData { pub name: String, /// The type of the object, which is arbitrary and set by the user. pub user_type: String, - /// This property has been renamed to `user_type`. - #[deprecated(since = "0.10.3", note = "Use [`ObjectData::user_type`] instead")] - pub obj_type: String, - /// 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")] - pub width: f32, - /// 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")] - pub height: f32, /// The X coordinate of this object in pixels. pub x: f32, /// The Y coordinate of this object in pixels. @@ -238,7 +225,7 @@ impl ObjectData { reader: &mut impl ResourceReader, cache: &mut impl ResourceCache, ) -> Result { - let (id, tile, mut n, mut t, c, mut w, mut h, mut v, mut r, template, x, y) = get_attrs!( + let (id, tile, mut n, mut t, c, w, h, mut v, mut r, template, x, y) = get_attrs!( for v in attrs { Some("id") => id ?= v.parse(), Some("gid") => tile ?= v.parse::(), @@ -278,10 +265,6 @@ impl ObjectData { // The template sets the default values for the object let obj = &template.object; v.get_or_insert(obj.visible); - #[allow(deprecated)] - w.get_or_insert(obj.width); - #[allow(deprecated)] - h.get_or_insert(obj.height); r.get_or_insert(obj.rotation); n.get_or_insert_with(|| obj.name.clone()); t.get_or_insert_with(|| obj.user_type.clone()); @@ -346,15 +329,11 @@ impl ObjectData { let shape = shape.unwrap_or(ObjectShape::Rect { width, height }); - #[allow(deprecated)] Ok(ObjectData { id, tile, name, - obj_type: user_type.clone(), user_type, - width, - height, x, y, rotation, diff --git a/src/tile.rs b/src/tile.rs index 6b6131cf..a0a4ae65 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -27,9 +27,7 @@ pub struct TileData { /// The animation frames of this tile. pub animation: Option>, /// The type of this tile. - // TODO(0.11.0): Rename to `user_type` (https://github.com/mapeditor/rs-tiled/pull/238, postponed because of - // breaking change) - pub tile_type: Option, + pub user_type: Option, /// The probability of this tile. pub probability: f32, } @@ -105,13 +103,12 @@ impl TileData { }); Ok(( id, - #[allow(deprecated)] TileData { image, properties, collision: objectgroup, animation, - tile_type: user_type, + user_type, probability: probability.unwrap_or(1.0), }, ))