11use std:: { collections:: HashMap , path:: Path } ;
22
3+ use xml:: attribute:: OwnedAttribute ;
4+
35use crate :: {
46 parse_properties,
5- util:: { map_wrapper, parse_tag, XmlEventResult } ,
7+ util:: { get_attrs , map_wrapper, parse_tag, XmlEventResult } ,
68 Error , Image , Properties , Result ,
79} ;
810
@@ -11,18 +13,32 @@ use crate::{
1113pub struct ImageLayerData {
1214 /// The single image this layer contains, if it exists.
1315 pub image : Option < Image > ,
16+ /// The layer's x repeat factor (true = repeat, false = no repeat).
17+ pub repeat_x : bool ,
18+ /// The layer's y repeat factor (true = repeat, false = no repeat).
19+ pub repeat_y : bool ,
1420}
1521
1622impl ImageLayerData {
1723 pub ( crate ) fn new (
1824 parser : & mut impl Iterator < Item = XmlEventResult > ,
25+ attrs : Vec < OwnedAttribute > ,
1926 map_path : & Path ,
2027 ) -> Result < ( Self , Properties ) > {
2128 let mut image: Option < Image > = None ;
2229 let mut properties = HashMap :: new ( ) ;
2330
2431 let path_relative_to = map_path. parent ( ) . ok_or ( Error :: PathIsNotFile ) ?;
2532
33+ // Parse repeat attributes from the imagelayer tag
34+ let ( repeat_x, repeat_y) = get_attrs ! (
35+ for v in attrs {
36+ Some ( "repeatx" ) => repeat_x ?= v. parse:: <i32 >( ) . map( |val| val == 1 ) ,
37+ Some ( "repeaty" ) => repeat_y ?= v. parse:: <i32 >( ) . map( |val| val == 1 ) ,
38+ }
39+ ( repeat_x, repeat_y)
40+ ) ;
41+
2642 parse_tag ! ( parser, "imagelayer" , {
2743 "image" => |attrs| {
2844 image = Some ( Image :: new( parser, attrs, path_relative_to) ?) ;
@@ -33,7 +49,14 @@ impl ImageLayerData {
3349 Ok ( ( ) )
3450 } ,
3551 } ) ;
36- Ok ( ( ImageLayerData { image } , properties) )
52+ Ok ( (
53+ ImageLayerData {
54+ image,
55+ repeat_x : repeat_x. unwrap_or ( false ) ,
56+ repeat_y : repeat_y. unwrap_or ( false ) ,
57+ } ,
58+ properties,
59+ ) )
3760 }
3861}
3962
0 commit comments