Răsfoiți Sursa

Fix map saving

Michał Zaremba 4 luni în urmă
părinte
comite
9e474422fd
2 a modificat fișierele cu 8 adăugiri și 3 ștergeri
  1. 1 2
      lib/callback/EditorCallback.h
  2. 7 1
      lib/mapObjects/CGHeroInstance.cpp

+ 1 - 2
lib/callback/EditorCallback.h

@@ -15,13 +15,12 @@ VCMI_LIB_NAMESPACE_BEGIN
 
 class DLL_LINKAGE EditorCallback : public MapInfoCallback
 {
-protected:
-	const CMap * getMapConstPtr() const override;
 
 public:
 	explicit EditorCallback(const CMap * map);
 
 	void setMap(const CMap * map);
+	const CMap * getMapConstPtr() const override;
 
 	// Access to full game state — not available in editor
 	CGameState & gameState() override;

+ 7 - 1
lib/mapObjects/CGHeroInstance.cpp

@@ -18,6 +18,7 @@
 #include "../callback/IGameInfoCallback.h"
 #include "../callback/IGameEventCallback.h"
 #include "../callback/IGameRandomizer.h"
+#include "../callback/EditorCallback.h"
 #include "../texts/CGeneralTextHandler.h"
 #include "../TerrainHandler.h"
 #include "../RoadHandler.h"
@@ -1715,7 +1716,12 @@ void CGHeroInstance::serializeCommonOptions(JsonSerializeFormat & handler)
 	handler.serializeIdArray("spellBook", spells);
 
 	if(handler.saving)
-		CArtifactSet::serializeJsonArtifacts(handler, "artifacts", &cb->gameState().getMap());
+	{
+		if(auto * ecb = dynamic_cast<EditorCallback *>(cb))
+			CArtifactSet::serializeJsonArtifacts(handler, "artifacts", const_cast<CMap *>(ecb->getMapConstPtr()));
+		else
+			CArtifactSet::serializeJsonArtifacts(handler, "artifacts", &cb->gameState().getMap());
+	}
 }
 
 void CGHeroInstance::serializeJsonOptions(JsonSerializeFormat & handler)