Added 12V tracks.

This commit is contained in:
Leonardo Zide
2025-02-17 13:38:29 -08:00
parent 1d065c10c9
commit fbc0150855
3 changed files with 124 additions and 52 deletions
+44 -28
View File
@@ -28,41 +28,46 @@ void lcTrainTrackInit(lcPiecesLibrary* Library)
for (QJsonObject::const_iterator PiecesIt = JsonPieces.constBegin(); PiecesIt != JsonPieces.constEnd(); ++PiecesIt)
{
PieceInfo* Info = Library->FindPiece(PiecesIt.key().toLatin1(), nullptr, false, false);
if (!Info)
continue;
lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo();
Info->SetTrainTrackInfo(TrainTrackInfo);
QJsonObject JsonPiece = PiecesIt->toObject();
QJsonArray JsonConnections = JsonPiece["Connections"].toArray();
QJsonArray JsonParts = JsonPiece["Parts"].toArray();
for (QJsonArray::const_iterator ConnectionIt = JsonConnections.constBegin(); ConnectionIt != JsonConnections.constEnd(); ++ConnectionIt)
for (QJsonArray::const_iterator PartsIt = JsonParts.constBegin(); PartsIt != JsonParts.constEnd(); ++PartsIt)
{
QJsonObject JsonConnection = ConnectionIt->toObject();
PieceInfo* Info = Library->FindPiece(PartsIt->toString().toLatin1(), nullptr, false, false);
QJsonArray JsonPosition = JsonConnection["Position"].toArray();
lcVector3 Position(JsonPosition[0].toDouble(), JsonPosition[1].toDouble(), JsonPosition[2].toDouble());
if (!Info)
continue;
float Rotation = JsonConnection["Rotation"].toDouble() * LC_DTOR;
QString ConnectionGroup = JsonConnection["Type"].toString();
int ConnectionDirection = 0;
lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo();
if (ConnectionGroup.startsWith('+'))
Info->SetTrainTrackInfo(TrainTrackInfo);
QJsonArray JsonConnections = JsonPiece["Connections"].toArray();
for (QJsonArray::const_iterator ConnectionIt = JsonConnections.constBegin(); ConnectionIt != JsonConnections.constEnd(); ++ConnectionIt)
{
ConnectionDirection = 1;
ConnectionGroup = ConnectionGroup.mid(1);
}
else if (ConnectionGroup.startsWith('-'))
{
ConnectionDirection = -1;
ConnectionGroup = ConnectionGroup.mid(1);
}
QJsonObject JsonConnection = ConnectionIt->toObject();
TrainTrackInfo->AddConnection(lcMatrix44(lcMatrix33RotationZ(Rotation), Position), { qHash(ConnectionGroup), ConnectionDirection } );
QJsonArray JsonPosition = JsonConnection["Position"].toArray();
lcVector3 Position(JsonPosition[0].toDouble(), JsonPosition[1].toDouble(), JsonPosition[2].toDouble());
float Rotation = JsonConnection["Rotation"].toDouble() * LC_DTOR;
QString ConnectionGroup = JsonConnection["Type"].toString();
int ConnectionDirection = 0;
if (ConnectionGroup.startsWith('+'))
{
ConnectionDirection = 1;
ConnectionGroup = ConnectionGroup.mid(1);
}
else if (ConnectionGroup.startsWith('-'))
{
ConnectionDirection = -1;
ConnectionGroup = ConnectionGroup.mid(1);
}
TrainTrackInfo->AddConnection(lcMatrix44(lcMatrix33RotationZ(Rotation), Position), { qHash(ConnectionGroup), ConnectionDirection } );
}
}
}
}
@@ -120,7 +125,18 @@ std::optional<lcMatrix44> lcTrainTrackInfo::GetPieceInsertTransform(lcPiece* Cur
return std::nullopt;
}
return GetConnectionTransform(CurrentPiece, ConnectionIndex, Info, ConnectionIndex ? 0 : 1);
const lcTrainTrackConnectionType& CurrentConnectionType = CurrentTrackInfo->GetConnections()[ConnectionIndex].Type;
const std::vector<lcTrainTrackConnection>& NewConnections = Info->GetTrainTrackInfo()->GetConnections();
quint32 NewConnectionIndex;// = ConnectionIndex ? 0 : 1;
for (NewConnectionIndex = 0; NewConnectionIndex < NewConnections.size(); NewConnectionIndex++)
if (AreConnectionsCompatible(CurrentConnectionType, NewConnections[NewConnectionIndex].Type))
break;
if (NewConnectionIndex == NewConnections.size())
return std::nullopt;
return GetConnectionTransform(CurrentPiece, ConnectionIndex, Info, NewConnectionIndex);
}
std::optional<lcMatrix44> lcTrainTrackInfo::GetConnectionTransform(lcPiece* CurrentPiece, quint32 CurrentConnectionIndex, PieceInfo* Info, quint32 NewConnectionIndex)
+7 -2
View File
@@ -37,16 +37,21 @@ public:
return mConnections;
}
bool CanConnectTo(lcTrainTrackConnectionType ConnectionType) const
bool CanConnectTo(const lcTrainTrackConnectionType& ConnectionType) const
{
for (const lcTrainTrackConnection& Connection : mConnections)
if (Connection.Type.Group == ConnectionType.Group && Connection.Type.Format + ConnectionType.Format == 0)
if (AreConnectionsCompatible(Connection.Type, ConnectionType))
return true;
return false;
}
protected:
static bool AreConnectionsCompatible(const lcTrainTrackConnectionType& a, const lcTrainTrackConnectionType& b)
{
return a.Group == b.Group && a.Format + b.Format == 0;
}
std::vector<lcTrainTrackConnection> mConnections;
};
+73 -22
View File
@@ -2,9 +2,9 @@
"Version": 1,
"Pieces":
{
"2859c04.dat":
"Train Track 9V Point Right":
{
"Description": "Train Track 9V Point Right Branching (Complete)",
"Parts": [ "2859c03.dat", "2859c04.dat" ],
"Connections":
[
{
@@ -24,9 +24,9 @@
}
]
},
"2861c04.dat":
"Train Track 9V Point Left":
{
"Description": "Train Track 9V Point Left Branching (Complete)",
"Parts": [ "2861c03.dat", "2861c04.dat" ],
"Connections":
[
{
@@ -46,9 +46,9 @@
}
]
},
"32087.dat":
"Train Track 9V Crossing":
{
"Description": "Train Track 9V Crossing",
"Parts": [ "32087.dat" ],
"Connections":
[
{
@@ -73,9 +73,9 @@
}
]
},
"74746.dat":
"Train Track 9V Straight":
{
"Description": "Train Track 9V Straight",
"Parts": [ "74746.dat" ],
"Connections":
[
{
@@ -90,9 +90,9 @@
}
]
},
"74747.dat":
"Train Track 9V Curved":
{
"Description": "Train Track 9V Curved",
"Parts": [ "74747.dat" ],
"Connections":
[
{
@@ -107,9 +107,9 @@
}
]
},
"3241ac01.dat":
"Train Track 12V Slotted Curved":
{
"Description": "Train Track 12V Slotted Curved (Complete 1 Segment)",
"Parts": [ "3241ac01.dat" ],
"Connections":
[
{
@@ -124,9 +124,9 @@
}
]
},
"4166a.dat":
"Train Track Sleeper Plate 2 x 8":
{
"Description": "Train Track Sleeper Plate 2 x 8 without Cable Grooves",
"Parts": [ "4166a.dat" ],
"Connections":
[
{
@@ -141,9 +141,26 @@
}
]
},
"3240bc02.dat":
"Train Track 12V Slotted Straight With End Sleepers":
{
"Description": "Train Track 12V Slotted Straight with Conductive Centre Rail with Sockets (Complete without End Sleepers)",
"Parts": [ "3240ac01.dat", "3240bc01.dat" ],
"Connections":
[
{
"Position": [ 160.0, 0.0, 0.0 ],
"Rotation": 0.0,
"Type": "+12V"
},
{
"Position": [ -160.0, 0.0, 0.0 ],
"Rotation": -180.0,
"Type": "-12V"
}
]
},
"Train Track 12V Slotted Straight Without End Sleepers":
{
"Parts": [ "3240ac02.dat", "3240bc02.dat" ],
"Connections":
[
{
@@ -158,9 +175,43 @@
}
]
},
"73697ac03.dat":
"Train Track 12V Slotted Straight With Signal":
{
"Description": "Train Track 12V Slotted Point Left Electric (Straight)",
"Parts": [ "862ac02.dat" ],
"Connections":
[
{
"Position": [ 160.0, 0.0, 0.0 ],
"Rotation": 0.0,
"Type": "+12V"
},
{
"Position": [ -160.0, 0.0, 0.0 ],
"Rotation": -180.0,
"Type": "+12V"
}
]
},
"Train Track 12V Slotted Decoupler":
{
"Parts": [ "u9230c01.dat", "u9230c02.dat" ],
"Connections":
[
{
"Position": [ 160.0, 0.0, 0.0 ],
"Rotation": 0.0,
"Type": "+12V"
},
{
"Position": [ -160.0, 0.0, 0.0 ],
"Rotation": -180.0,
"Type": "+12V"
}
]
},
"Train Track 12V Slotted Point Left":
{
"Parts": [ "73697ac01.dat", "73697ac02.dat", "73697ac03.dat", "73697ac04.dat" ],
"Connections":
[
{
@@ -180,9 +231,9 @@
}
]
},
"73696ac04.dat":
"Train Track 12V Slotted Point Right":
{
"Description": "Train Track 12V Slotted Point Right Electric (Branching)",
"Parts": [ "73696ac01.dat", "73696ac02.dat", "73696ac03.dat", "73696ac04.dat" ],
"Connections":
[
{
@@ -202,9 +253,9 @@
}
]
},
"73698.dat":
"Train Track 12V Slotted Crossing":
{
"Description": "Train Track 12V Slotted Crossing",
"Parts": [ "73698.dat" ],
"Connections":
[
{