Changed save data in Questing Foe to allow for custom foe ids#2535
Merged
KABoissonneault merged 1 commit intoInterkarma:masterfrom Feb 11, 2024
Merged
Conversation
…evious enum-based approach would fail on enum values outside of the predetermined enum fields, due to string-based serialization
KABoissonneault
commented
Aug 23, 2023
| SaveData_v1 data = (SaveData_v1)dataIn; | ||
| SaveData_v2 data; | ||
|
|
||
| if (dataIn is SaveData_v1) |
Collaborator
Author
There was a problem hiding this comment.
I had expected the [fsObject("v2", typeof(SaveData_v1))] attribute on the struct to cause fsSerializer to migrate the struct automatically. This is not the case. I suspect the migration only happens if Foe.SaveData_v2 was the top-level struct being deserialized. In the normal case of loading a save with a pending quest, the save data is nested as a generic object in ResourceSaveData_v1.resourceSpecific.
So, I do the migration manually here
numidium
approved these changes
Feb 11, 2024
ajrb
approved these changes
Feb 11, 2024
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After looking into this issue: https://forums.dfworkshop.net/viewtopic.php?t=6357
Normally, we can store any
intvalue in aMobileTypesenum, which occurs when using custom enemies with ids not defined in theenum. This works as long as we don't rely on features that require a field to be defined, such as serialization to and from string.I found that in fsSerializer, enum values are serialized as strings, based on the matching enum field name.
In the
Foe.SaveData_v1struct, we havefoeTypeas aMobileTypesenum. This shows in the save like thisIf a field is not defined for this value (ex: custom enemy ids), this gets saved as
"foeType": null, which will default to 0 when loaded back in (hence the rat mentioned in the linked thread).To work around this issue, I've used an
intwith the id value. I have considered using a string to retain legibility, but I was not sure if it would still work once people start localizing custom enemies (we only have the Career name to identify custom enemies, and that string is user facing).With the new save data
I have found one other place where a
MobileTypesis serialized, inItemData_v1, with the fieldtrappedSoulType. I have not provided a fix for this one, because:ItemData_v1explicitly. Moving toItemData_v2would require updating all save structures using items to v2 (big change) and the interfaces (breaks mods)