Skip to content
Snippets Groups Projects
Unverified Commit fd15cb4c authored by aleok's avatar aleok Committed by GitHub
Browse files

Merge pull request #111 from PieKing1215/layer-id

Add layer id parsing
parents 7585b490 3a7b069f
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,9 @@ pub struct Layer { ...@@ -54,6 +54,9 @@ pub struct Layer {
pub tiles: LayerData, pub tiles: LayerData,
pub properties: Properties, pub properties: Properties,
pub layer_index: u32, 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 { impl Layer {
...@@ -64,7 +67,7 @@ impl Layer { ...@@ -64,7 +67,7 @@ impl Layer {
layer_index: u32, layer_index: u32,
infinite: bool, infinite: bool,
) -> Result<Layer, TiledError> { ) -> Result<Layer, TiledError> {
let ((o, v, ox, oy), n) = get_attrs!( let ((o, v, ox, oy), (n, id)) = get_attrs!(
attrs, attrs,
optionals: [ optionals: [
("opacity", opacity, |v:String| v.parse().ok()), ("opacity", opacity, |v:String| v.parse().ok()),
...@@ -74,6 +77,7 @@ impl Layer { ...@@ -74,6 +77,7 @@ impl Layer {
], ],
required: [ required: [
("name", name, |v| Some(v)), ("name", name, |v| Some(v)),
("id", id, |v:String| v.parse().ok()),
], ],
TiledError::MalformedAttributes("layer must have a name".to_string()) TiledError::MalformedAttributes("layer must have a name".to_string())
); );
...@@ -103,6 +107,7 @@ impl Layer { ...@@ -103,6 +107,7 @@ impl Layer {
tiles: tiles, tiles: tiles,
properties: properties, properties: properties,
layer_index, layer_index,
id,
}) })
} }
} }
......
...@@ -20,6 +20,9 @@ pub struct ObjectGroup { ...@@ -20,6 +20,9 @@ pub struct ObjectGroup {
*/ */
pub layer_index: Option<u32>, pub layer_index: Option<u32>,
pub properties: Properties, 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 { impl ObjectGroup {
...@@ -28,7 +31,7 @@ impl ObjectGroup { ...@@ -28,7 +31,7 @@ impl ObjectGroup {
attrs: Vec<OwnedAttribute>, attrs: Vec<OwnedAttribute>,
layer_index: Option<u32>, layer_index: Option<u32>,
) -> Result<ObjectGroup, TiledError> { ) -> Result<ObjectGroup, TiledError> {
let ((o, v, c, n), ()) = get_attrs!( let ((o, v, c, n), id) = get_attrs!(
attrs, attrs,
optionals: [ optionals: [
("opacity", opacity, |v:String| v.parse().ok()), ("opacity", opacity, |v:String| v.parse().ok()),
...@@ -36,7 +39,9 @@ impl ObjectGroup { ...@@ -36,7 +39,9 @@ impl ObjectGroup {
("color", colour, |v:String| v.parse().ok()), ("color", colour, |v:String| v.parse().ok()),
("name", name, |v:String| v.into()), ("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()) TiledError::MalformedAttributes("object groups must have a name".to_string())
); );
let mut objects = Vec::new(); let mut objects = Vec::new();
...@@ -59,6 +64,7 @@ impl ObjectGroup { ...@@ -59,6 +64,7 @@ impl ObjectGroup {
colour: c, colour: c,
layer_index, layer_index,
properties, properties,
id,
}) })
} }
} }
......
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