Browse Source

Fix map object appearance serialization

AlexVinS 9 years ago
parent
commit
8e3e574900
3 changed files with 21 additions and 7 deletions
  1. 6 6
      lib/mapObjects/CObjectClassesHandler.h
  2. 3 0
      lib/mapping/MapFormatJson.cpp
  3. 12 1
      test/MapComparer.cpp

+ 6 - 6
lib/mapObjects/CObjectClassesHandler.h

@@ -101,12 +101,6 @@ class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
 	/// Human-readable name of this object, used for objects like banks and dwellings, if set
 	boost::optional<std::string> objectName;
 
-	si32 type;
-	si32 subtype;
-
-	std::string typeName;
-	std::string subTypeName;
-
 	JsonNode base; /// describes base template
 
 	std::vector<ObjectTemplate> templates;
@@ -117,6 +111,12 @@ protected:
 	/// initialization for classes that inherit this one
 	virtual void initTypeData(const JsonNode & input);
 public:
+	std::string typeName;
+	std::string subTypeName;
+
+	si32 type;
+	si32 subtype;
+
 	virtual ~AObjectTypeHandler(){}
 
 	void setType(si32 type, si32 subtype);

+ 3 - 0
lib/mapping/MapFormatJson.cpp

@@ -779,8 +779,11 @@ void CMapLoaderJson::MapObjectLoader::construct()
 	ObjectTemplate appearance;
 
 	appearance.readJson(configuration["template"], false);
+	appearance.id = Obj(handler->type);
+	appearance.subid = handler->subtype;
 
 	instance = handler->create(appearance);
+
 	instance->id = ObjectInstanceID(owner->map->objects.size());
 	instance->instanceName = jsonKey;
 	instance->pos = pos;

+ 12 - 1
test/MapComparer.cpp

@@ -116,6 +116,16 @@ void checkEqual(const DisposedHero & actual, const DisposedHero & expected)
 	VCMI_CHECK_FIELD_EQUAL(portrait);
 	VCMI_CHECK_FIELD_EQUAL(name);
 	VCMI_CHECK_FIELD_EQUAL(players);
+
+}
+
+void checkEqual(const ObjectTemplate & actual, const ObjectTemplate & expected)
+{
+	VCMI_CHECK_FIELD_EQUAL(id);
+	VCMI_CHECK_FIELD_EQUAL(subid);
+	VCMI_CHECK_FIELD_EQUAL(printPriority);
+	VCMI_CHECK_FIELD_EQUAL(animationFile);
+	//VCMI_CHECK_FIELD_EQUAL(stringID);
 }
 
 void checkEqual(const TerrainTile & actual, const TerrainTile & expected)
@@ -196,8 +206,9 @@ void MapComparer::compareObject(const CGObjectInstance * actual, const CGObjectI
 	std::string expectedFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % expected->typeName % expected->ID % expected->subTypeName % expected->subID % expected->tempOwner);
 
 	BOOST_CHECK_EQUAL(actualFullID, expectedFullID);
-	BOOST_CHECK_EQUAL(actual->pos, expected->pos);
 
+	VCMI_CHECK_FIELD_EQUAL_P(pos);
+	checkEqual(actual->appearance, expected->appearance);
 }
 
 void MapComparer::compareObjects()