Open boformer opened 8 years ago
Sorry, I've been away from CSL for a while. Thanks for the code! I'm a little concerned about merging the data with the main save file. Won't that cause problems if the mod is ever deactivated later on?
No. The data will just be dropped when you save the city without the mod (just like it is now).
Interesting, thanks for the info. I'll try it out and, if all is well, I'll implement it.
In your loading code, you call new MemoryStream(propDataBytes)
twice instead of using the memoryStream
variable from the using
statement. Is that normal? I noticed you have the same code in BuildingThemes.
I implemented the new save system and everything works normally. I then deactivated the mod to make sure a game saved with TM data would still load correctly with the mod disabled. This worked as expected. I then saved the game at this point and tried loading it again but, this time, with the mod enabled. I expected the city to load without any TM data, but to my surprise, the data that had been saved before I deactivated the mod was still there. This could cause errors if changes to the road infrastructure were made between the times I deactivated and reactivated the mod. This issue would, of course, also be present with the current (XML file) save system, but any errors it would cause could be easily cleared by deleting the XML file. With the data saved in the main file, this fix would not be possible. Applying old TM data to a changed road infrastructure could actually be harmless. I will run some tests to verify this and report back. In the meantime, I thought you would want to know that the data isn't in fact dropped from the saved game file when you deactivate the mod, as you indicated above.
I think it would be better to store the mod save data in the crp file instead of spamming xml files in the Cities_Data folder.
The Mod API supports that. I just updated Building Themes to store the save data in the crp.
Basically you just have to supply the
XMLSerializer
with aMemoryStream
instead of aStreamWriter
.Then you can get the byte[] representation of the stream and save it using the mod API:
Loading:
The old data loading should be kept for a smooth transition to the new serialization system.