Changed save data in Questing Foe to allow for custom foe ids #2535
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
int
value in aMobileTypes
enum, 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_v1
struct, we havefoeType
as aMobileTypes
enum. 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
int
with 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
MobileTypes
is serialized, inItemData_v1
, with the fieldtrappedSoulType
. I have not provided a fix for this one, because:ItemData_v1
explicitly. Moving toItemData_v2
would require updating all save structures using items to v2 (big change) and the interfaces (breaks mods)