shpaass / yafc-ce

Powerful Factorio calculator/analyser that works with mods
GNU General Public License v3.0
51 stars 18 forks source link

[Todo] Preferences: Refactor Instance-deserialization to be flexible with attribute names #253

Open shpaass opened 2 weeks ago

shpaass commented 2 weeks ago

Right now, the deserialization of Yafc.Preferences#Instance breaks if you change the name of attributes in ProjectDefinition. It wipes the renamed attribute because the deserialized objects do not have the new attribute.

For instance, if you were to rename path into projectPath, the deserialization from AppData/YAFC/yafc.config can't match them, so the whole list would have projectPath as empty. That ultimately results in the list of recent projects being wiped.

There are ways to sove this problem, but they need time and googling.

(This ticket was created to better track the corresponding TODO in the code)

DaleStan commented 1 week ago

Most json serializers have [JsonProperty(...)] (Newtonsoft.Json) or [JsonPropertyName(...)] (System.Text.Json.Serialization) attributes to control what gets written in the json, along with more general tools for saying "Write camelCase to the json even though the source is in PascalCase.

We can just directly copy their behavior, or we could do an class OldPropertyNamesAttribute(params string[] oldPropertyNames) to always write the newest name but support reading from older names.

The latter means that you immediately know how projectPath is stored in the json, but doesn't let older versions read json written by newer versions.