mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
fix serialisation
This commit is contained in:
@@ -76,9 +76,20 @@ BattleOnlyModeTab::BattleOnlyModeTab()
|
||||
{
|
||||
OBJECT_CONSTRUCTION;
|
||||
|
||||
//JsonNode node = persistentStorage["lobby"]["battleModeSettings"];
|
||||
//JsonDeserializer handler(nullptr, node);
|
||||
//startInfo->serializeJson(handler);
|
||||
try
|
||||
{
|
||||
JsonNode node = persistentStorage["battleModeSettings"];
|
||||
if(!node.isNull())
|
||||
{
|
||||
node.setModScope(ModScope::scopeGame());
|
||||
JsonDeserializer handler(nullptr, node);
|
||||
startInfo->serializeJson(handler);
|
||||
}
|
||||
}
|
||||
catch(std::exception & e)
|
||||
{
|
||||
logGlobal->error("Error loading saved battleModeSettings, received exception: %s", e.what());
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
@@ -213,7 +224,7 @@ void BattleOnlyModeTab::update()
|
||||
JsonNode node;
|
||||
JsonSerializer handler(nullptr, node);
|
||||
startInfo->serializeJson(handler);
|
||||
Settings storage = persistentStorage.write["lobby"]["battleModeSettings"];
|
||||
Settings storage = persistentStorage.write["battleModeSettings"];
|
||||
storage->Struct() = node.Struct();
|
||||
}
|
||||
|
||||
|
||||
@@ -259,6 +259,9 @@ void BattleOnlyModeStartInfo::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
handler.serializeId("selectedTerrain", selectedTerrain);
|
||||
handler.serializeId("selectedTown", selectedTown);
|
||||
if(!handler.saving && selectedTown == FactionID::NONE)
|
||||
selectedTown = FactionID::ANY;
|
||||
|
||||
auto slots = handler.enterArray("slots");
|
||||
slots.resize(2);
|
||||
for(int i = 0; i < 2; i++)
|
||||
@@ -305,10 +308,13 @@ void BattleOnlyModeStartInfo::serializeJson(JsonSerializeFormat & handler)
|
||||
s->serializeIdMap("artifacts", tmp);
|
||||
std::map<ArtifactID, ArtifactPosition> converted;
|
||||
for (auto &[id, pos] : tmp)
|
||||
if(id != ArtifactID::NONE)
|
||||
converted[id] = ArtifactPosition(pos);
|
||||
artifacts[i] = vstd::reverseMap(converted);
|
||||
}
|
||||
s->serializeIdArray("spells", spells[i]);
|
||||
if(!handler.saving)
|
||||
spells[i].erase(std::remove(spells[i].begin(), spells[i].end(), SpellID::NONE), spells[i].end());
|
||||
s->serializeBool("warMachines", warMachines[i]);
|
||||
s->serializeBool("spellBook", spellBook[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user