kendallroth / cs2-city-stats

Mod to view city statistics
https://mods.paradoxplaza.com/mods/85284/Windows
1 stars 2 forks source link

Persist panel visibility/position within save #7

Open kendallroth opened 3 months ago

kendallroth commented 3 months ago

Inspired by #2, the panel visibility and position should be persisted within a save game. This will require storing the values in a serializable entity (or component?) in ECS, that could then be automatically persisted to the game save. However, this depends on whether there is actually value to this, as compared to other options...

System docs

krzychu124: for panel position, I suggest storing it on C# side, value binding to read, calling a trigger from UI with new value when position has changed. Serialize in UI system entity component, when deserializing, validate with current screen resolution, reset if out of bounds. reset will be trivial since it will just overwrite value of the binding that UI is reading panel visibility can be done similar way

PoliteCanadian: To modify data in a save game, would I simply persist it within a registered entity component ("simply" is probably an oversimplification, but it does make sense that the game entities would be persisted somewhere in each save game 🤦‍♂️ )

krzychu124: when a component or system implements ISerializable interface (sometimes needs a few more) it will be automatically picked up by serialization system and processed as any other savegame data here example from Traffic mod, the system, besides running a job you can ignore, is saving and restoring a version number when the game is serializing or deserializing the savegame data. It's fairly straightforward. https://github.com/krzychu124/Traffic/blob/main/Code/Systems/DataMigration/TrafficDataMigrationSystem.cs so you just need IDefaultSerializable, ISerializable three methods from the bottom of the file and a field or fields to store the data which should be serialize

kendallroth commented 3 months ago

Persisting panel visibility/position within individual save files is likely unnecessary, as players probably wouldn't have different visibility/position per save. Per-save data may be more useful for configuring which stats are available, but even that could be done as global settings or a ModsData file (both might make more sense) 🤷.

skst commented 1 month ago

FWIW, I'd actually prefer the position and stat selection to persist globally, so I do not have to set (or update) them for every city.

kendallroth commented 1 month ago

Yeah, I'm honestly not sure which approach to take...which is why I've kinda put this on the back-burner for the time being... I do agree there is probably more value in persisting the setting globally than per-save, as I doubt that would really ever occur.

skst commented 1 month ago

Well, not that you're asking me 🙂, but (again, FWIW), perhaps implement the global method first. That sounds like the easiest. Then, if you feel like it or people beg for a per-city setting, you can add the ability to override the global setting for a given city.

(I assure you, it's purely a coincidence that I prefer the global method.)

kendallroth commented 1 month ago

Yeah, I could definitely see storing the panel position globally (via settings or ModsData/), and this would probably be what I try before per-save (at this point).

I'm not entirely certain about storing the panel visibility globally, as there is already the setting to open upon load or not, which seems sufficient... I think the next related change I would make would be to remove that setting in favour of storing the panel visibility per-save 🤷.

However, I'm probably not planning to store the stat selection globally (missed this in first request), as that is persisted within each save, and may change over the lifetime of the save as city services become available or concerns change, etc 🤷.