@@ -140,6 +140,76 @@ do -- NewLayer/RemoveLayer
140140 assert (# s .layers == 1 )
141141end
142142
143+ -- NewLayer Ordering
144+ do
145+ local function testNewLayerOrdering (testGroup , testTilemap )
146+ local s = Sprite (32 , 32 )
147+ assert (# s .layers == 1 )
148+ local base = app .layer
149+
150+ app .command .NewLayer { name = " First" , group = testGroup , tilemap = testTilemap }
151+ local first = app .layer
152+ app .command .NewLayer { name = " Second" , group = testGroup , tilemap = testTilemap }
153+ local second = app .layer
154+ app .command .NewLayer { name = " Third" , group = testGroup , tilemap = testTilemap }
155+ local third = app .layer
156+
157+ s :deleteLayer (base )
158+
159+ expect_eq (first .name , " First" )
160+ expect_eq (second .name , " Second" )
161+ expect_eq (third .name , " Third" )
162+
163+ expect_eq (first .stackIndex , 1 )
164+ expect_eq (second .stackIndex , 2 )
165+ expect_eq (third .stackIndex , 3 )
166+
167+ app .layer = second
168+ app .command .NewLayer { before = true , name = " Before Second" , group = testGroup , tilemap = testTilemap }
169+ local beforeSecond = app .layer
170+
171+ app .layer = second
172+ app .command .NewLayer { before = false , name = " After Second" , group = testGroup , tilemap = testTilemap }
173+ local afterSecond = app .layer
174+
175+ expect_eq (first .name , " First" )
176+ expect_eq (second .name , " Second" )
177+ expect_eq (third .name , " Third" )
178+ expect_eq (beforeSecond .name , " Before Second" )
179+ expect_eq (afterSecond .name , " After Second" )
180+
181+ expect_eq (first .stackIndex , 1 )
182+ expect_eq (beforeSecond .stackIndex , 2 )
183+ expect_eq (second .stackIndex , 3 )
184+ expect_eq (afterSecond .stackIndex , 4 )
185+ expect_eq (third .stackIndex , 5 )
186+
187+ app .layer = second
188+ app .command .NewLayer { top = true , name = " Top" , group = testGroup , tilemap = testTilemap }
189+ local top = app .layer
190+
191+ expect_eq (top .stackIndex , 6 )
192+
193+ app .layer = first
194+ app .command .NewLayer { before = true , name = " Bottom" , group = testGroup , tilemap = testTilemap }
195+ local bottom = app .layer
196+
197+ expect_eq (bottom .stackIndex , 1 )
198+ expect_eq (first .stackIndex , 2 )
199+ expect_eq (beforeSecond .stackIndex , 3 )
200+ expect_eq (second .stackIndex , 4 )
201+ expect_eq (afterSecond .stackIndex , 5 )
202+ expect_eq (third .stackIndex , 6 )
203+ expect_eq (top .stackIndex , 7 )
204+
205+ s :close ()
206+ end
207+
208+ testNewLayerOrdering (false , false ) -- Regular layers
209+ testNewLayerOrdering (true , false ) -- Groups
210+ testNewLayerOrdering (false , true ) -- Tilemaps
211+ end
212+
143213do -- Background/Transparent layers
144214 local s = Sprite (32 , 32 )
145215 assert (s .layers [1 ].isTransparent )
0 commit comments