1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

store ObjectInstanceID of objects to remove instead of their position

This commit is contained in:
godric3
2024-09-30 20:41:13 +02:00
parent e50ba14bbe
commit d078c5ff2d
7 changed files with 19 additions and 82 deletions

View File

@ -104,39 +104,8 @@ void CMapEvent::serializeJson(JsonSerializeFormat & handler)
handler.serializeInt("nextOccurrence", nextOccurrence);
resources.serializeJson(handler, "resources");
if(handler.saving)
{
JsonNode deletedObjectsJson;
for(const auto & entry : deletedObjectsCoordinates)
{
JsonNode values;
JsonNode valueX;
JsonNode valueY;
JsonNode valueZ;
valueX.Float() = static_cast<int>(entry.x);
valueY.Float() = static_cast<int>(entry.y);
valueZ.Float() = static_cast<int>(entry.z);
values.Vector().push_back(valueX);
values.Vector().push_back(valueY);
values.Vector().push_back(valueZ);
deletedObjectsJson.Vector().push_back(values);
}
handler.serializeRaw("deletedObjectsCoordinates", deletedObjectsJson, std::nullopt);
}
else
{
JsonNode deletedObjectsJson = handler.getCurrent()["deletedObjectsCoordinates"];
for(auto const & entry : deletedObjectsJson.Vector())
{
int3 position;
position.x = static_cast<int>(entry[0].Float());
position.y = static_cast<int>(entry[1].Float());
position.z = static_cast<int>(entry[2].Float());
deletedObjectsCoordinates.push_back(position);
}
}
auto deletedObjects = handler.enterArray("deletedObjectsInstances");
deletedObjects.serializeArray(deletedObjectsInstances);
}
void CCastleEvent::serializeJson(JsonSerializeFormat & handler)
@ -489,16 +458,6 @@ const CGObjectInstance * CMap::getObjectiveObjectFrom(const int3 & pos, Obj type
return bestMatch;
}
const CGObjectInstance * CMap::getObjectFrom(const int3 & pos)
{
for(CGObjectInstance * object : objects)
{
if(object->pos == pos)
return object;
}
return nullptr;
}
void CMap::checkForObjectives()
{
// NOTE: probably should be moved to MapFormatH3M.cpp