joshuaauerbachwatson / anyCards

Multi-person card game with no built-in rules
Apache License 2.0
0 stars 0 forks source link

[bug] The save/restore of game setups isn't working properly #29

Closed joshuaauerbachwatson closed 1 year ago

joshuaauerbachwatson commented 1 year ago

After (vacuously) saving an initial game state, every attempt in restoring that game state results in a blank playing area with no dealing deck. There is nothing obvious on the console. In starting to investigate it seems that the code to do the game restore is regressed from what I'm pretty sure I remember writing: in particular, the cards of the game are not being reordered randomly as was the design, so every restore of the same game state will be identical.

joshuaauerbachwatson commented 1 year ago

The symptom was due to a change in how sizes are assigned to cards. We need to use the ViewController.cardSize constant in all relevant places. But, I was correct that the cards were not being properly randomized in a restored setup. That is now fixed. In working on this I also noticed that recently-added properties of a card (e.g. mayTurnOver) as well as recently added properties of boxes (owner, kind) were not being propagated between devices (meaning they were being lost on setup restore as well, since both use the GameState as the serialized representation). That is also fixed now. In the process, I refactored CardState into a three-class hierarchy (ItemState is the parent of both CardState and GridBoxState) since the properties of cards and boxes are mostly distinct.