mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Allow multiple terrains per biome
This commit is contained in:
@@ -15,9 +15,18 @@
|
||||
"description" : "Type of the obstacle set"
|
||||
},
|
||||
"terrain" : {
|
||||
// TODO: Allow multiple terrains
|
||||
"type" : "string",
|
||||
"description" : "Terrain of the obstacle set"
|
||||
"anyOf": [
|
||||
{
|
||||
"type" : "string",
|
||||
"description" : "Terrain of the obstacle set"
|
||||
},
|
||||
{
|
||||
"type" : "array",
|
||||
"items" : { "type" : "string" },
|
||||
"description" : "Terrains of the obstacle set"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -17,13 +17,13 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
ObstacleSet::ObstacleSet():
|
||||
type(INVALID),
|
||||
terrain(TerrainId::NONE)
|
||||
allowedTerrains({TerrainId::NONE})
|
||||
{
|
||||
}
|
||||
|
||||
ObstacleSet::ObstacleSet(EObstacleType type, TerrainId terrain):
|
||||
type(type),
|
||||
terrain(terrain)
|
||||
allowedTerrains({terrain})
|
||||
{
|
||||
}
|
||||
|
||||
@@ -46,22 +46,27 @@ ObstacleSetFilter::ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, Ter
|
||||
|
||||
bool ObstacleSetFilter::filter(const ObstacleSet &set) const
|
||||
{
|
||||
return (set.getTerrain() == terrain) || (terrain == TerrainId::ANY_TERRAIN);
|
||||
return (vstd::contains(set.getTerrains(), terrain) || terrain == TerrainId::ANY_TERRAIN);
|
||||
}
|
||||
|
||||
TerrainId ObstacleSetFilter::getTerrain() const
|
||||
std::set<TerrainId> ObstacleSet::getTerrains() const
|
||||
{
|
||||
return terrain;
|
||||
}
|
||||
|
||||
TerrainId ObstacleSet::getTerrain() const
|
||||
{
|
||||
return terrain;
|
||||
return allowedTerrains;
|
||||
}
|
||||
|
||||
void ObstacleSet::setTerrain(TerrainId terrain)
|
||||
{
|
||||
this->terrain = terrain;
|
||||
this->allowedTerrains = {terrain};
|
||||
}
|
||||
|
||||
void ObstacleSet::setTerrains(const std::set<TerrainId> & terrains)
|
||||
{
|
||||
this->allowedTerrains = terrains;
|
||||
}
|
||||
|
||||
void ObstacleSet::addTerrain(TerrainId terrain)
|
||||
{
|
||||
this->allowedTerrains.insert(terrain);
|
||||
}
|
||||
|
||||
ObstacleSet::EObstacleType ObstacleSet::getType() const
|
||||
@@ -221,12 +226,27 @@ std::shared_ptr<ObstacleSet> ObstacleSetHandler::loadFromJson(const std::string
|
||||
auto biome = json["biome"].Struct();
|
||||
os->setType(ObstacleSet::typeFromString(biome["objectType"].String()));
|
||||
|
||||
auto terrainName = biome["terrain"].String();
|
||||
|
||||
VLC->identifiers()->requestIdentifier(scope, "terrain", terrainName, [os](si32 id)
|
||||
if (biome["terrain"].isString())
|
||||
{
|
||||
os->setTerrain(TerrainId(id));
|
||||
});
|
||||
auto terrainName = biome["terrain"].String();
|
||||
|
||||
VLC->identifiers()->requestIdentifier(scope, "terrain", terrainName, [os](si32 id)
|
||||
{
|
||||
os->setTerrain(TerrainId(id));
|
||||
});
|
||||
}
|
||||
else // Other cases won't pass validation
|
||||
{
|
||||
auto terrains = biome["terrain"].Vector();
|
||||
|
||||
for (const auto & terrain : terrains)
|
||||
{
|
||||
VLC->identifiers()->requestIdentifier(scope, "terrain", terrain.String(), [os](si32 id)
|
||||
{
|
||||
os->addTerrain(TerrainId(id));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
auto templates = json["templates"].Vector();
|
||||
for (const auto & node : templates)
|
||||
|
||||
@@ -46,8 +46,10 @@ public:
|
||||
EObstacleType getType() const;
|
||||
void setType(EObstacleType type);
|
||||
|
||||
TerrainId getTerrain() const;
|
||||
std::set<TerrainId> getTerrains() const;
|
||||
void setTerrain(TerrainId terrain);
|
||||
void setTerrains(const std::set<TerrainId> & terrains);
|
||||
void addTerrain(TerrainId terrain);
|
||||
|
||||
static EObstacleType typeFromString(const std::string &str);
|
||||
std::string toString() const;
|
||||
@@ -56,7 +58,7 @@ public:
|
||||
|
||||
private:
|
||||
EObstacleType type;
|
||||
TerrainId terrain;
|
||||
std::set<TerrainId> allowedTerrains;
|
||||
std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user