Cleaned up classes. Now we have a base AbstractData class which has 2 children:
PrimitiveData which is for value types like integer, float etc.
ArrayData. This further has 2 children:
TableData
SerializationData which is used in emulators to hold the ser/de data in the form of instances of these above classes.
Removed most classes including RawDataArrayData and DataArrayData. Their functionality is now handled directly via SerializationData which is also now embedded into SerDeEmulator as a data container.
Removed StrictSerDe emulators and instead add type-checking directly to the regular ones.
Deprecated Utils.serialize, Utils.deserialize and Utils.deserializeInto functions and added a new ::MSU.Serialization namespace which now contains improved alternatives for these functions.
Moved the serialization data types enum to the new ::MSU.Serialization namespace.
Added DeserializeMetaData key to SerializationSystem which is set during onBeforeDeserialize of world_state. We then use this metadata during flagDeserialize of the serialization system so that isSavedVersionAtLeast etc. report the correct version with this metadata. I'd consider this a bugfix in MSU unless there is something wrong with this approach.
Changed inheritance structure of flag ser/de emulators from the base SerDeEmulator class. This also renames the previously known SerializationEmulator and DeserializationEmulator into the more appropriate FlagSerializationEmulator and FlagDeserializationEmulator. This also involves moving the read/write funtions directly into the parent class and allowing the child classes to instead modify the relevant __readData and __writeData functions and add other funtionality as desired. This was important because I wanted a SerializationEmulator and DeserializationEmulator class which can be instantiated from the SerializationData without having to pass in a Mod Id and Flag Container. So instead one can simply do ::MSU.Class.SerializationEmulator(::MSU.Class.MetaDataEmulator(), this) inside the SerializationData.
The last one above is probably the most controversial change in this PR. I'd like to discuss it and am open to feedback / suggestions for alternative approaches.
Note that because of this change to the emulators, after updating to MSU 1.4.0 when people load their older saved game for the first time, the log will be spammed with warnings of mismatch between read data and the data type stored in the emulator when deserializaing mod settings. However, the values loaded will still be correct. This won't happen for saves made with MSU 1.3.0.
Fully tested and working with the following example code:
local mod = ::MSU.Mod;
local myData = {
string = "someString",
int = 124,
float = "1.1241241",
player = ::MSU.Class.SerializationData()
table = {
nestedInt = 1
}
}
::getBro("Ruthard").onSerialize(myData.player.getSerializationEmulator());
mod.PersistentData.createFile("testPersistence", myData);
local readData = mod.PersistentData.readFile("testPersistence");
local readPlayer = ::World.getTemporaryRoster().create("scripts/entity/tactical/player");
readPlayer.onDeserialize(readData.player.getDeserializationEmulator());
::logInfo(readPlayer.getName());
After some discussion in Discord we still have to do the following:
[X] rework MetaDataEmulator to be constructed with a table/instance of dummy/real metadata and serialize all relevant information from itself and that real metadata @Enduriel
[ ] rework the SerializationData to serialize the new MetaDataEmulator so that persistently serialized bb classes will automatigically have the right metadata attached to them @LordMidas
[x] throwing vs erroring during deserialization type mismatch -> error and print row & file like in printData @LordMidas
Cleaned up classes. Now we have a base
AbstractData
class which has 2 children:PrimitiveData
which is for value types like integer, float etc.ArrayData
. This further has 2 children:TableData
SerializationData
which is used in emulators to hold the ser/de data in the form of instances of these above classes.Removed most classes including
RawDataArrayData
andDataArrayData
. Their functionality is now handled directly viaSerializationData
which is also now embedded intoSerDeEmulator
as a data container.Removed
StrictSerDe
emulators and instead add type-checking directly to the regular ones.Deprecated
Utils.serialize
,Utils.deserialize
andUtils.deserializeInto
functions and added a new::MSU.Serialization
namespace which now contains improved alternatives for these functions.Moved the serialization data types enum to the new
::MSU.Serialization
namespace.Added
DeserializeMetaData
key toSerializationSystem
which is set duringonBeforeDeserialize
ofworld_state
. We then use this metadata duringflagDeserialize
of the serialization system so thatisSavedVersionAtLeast
etc. report the correct version with this metadata. I'd consider this a bugfix in MSU unless there is something wrong with this approach.Changed inheritance structure of flag ser/de emulators from the base
SerDeEmulator
class. This also renames the previously knownSerializationEmulator
andDeserializationEmulator
into the more appropriateFlagSerializationEmulator
andFlagDeserializationEmulator
. This also involves moving theread/write
funtions directly into the parent class and allowing the child classes to instead modify the relevant__readData
and__writeData
functions and add other funtionality as desired. This was important because I wanted aSerializationEmulator
andDeserializationEmulator
class which can be instantiated from theSerializationData
without having to pass in a Mod Id and Flag Container. So instead one can simply do::MSU.Class.SerializationEmulator(::MSU.Class.MetaDataEmulator(), this)
inside theSerializationData
.The last one above is probably the most controversial change in this PR. I'd like to discuss it and am open to feedback / suggestions for alternative approaches.
Note that because of this change to the emulators, after updating to MSU 1.4.0 when people load their older saved game for the first time, the log will be spammed with warnings of mismatch between read data and the data type stored in the emulator when deserializaing mod settings. However, the values loaded will still be correct. This won't happen for saves made with MSU 1.3.0.
Fully tested and working with the following example code: