diff --git a/src/layers.rs b/src/layers.rs index b802c569add9753496fd1fb37a210bf5ce313eb5..19bb2ce266f4a97f2f57f9a093eba13eabb8bbbd 100644 --- a/src/layers.rs +++ b/src/layers.rs @@ -54,6 +54,9 @@ pub struct Layer { pub tiles: LayerData, pub properties: Properties, pub layer_index: u32, + /// The ID of the layer, as shown in the editor. + /// Layer ID stays the same even if layers are reordered or modified in the editor. + pub id: u32, } impl Layer { @@ -64,7 +67,7 @@ impl Layer { layer_index: u32, infinite: bool, ) -> Result<Layer, TiledError> { - let ((o, v, ox, oy), n) = get_attrs!( + let ((o, v, ox, oy), (n, id)) = get_attrs!( attrs, optionals: [ ("opacity", opacity, |v:String| v.parse().ok()), @@ -74,6 +77,7 @@ impl Layer { ], required: [ ("name", name, |v| Some(v)), + ("id", id, |v:String| v.parse().ok()), ], TiledError::MalformedAttributes("layer must have a name".to_string()) ); @@ -103,6 +107,7 @@ impl Layer { tiles: tiles, properties: properties, layer_index, + id, }) } } diff --git a/src/objects.rs b/src/objects.rs index 3e5edf919dea4938bee8111f7f77ce5597455203..1329cc9fa3fbf90309e42c02d9c518867caa7811 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -20,6 +20,9 @@ pub struct ObjectGroup { */ pub layer_index: Option<u32>, pub properties: Properties, + /// The ID of the layer, as shown in the editor. + /// Layer ID stays the same even if layers are reordered or modified in the editor. + pub id: u32, } impl ObjectGroup { @@ -28,7 +31,7 @@ impl ObjectGroup { attrs: Vec<OwnedAttribute>, layer_index: Option<u32>, ) -> Result<ObjectGroup, TiledError> { - let ((o, v, c, n), ()) = get_attrs!( + let ((o, v, c, n), id) = get_attrs!( attrs, optionals: [ ("opacity", opacity, |v:String| v.parse().ok()), @@ -36,7 +39,9 @@ impl ObjectGroup { ("color", colour, |v:String| v.parse().ok()), ("name", name, |v:String| v.into()), ], - required: [], + required: [ + ("id", id, |v:String| v.parse().ok()), + ], TiledError::MalformedAttributes("object groups must have a name".to_string()) ); let mut objects = Vec::new(); @@ -59,6 +64,7 @@ impl ObjectGroup { colour: c, layer_index, properties, + id, }) } }