mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
fix serialisation
This commit is contained in:
@@ -76,9 +76,20 @@ BattleOnlyModeTab::BattleOnlyModeTab()
|
|||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
|
|
||||||
//JsonNode node = persistentStorage["lobby"]["battleModeSettings"];
|
try
|
||||||
//JsonDeserializer handler(nullptr, node);
|
{
|
||||||
//startInfo->serializeJson(handler);
|
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();
|
init();
|
||||||
|
|
||||||
@@ -213,7 +224,7 @@ void BattleOnlyModeTab::update()
|
|||||||
JsonNode node;
|
JsonNode node;
|
||||||
JsonSerializer handler(nullptr, node);
|
JsonSerializer handler(nullptr, node);
|
||||||
startInfo->serializeJson(handler);
|
startInfo->serializeJson(handler);
|
||||||
Settings storage = persistentStorage.write["lobby"]["battleModeSettings"];
|
Settings storage = persistentStorage.write["battleModeSettings"];
|
||||||
storage->Struct() = node.Struct();
|
storage->Struct() = node.Struct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -259,6 +259,9 @@ void BattleOnlyModeStartInfo::serializeJson(JsonSerializeFormat & handler)
|
|||||||
{
|
{
|
||||||
handler.serializeId("selectedTerrain", selectedTerrain);
|
handler.serializeId("selectedTerrain", selectedTerrain);
|
||||||
handler.serializeId("selectedTown", selectedTown);
|
handler.serializeId("selectedTown", selectedTown);
|
||||||
|
if(!handler.saving && selectedTown == FactionID::NONE)
|
||||||
|
selectedTown = FactionID::ANY;
|
||||||
|
|
||||||
auto slots = handler.enterArray("slots");
|
auto slots = handler.enterArray("slots");
|
||||||
slots.resize(2);
|
slots.resize(2);
|
||||||
for(int i = 0; i < 2; i++)
|
for(int i = 0; i < 2; i++)
|
||||||
@@ -305,10 +308,13 @@ void BattleOnlyModeStartInfo::serializeJson(JsonSerializeFormat & handler)
|
|||||||
s->serializeIdMap("artifacts", tmp);
|
s->serializeIdMap("artifacts", tmp);
|
||||||
std::map<ArtifactID, ArtifactPosition> converted;
|
std::map<ArtifactID, ArtifactPosition> converted;
|
||||||
for (auto &[id, pos] : tmp)
|
for (auto &[id, pos] : tmp)
|
||||||
|
if(id != ArtifactID::NONE)
|
||||||
converted[id] = ArtifactPosition(pos);
|
converted[id] = ArtifactPosition(pos);
|
||||||
artifacts[i] = vstd::reverseMap(converted);
|
artifacts[i] = vstd::reverseMap(converted);
|
||||||
}
|
}
|
||||||
s->serializeIdArray("spells", spells[i]);
|
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("warMachines", warMachines[i]);
|
||||||
s->serializeBool("spellBook", spellBook[i]);
|
s->serializeBool("spellBook", spellBook[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user