ben-ryder / Conqueror-of-Empires

A turn-based strategy game where up to 4 local players battle to be victorious, by expanding their empires, and controlling units to conquer cities and attack the enemy.
GNU General Public License v3.0
41 stars 9 forks source link

Change data storage format to JSON #5

Closed ben-ryder closed 4 years ago

ben-ryder commented 4 years ago

Describe your feature Currently, the game data is saved and stored using pickle. This saves a copy of the game's 'Model' object, which can be reloaded back in to resume a game. I suggest changing this to use a common standard format, such as JSON. This will mean that code base changes will be much less likely to cause old games to crash, and might make future testing easier as you can simply inspect the save file, or edit it if you want certain game conditions.

Is your suggestion related to any problems? The current use of pickle may slow future development and cause old games to crash after code base changes.

Additional context n/a

ben-ryder commented 4 years ago

To add some extra information: When creating a game, the make() method is used in project/game/new.py, which instantiates the Model (which in turn creates the world, players etc) and then pickles this new object to a file. When loading the game, the game controller loads the object from the file and uses that. This means all __init__methods on the object are only used once when originally creating the game.

To convert the game to save in a JSON format, this needs to cange so that evey object can either initialse new, or with existing data. They must also be able to give out all their data so this can be saved into the file. The details would have to be decided.

ben-ryder commented 4 years ago

This has now been merged into dev. It will be combined with the work for GH-2 before being pushed to master.