Przeglądaj źródła

fix deserializion of ResourceSet for compatibility

Laserlicht 2 miesięcy temu
rodzic
commit
967283beb6
2 zmienionych plików z 21 dodań i 2 usunięć
  1. 19 1
      lib/ResourceSet.h
  2. 2 1
      lib/serializer/ESerializationVersion.h

+ 19 - 1
lib/ResourceSet.h

@@ -214,7 +214,25 @@ public:
 
 	template <typename Handler> void serialize(Handler &h)
 	{
-		h & container;
+		if (h.version >= Handler::Version::CONFIGURABLE_RESOURCES)
+			h & container;
+		else
+		{
+			if (h.saving)
+			{
+				std::array<TResource, 8> tmp = {};
+				for (size_t i = 0; i < 7; ++i)
+        			tmp[i] = container[i];
+				tmp[7] = TResource{};
+				h & tmp;
+			}
+			else
+			{
+				std::array<TResource, 8> tmp = {};
+				h & tmp;
+				container = std::vector<TResource>(tmp.begin(), tmp.begin() + 7);
+			}
+		}
 	}
 
 	DLL_LINKAGE void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName);

+ 2 - 1
lib/serializer/ESerializationVersion.h

@@ -49,8 +49,9 @@ enum class ESerializationVersion : int32_t
 	CAMPAIGN_BONUSES, // new format for scenario bonuses in campaigns
 	BONUS_HIDDEN, // hidden bonus
 	MORE_MAP_LAYERS, // more map layers
+	CONFIGURABLE_RESOURCES, // configurable resources
 
-	CURRENT = MORE_MAP_LAYERS,
+	CURRENT = CONFIGURABLE_RESOURCES,
 };
 
 static_assert(ESerializationVersion::MINIMAL <= ESerializationVersion::CURRENT, "Invalid serialization version definition!");