1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

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

Added a test for tile block-visit.
This commit is contained in:
AlexVinS
2016-02-23 23:46:33 +03:00
parent c3775486db
commit d2f04332d0
3 changed files with 27 additions and 20 deletions

View File

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

View File

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

View File

@@ -128,6 +128,13 @@ void checkEqual(const TerrainTile & actual, const TerrainTile & expected)
VCMI_REQUIRE_FIELD_EQUAL(roadType); VCMI_REQUIRE_FIELD_EQUAL(roadType);
VCMI_REQUIRE_FIELD_EQUAL(roadDir); VCMI_REQUIRE_FIELD_EQUAL(roadDir);
VCMI_REQUIRE_FIELD_EQUAL(extTileFlags); 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() void MapComparer::compareHeader()