From 57097f4ae6d1a8864240fca292a33978caeb7723 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 27 Nov 2024 20:50:12 +0000 Subject: [PATCH] Fix serialization of selected spellbook page On game start, player interface attempts to load local state from empty json, resetting all values to 0. However we want to show spellbook at "all spells" page as default, not as top-most page with air spells --- client/PlayerLocalState.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client/PlayerLocalState.cpp b/client/PlayerLocalState.cpp index 66d3d69ff..29e664498 100644 --- a/client/PlayerLocalState.cpp +++ b/client/PlayerLocalState.cpp @@ -396,16 +396,19 @@ void PlayerLocalState::deserialize(const JsonNode & source) } } - spellbookSettings.spellbookLastPageBattle = source["spellbook"]["pageBattle"].Integer(); - spellbookSettings.spellbookLastPageAdvmap = source["spellbook"]["pageAdvmap"].Integer(); - spellbookSettings.spellbookLastTabBattle = source["spellbook"]["tabBattle"].Integer(); - spellbookSettings.spellbookLastTabAdvmap = source["spellbook"]["tabAdvmap"].Integer(); + if (!source["spellbook"].isNull()) + { + spellbookSettings.spellbookLastPageBattle = source["spellbook"]["pageBattle"].Integer(); + spellbookSettings.spellbookLastPageAdvmap = source["spellbook"]["pageAdvmap"].Integer(); + spellbookSettings.spellbookLastTabBattle = source["spellbook"]["tabBattle"].Integer(); + spellbookSettings.spellbookLastTabAdvmap = source["spellbook"]["tabAdvmap"].Integer(); + } // append any owned heroes / towns that were not present in loaded state wanderingHeroes.insert(wanderingHeroes.end(), oldHeroes.begin(), oldHeroes.end()); ownedTowns.insert(ownedTowns.end(), oldTowns.begin(), oldTowns.end()); -//FIXME: broken, anything that is selected in here will be overwritten on NewTurn pack +//FIXME: broken, anything that is selected in here will be overwritten on PlayerStartsTurn pack // ObjectInstanceID selectedObjectID(source["currentSelection"].Integer()); // const CGObjectInstance * objectPtr = owner.cb->getObjInstance(selectedObjectID); // const CArmedInstance * armyPtr = dynamic_cast(objectPtr);