1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-08 23:22:25 +02:00

fix mine handler for rmg

This commit is contained in:
Laserlicht
2025-09-29 01:01:54 +02:00
parent 5ae4db60e3
commit 07659e3b25
3 changed files with 12 additions and 31 deletions

View File

@@ -251,35 +251,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
CArmedInstance::serializeJsonOptions(handler);
serializeJsonOwner(handler);
if(isAbandoned())
{
if(handler.saving)
{
JsonNode node;
for(const auto & resID : abandonedMineResources)
node.Vector().emplace_back(resID.toResource()->getJsonKey());
handler.serializeRaw("possibleResources", node, std::nullopt);
}
else
{
auto guard = handler.enterArray("possibleResources");
const JsonNode & node = handler.getCurrent();
auto names = node.convertTo<std::vector<std::string>>();
for(const std::string & s : names)
{
std::vector<std::string> resNames;
for(auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
resNames.push_back(res.toResource()->getJsonKey());
int raw_res = vstd::find_pos(resNames, s);
if(raw_res < 0)
logGlobal->error("Invalid resource name: %s", s);
else
abandonedMineResources.emplace(raw_res);
}
}
}
handler.serializeIdArray<GameResID>("possibleResources", abandonedMineResources);
}
bool CGTeleport::isEntrance() const

View File

@@ -12,6 +12,7 @@
#include "../RmgMap.h"
#include "../../mapObjectConstructors/AObjectTypeHandler.h"
#include "../../mapObjectConstructors/CObjectClassesHandler.h"
#include "../../mapObjectConstructors/CommonConstructors.h"
#include "../../mapObjects/CGResource.h"
#include "../../mapObjects/MiscObjects.h"
#include "../../mapping/CMapEditManager.h"
@@ -58,7 +59,14 @@ bool MinePlacer::placeMines(ObjectManager & manager)
const auto res = GameResID(mineInfo.first);
for(int i = 0; i < mineInfo.second; ++i)
{
auto mineHandler = LIBRARY->objtypeh->getHandlerFor(Obj::MINE, res);
TObjectTypeHandler mineHandler;
for(auto & subObjID : LIBRARY->objtypeh->knownSubObjects(Obj::MINE))
{
auto handler = std::dynamic_pointer_cast<MineInstanceConstructor>(LIBRARY->objtypeh->getHandlerFor(Obj::MINE, subObjID));
if(handler->getResourceType() == res)
mineHandler = handler;
}
const auto & rmginfo = mineHandler->getRMGInfo();
auto mine = std::dynamic_pointer_cast<CGMine>(mineHandler->create(map.mapInstance->cb, nullptr));
mine->producedResource = res;

View File

@@ -402,6 +402,7 @@ void Inspector::updateProperties(CGMine * o)
if(!o) return;
addProperty(QObject::tr("Owner"), o->tempOwner, new OwnerDelegate(controller), false);
if(o->producedResource != GameResID::NONE)
addProperty(QObject::tr("Resource"), o->producedResource);
addProperty(QObject::tr("Productivity"), o->producedQuantity);
}