1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Merge pull request #4964 from vcmi/connections_rework

Connections rework
This commit is contained in:
Ivan Savenko
2024-12-02 13:21:32 +02:00
committed by GitHub
3 changed files with 29 additions and 9 deletions

View File

@@ -421,6 +421,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
}
ZoneConnection::ZoneConnection():
id(-1),
zoneA(-1),
zoneB(-1),
guardStrength(0),
@@ -430,6 +431,16 @@ ZoneConnection::ZoneConnection():
}
int ZoneConnection::getId() const
{
return id;
}
void ZoneConnection::setId(int id)
{
this->id = id;
}
TRmgTemplateZoneId ZoneConnection::getZoneA() const
{
return zoneA;
@@ -473,7 +484,7 @@ rmg::ERoadOption ZoneConnection::getRoadOption() const
bool operator==(const ZoneConnection & l, const ZoneConnection & r)
{
return l.zoneA == r.zoneA && l.zoneB == r.zoneB && l.guardStrength == r.guardStrength;
return l.id == r.id;
}
void ZoneConnection::serializeJson(JsonSerializeFormat & handler)
@@ -592,7 +603,7 @@ const CRmgTemplate::Zones & CRmgTemplate::getZones() const
const std::vector<ZoneConnection> & CRmgTemplate::getConnectedZoneIds() const
{
return connectedZoneIds;
return connections;
}
void CRmgTemplate::validate() const
@@ -721,7 +732,14 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
{
auto connectionsData = handler.enterArray("connections");
connectionsData.serializeStruct(connectedZoneIds);
connectionsData.serializeStruct(connections);
if(!handler.saving)
{
for(size_t i = 0; i < connections.size(); ++i)
{
connections[i].setId(i);
}
}
}
{
@@ -843,7 +861,7 @@ void CRmgTemplate::afterLoad()
}
}
for(const auto & connection : connectedZoneIds)
for(const auto & connection : connections)
{
auto id1 = connection.getZoneA();
auto id2 = connection.getZoneB();