I had a look at the “layers bug”: vassalengine.org/tracker/sho … i?id=12850
Made a simple module for testing layers, it’s attached to the bug. It’s setup as follows:
- two layers, L1 and L2 - three at-start stacks -- stack "Stack L1" contains 2 pieces that both belong to layer L1 --- piece SL1p1 --- piece SL1p2 -- stack "Stack L2" contains 2 pieces that both belong to layer L2 --- piece SL2p1 --- piece SL2p2 -- stack "Stack Mixed" contains 2 pieces, one belonging to layer L1 and the other to layer L2 --- piece P1 (belongs to L1) --- piece P2 (belongs to L2)
The Vassal reference manual, page “GamePieceLayers.htm” shows what seems to be one of the most important rules concerning layers: “Pieces assigned to different layers will never combine into a stack.”
The editor allows the creation of at-start stacks with several pieces which belong to different layers. This is a contradiction to the rule that I cited above, but ok, all power to the module designer, I guess.
The module file knows nothing about the stacks belonging to certain layers, it only knows that there are <VASSAL.build.module.map.SetupStack> elements for each at-start stack, and inside them is one <VASSAL.build.widget.PieceSlot> element for each gamepiece. The layer information is saved with the pieces. So far so good.
Opening the module in the player, we get the first “real” bug: vassal opened the module, evaluated the stacks, the pieces inside, it should have realized that this one stack with pieces from two different layers is illegal, and should have created 2 different stacks, one for each layer. It should not look nice, the stacks should sit in the same position on top of each other, but the rule “different layers will never combine into a stack” should be followed, and besides, what was the module designer thinking when he put pieces of several layers into the same stack, it’s his fault that one of the stacks is hidden behind another now.
But instead of this we see just one stack with two pieces/counters, breaking the “different layers will never combine into a stack” rule. What follows, is either due to this initial screwup, or separate bugs, I cannot tell it apart at this point:
- two buttons to switch off layers L1 / L2, one of them does nothing for the mixed stack, the other switches off the whole stack
- mouse-over above the mixed stack does not show the popup with the stack’s contents
- bug description contains more e.g. moving the mixed stack leads to weird results
Another problem described in the bug report is that the layer to which a piece belongs can change over time, this can lead to a piece getting stranded in a stack where it doesn’t belong.
My first idea for a solution is to make sure the rule “different layers will never combine into a stack” is always followed. When a module is opened and the game board is built, the engine should evaluate the layer properties and create several stacks in the same position if needed. Then we can test and see if the problems with “mixed layer stacks” still appear.
The dynamic change of a piece’s layer would also be solved in the same way, the engine should evaluate these layer changes and create new stacks or merge stacks if needed, to ensure that there are never mixed layer stacks in the game.
I did not check where all of this happens in the code yet, just put some breakpoints around LayeredPieceCollection and CompoundPieceCollection and saw them fire when I opened the module and pass the stacks/pieces that I built in the editor, it looked like a good place to start enforcing the rule about no mixed stacks.
I think the first thing that we should agree on is the general direction of the bug fix, does the solution that I proposed make sense from a game modeling point of view? Is it ok to strictly enforce the game rules, and solve possible bugs and weird situations by doing that, even if it means having an editor that allows illegal setups, and graphical weirdness where stacks sit on top of and hide each other?