I told you I could do it! It wasn’t easy — I had to rewrite four other classes to make this work. My code is a lottttt cleaner than before. Some highlights of tasks I undertook to get this working:
- Reworking the State machine that drives Tile functionality
- Reconfiguring the base tile dictionary to feature key value pairs of <int, BoardTile>, instead of <int, PersistableObject>, then extending my BoardTile class from PersistableTile, which is where the save functionality is stored. (This may move to BoardTile later, it’s kind of a weird setup and it feels needlessly complicated at the moment.
- Redesigning the workflow of instantiating tiles. Gone are ButtonTileHandler’s heavy responsibilities. Now I have a BoardTileFactory for that.
- Rewriting the Save functionality to do a foreach(KeyValuePair<int, BoardTile> tile in mapTiles) loop rather than a for loop — the latter was causing inconsistencies when tiles were deleted, where gaps in numbers existed in Tile ID / mapTiles.Keys.
- Writing a function that nicely reorders the dictionary when you reload it, in the event of Tile ID gaps. This can be enabled or disabled by the user.
It’s been a busy few hours! The next task on my list is adding ‘are you sure’-type UI prompts, as well as a Save As dialogue for saving and an Open dialogue for loading maps. Once these are done….the UI will need redesigning.
The work continues-