2
0
Эх сурвалжийг харах

Load object appearance and pos before addNewObject call, it is required for block-visit calculation.
Added a test for tile block-visit.

AlexVinS 9 жил өмнө
parent
commit
d2f04332d0

+ 5 - 12
lib/mapObjects/CObjectHandler.cpp

@@ -322,31 +322,24 @@ bool CGObjectInstance::passableFor(PlayerColor color) const
 
 void CGObjectInstance::serializeJson(JsonSerializeFormat & handler)
 {
+	//only save here, loading is handled by map loader
 	if(handler.saving)
 	{
 		handler.serializeString("type", typeName);
 		handler.serializeString("subtype", subTypeName);
-	}
-
-	handler.serializeNumeric("x", pos.x);
-	handler.serializeNumeric("y", pos.y);
-	handler.serializeNumeric("l", pos.z);
 
-	if(handler.saving)
-	{
+		handler.serializeNumeric("x", pos.x);
+		handler.serializeNumeric("y", pos.y);
+		handler.serializeNumeric("l", pos.z);
 		appearance.writeJson(handler.getCurrent()["template"], false);
 	}
-	else
-	{
-		appearance.readJson(handler.getCurrent()["template"], false);
-	}
 
 	{
 		auto options = handler.enterStruct("options");
 		serializeJsonOptions(handler);
 	}
 
-	if(handler.saving && handler.getCurrent()["options"].isNull())
+	if(handler.saving && handler.getCurrent()["options"].Struct().empty())
 	{
 		handler.getCurrent().Struct().erase("options");
 	}

+ 15 - 8
lib/mapping/MapFormatJson.cpp

@@ -746,7 +746,7 @@ void CMapLoaderJson::MapObjectLoader::construct()
 
 	//TODO:consider move to ObjectTypeHandler
 	//find type handler
-	std::string typeName = configuration["type"].String(), subTypeName = configuration["subtype"].String();
+	std::string typeName = configuration["type"].String(), subtypeName = configuration["subtype"].String();
 	if(typeName.empty())
 	{
 		logGlobal->errorStream() << "Object type missing";
@@ -754,29 +754,36 @@ void CMapLoaderJson::MapObjectLoader::construct()
 		return;
 	}
 
+	int3 pos;
+	pos.x = configuration["x"].Float();
+	pos.y = configuration["y"].Float();
+	pos.z = configuration["l"].Float();
 
 	//special case for grail
     if(typeName == "grail")
 	{
-		auto & pos = owner->map->grailPos;
-		pos.x = configuration["x"].Float();
-		pos.y = configuration["y"].Float();
-		pos.z = configuration["l"].Float();
+		owner->map->grailPos = pos;
+
 		owner->map->grailRadius = configuration["options"]["grailRadius"].Float();
 		return;
 	}
-	else if(subTypeName.empty())
+	else if(subtypeName.empty())
 	{
 		logGlobal->errorStream() << "Object subtype missing";
 		logGlobal->debugStream() << configuration;
 		return;
 	}
 
-	auto handler = VLC->objtypeh->getHandlerFor(typeName, subTypeName);
+	auto handler = VLC->objtypeh->getHandlerFor(typeName, subtypeName);
+
+	ObjectTemplate appearance;
+
+	appearance.readJson(configuration["template"], false);
 
-	instance = handler->create(ObjectTemplate());
+	instance = handler->create(appearance);
 	instance->id = ObjectInstanceID(owner->map->objects.size());
 	instance->instanceName = jsonKey;
+	instance->pos = pos;
 	owner->map->addNewObject(instance);
 }
 

+ 7 - 0
test/MapComparer.cpp

@@ -128,6 +128,13 @@ void checkEqual(const TerrainTile & actual, const TerrainTile & expected)
 	VCMI_REQUIRE_FIELD_EQUAL(roadType);
 	VCMI_REQUIRE_FIELD_EQUAL(roadDir);
 	VCMI_REQUIRE_FIELD_EQUAL(extTileFlags);
+
+	BOOST_REQUIRE_EQUAL(actual.blockingObjects.size(), expected.blockingObjects.size());
+	BOOST_REQUIRE_EQUAL(actual.visitableObjects.size(), expected.visitableObjects.size());
+
+	VCMI_REQUIRE_FIELD_EQUAL(visitable);
+	VCMI_REQUIRE_FIELD_EQUAL(blocked);
+
 }
 
 void MapComparer::compareHeader()