Skip to content
Snippets Groups Projects
Unverified Commit dab7cb6b authored by Alejandro Perea's avatar Alejandro Perea Committed by GitHub
Browse files

Add some missing attributes (#173)

* Add attributes
- `#[inline]` for properties
- `#![deny(unsafe_code)]`
- `#![deny(missing_copy_implementations)]`
- `#![deny(missing_debug_implementations)]`

* Add more inline attributes

* Merge with upstream
parent f679def4
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ use xml::attribute::OwnedAttribute;
use crate::{error::TiledError, util::{get_attrs, XmlEventResult, parse_tag}};
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Frame {
pub tile_id: u32,
pub duration: u32,
......
......@@ -21,6 +21,7 @@ pub trait ResourceCache {
}
/// A cache that identifies resources by their path in the user's filesystem.
#[derive(Debug)]
pub struct FilesystemResourceCache {
tilesets: HashMap<ResourcePathBuf, Arc<Tileset>>,
}
......
......@@ -93,6 +93,7 @@ impl<'map> GroupLayer<'map> {
}
/// An iterator that iterates over all the layers in a group layer, obtained via [`GroupLayer::layers`].
#[derive(Debug)]
pub struct GroupLayerIter<'map> {
map: &'map Map,
group: &'map GroupLayerData,
......
......@@ -39,6 +39,7 @@ map_wrapper!(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()
}
......
......@@ -114,61 +114,73 @@ map_wrapper!(Layer => LayerData);
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> {
LayerType::new(self.map, &self.data.layer_type)
}
}
#[derive(Debug)]
pub enum LayerType<'map> {
TileLayer(TileLayer<'map>),
ObjectLayer(ObjectLayer<'map>),
......
......@@ -64,6 +64,7 @@ impl<'map> ObjectLayer<'map> {
}
/// An iterator that iterates over all the objects in an object layer, obtained via [`ObjectLayer::objects`].
#[derive(Debug)]
pub struct Objects<'map> {
map: &'map Map,
data: &'map ObjectLayerData,
......@@ -91,6 +92,7 @@ impl<'map> Iterator for Objects<'map> {
}
impl<'map> ExactSizeIterator for Objects<'map> {
#[inline]
fn len(&self) -> usize {
self.data.objects.len() - self.index
}
......
......@@ -70,11 +70,13 @@ impl<'map> FiniteTileLayer<'map> {
}
/// 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
}
......
......@@ -125,31 +125,37 @@ impl<'map> LayerTile<'map> {
///
/// 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
}
}
#[derive(Debug)]
pub enum TileLayer<'map> {
Finite(FiniteTileLayer<'map>),
Infinite(InfiniteTileLayer<'map>),
......
#![deny(unsafe_code)]
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]
mod animation;
mod cache;
mod error;
......
......@@ -116,6 +116,7 @@ impl Map {
}
/// An iterator that iterates over all the layers in a map, obtained via [`Map::layers`].
#[derive(Debug)]
pub struct MapLayerIter<'map> {
map: &'map Map,
index: usize,
......
......@@ -172,6 +172,7 @@ map_wrapper!(Object => ObjectData);
impl<'map> Object<'map> {
/// Get the object's id.
#[inline]
pub fn id(&self) -> u32 {
self.data.id
}
......@@ -185,51 +186,61 @@ impl<'map> Object<'map> {
}
/// Get a reference to the object's name.
#[inline]
pub fn name(&self) -> &str {
self.data.name.as_ref()
}
/// Get a reference to the object's type.
#[inline]
pub fn obj_type(&self) -> &str {
self.data.obj_type.as_ref()
}
/// Get the object's width.
#[inline]
pub fn width(&self) -> f32 {
self.data.width
}
/// Get the object's height.
#[inline]
pub fn height(&self) -> f32 {
self.data.height
}
/// Get the object's x.
#[inline]
pub fn x(&self) -> f32 {
self.data.x
}
/// Get object's y.
#[inline]
pub fn y(&self) -> f32 {
self.data.y
}
/// Get a reference to the object's rotation.
#[inline]
pub fn rotation(&self) -> f32 {
self.data.rotation
}
/// Whether the object should be visible or not.
#[inline]
pub fn visible(&self) -> bool {
self.data.visible
}
/// Get a reference to the object's shape.
#[inline]
pub fn shape(&self) -> &ObjectShape {
&self.data.shape
}
/// Get a reference to the object's properties.
#[inline]
pub fn properties(&self) -> &Properties {
&self.data.properties
}
......
......@@ -24,6 +24,7 @@ pub(crate) struct TileData {
probability: f32,
}
#[derive(Debug)]
pub struct Tile<'tileset> {
pub(crate) tileset: &'tileset Tileset,
pub(crate) data: &'tileset TileData,
......
......@@ -106,6 +106,7 @@ impl Tileset {
}
/// Gets the tile with the specified ID from the tileset.
#[inline]
pub fn get_tile(&self, id: u32) -> Option<Tile> {
self.tiles.get(&id).map(|data| Tile::new(self, data))
}
......
......@@ -55,18 +55,20 @@ macro_rules! parse_tag {
/// Creates a new type that wraps an internal data type over along with a map.
macro_rules! map_wrapper {
($name:ident => $data_ty:ty) => {
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct $name<'map> {
pub(crate) map: &'map $crate::Map,
pub(crate) data: &'map $data_ty,
}
impl<'map> $name<'map> {
#[inline]
pub(crate) fn new(map: &'map $crate::Map, data: &'map $data_ty) -> Self {
Self { map, data }
}
/// Get the map this object is from.
#[inline]
pub fn map(&self) -> &'map $crate::Map {
self.map
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment