mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-28 03:57:02 +02:00
Handle connections by unique id
This commit is contained in:
parent
a4417f3fc5
commit
c8e3458dfb
@ -420,6 +420,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ZoneConnection::ZoneConnection():
|
ZoneConnection::ZoneConnection():
|
||||||
|
id(-1),
|
||||||
zoneA(-1),
|
zoneA(-1),
|
||||||
zoneB(-1),
|
zoneB(-1),
|
||||||
guardStrength(0),
|
guardStrength(0),
|
||||||
@ -429,6 +430,16 @@ ZoneConnection::ZoneConnection():
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ZoneConnection::getId() const
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZoneConnection::setId(int id)
|
||||||
|
{
|
||||||
|
this->id = id;
|
||||||
|
}
|
||||||
|
|
||||||
TRmgTemplateZoneId ZoneConnection::getZoneA() const
|
TRmgTemplateZoneId ZoneConnection::getZoneA() const
|
||||||
{
|
{
|
||||||
return zoneA;
|
return zoneA;
|
||||||
@ -472,7 +483,7 @@ rmg::ERoadOption ZoneConnection::getRoadOption() const
|
|||||||
|
|
||||||
bool operator==(const ZoneConnection & l, const ZoneConnection & r)
|
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)
|
void ZoneConnection::serializeJson(JsonSerializeFormat & handler)
|
||||||
@ -591,7 +602,7 @@ const CRmgTemplate::Zones & CRmgTemplate::getZones() const
|
|||||||
|
|
||||||
const std::vector<ZoneConnection> & CRmgTemplate::getConnectedZoneIds() const
|
const std::vector<ZoneConnection> & CRmgTemplate::getConnectedZoneIds() const
|
||||||
{
|
{
|
||||||
return connectedZoneIds;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRmgTemplate::validate() const
|
void CRmgTemplate::validate() const
|
||||||
@ -720,7 +731,14 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto connectionsData = handler.enterArray("connections");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -842,7 +860,7 @@ void CRmgTemplate::afterLoad()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const auto & connection : connectedZoneIds)
|
for(const auto & connection : connections)
|
||||||
{
|
{
|
||||||
auto id1 = connection.getZoneA();
|
auto id1 = connection.getZoneA();
|
||||||
auto id2 = connection.getZoneB();
|
auto id2 = connection.getZoneB();
|
||||||
|
@ -96,6 +96,8 @@ public:
|
|||||||
|
|
||||||
ZoneConnection();
|
ZoneConnection();
|
||||||
|
|
||||||
|
int getId() const;
|
||||||
|
void setId(int id);
|
||||||
TRmgTemplateZoneId getZoneA() const;
|
TRmgTemplateZoneId getZoneA() const;
|
||||||
TRmgTemplateZoneId getZoneB() const;
|
TRmgTemplateZoneId getZoneB() const;
|
||||||
TRmgTemplateZoneId getOtherZoneId(TRmgTemplateZoneId id) const;
|
TRmgTemplateZoneId getOtherZoneId(TRmgTemplateZoneId id) const;
|
||||||
@ -107,6 +109,7 @@ public:
|
|||||||
|
|
||||||
friend bool operator==(const ZoneConnection &, const ZoneConnection &);
|
friend bool operator==(const ZoneConnection &, const ZoneConnection &);
|
||||||
private:
|
private:
|
||||||
|
int id;
|
||||||
TRmgTemplateZoneId zoneA;
|
TRmgTemplateZoneId zoneA;
|
||||||
TRmgTemplateZoneId zoneB;
|
TRmgTemplateZoneId zoneB;
|
||||||
int guardStrength;
|
int guardStrength;
|
||||||
@ -293,7 +296,7 @@ private:
|
|||||||
CPlayerCountRange players;
|
CPlayerCountRange players;
|
||||||
CPlayerCountRange humanPlayers;
|
CPlayerCountRange humanPlayers;
|
||||||
Zones zones;
|
Zones zones;
|
||||||
std::vector<rmg::ZoneConnection> connectedZoneIds;
|
std::vector<rmg::ZoneConnection> connections;
|
||||||
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
||||||
std::unique_ptr<JsonNode> mapSettings;
|
std::unique_ptr<JsonNode> mapSettings;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user