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 {
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,
})
}
}
......
......@@ -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,
})
}
}
......
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