MSUTeam / MSU

Modding Standards and Utilities for Battle Brothers
22 stars 4 forks source link

Storage persistence midas 2 #341

Closed LordMidas closed 5 months ago

LordMidas commented 7 months ago

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());
Enduriel commented 7 months ago

You typoed %s and instead wrote $s in your commit moving MSU# into a separate table

Enduriel commented 6 months ago

After some discussion in Discord we still have to do the following: