Repository navigation
Description
What happens
Line numbers are on main at f0598c8.
A group can hold its own layers with a subgroup between them, like an outline:
P
├─ A
├─ Q
│ └─ B
└─ C
The drawing order is A, B, C. Copy Group on P and Paste put the copy in as A, C, B: B, the subgroup's layer, drops below C. A layer drawn above C now draws under it, and the subgroup moves to the end of its parent.
Paste adds the copied groups one at a time, outermost first (crates/engine/src/cmd/layer_copy.rs:192–208, sorted at line 194, each m.add_group(g) at line 206). Map::add_group (crates/map/src/lib.rs:2579) gathers the new group's layers right away: gather_chain (line 3098) calls gather_group (line 3106), which moves the group's members together "at the topmost, keeping their order". When P is added, Q doesn't exist yet. P's members are only A and C, so they are gathered together and B is left below them: A, C, B. Adding Q afterwards gathers B alone, and gathering P again keeps A, C, B, which is already contiguous.
Opening a project doesn't do this: Map::tidy_groups (line 3129) gathers once every group exists, so group_layers(P) already includes B.
The same placing is used by the layer files that hold a group in #3344 (#2870), so a group saved and added back would come in reordered the same way.
Steps to reproduce
- On an empty map, add three layers in the drawing order A, B, C.
group.addwith{"name": "P", "layers": ["A", "B", "C"]}, thengroup.addwith{"name": "Q", "parent": "P", "layers": ["B"]}. The map shows P holding A, Q (with B) and C, in the order A, B, C.layer.copywith{"group": "P"}, thenmap.newandlayer.paste.
The pasted map's layers are A, C, B. Checked on this arrangement with a throwaway engine test: the order before copying was A,B,C, and after pasting it was A,C,B.
Expected
The pasted layers keep their copied drawing order, A, B, C, for any nesting of groups. The groups are the same as copied.
Proposed fix
In place (paste on main), once every copied group has been added, put the pasted layers back in the order they were copied. They form one run of the drawing order: they went in together above before (line 172), and gathering only moves them among themselves. The copied order came from a map, so it already keeps each group's layers together, and putting it back can't split a group.
For example, a Map method beside gather_group:
/// Puts the layers `ids` back in this order, in the places they now take in the drawing
/// order, the other layers staying where they are.
pub fn restore_order(&mut self, ids: &[u32])paste would call it as m.restore_order(&pasted) after the group loop. The method should treat tile layers drawn among them as place_layer and gather_group do, with release_tiles and settle_tiles.
A test on layer.paste with the arrangement above, asserting A, B, C, and a deeper one (a subgroup inside the subgroup, between two layers of each level). After #3344 the same test covers group files, through layer.addLayerFile.
Activity