Newer
Older
error::Result,
layers::{LayerData, LayerTag},
properties::{parse_properties, Properties},
/// The raw data of a [`GroupLayer`]. Does not include a reference to its parent [`Map`](crate::Map).
layers: Vec<LayerData>,
}
impl GroupLayerData {
pub(crate) fn new(
parser: &mut impl Iterator<Item = XmlEventResult>,
infinite: bool,
map_path: &Path,
tilesets: &[MapTilesetGid],
) -> Result<(Self, Properties)> {
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
let mut properties = HashMap::new();
let mut layers = Vec::new();
parse_tag!(parser, "group", {
"layer" => |attrs| {
layers.push(LayerData::new(
parser,
attrs,
LayerTag::TileLayer,
infinite,
map_path,
&tilesets,
)?);
Ok(())
},
"imagelayer" => |attrs| {
layers.push(LayerData::new(
parser,
attrs,
LayerTag::ImageLayer,
infinite,
map_path,
&tilesets,
)?);
Ok(())
},
"objectgroup" => |attrs| {
layers.push(LayerData::new(
parser,
attrs,
LayerTag::ObjectLayer,
infinite,
map_path,
&tilesets,
)?);
Ok(())
},
"group" => |attrs| {
layers.push(LayerData::new(
parser,
attrs,
LayerTag::GroupLayer,
infinite,
map_path,
&tilesets,
)?);
Ok(())
},
"properties" => |_| {
properties = parse_properties(parser)?;
Ok(())
},
});
Ok((Self { layers }, properties))
map_wrapper!(
#[doc = "A group layer, used to organize the layers of the map in a hierarchy."]
#[doc = "\nAlso see the [TMX docs](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#group)."]
#[doc = "## Note"]
#[doc = "In Tiled, the properties of the group layer recursively affect child layers.
Implementing this behavior is left up to the user of this library."]
GroupLayer => GroupLayerData
);
/// Returns an iterator over the layers present in this group in display order.
pub fn layers(&self) -> impl ExactSizeIterator<Item = Layer> {
self.layers
.iter()
.map(move |layer| Layer::new(self.map, layer))
/// Gets a specific layer from the group by index.
pub fn get_layer(&self, index: usize) -> Option<Layer> {
self.data
.layers
.get(index)
.map(|data| Layer::new(self.map, data))