Made sleeper id data driven.

This commit is contained in:
Leonardo Zide
2025-02-23 19:13:29 -08:00
parent eff843c9eb
commit 228fb79667
4 changed files with 32 additions and 7 deletions
+2 -2
View File
@@ -279,7 +279,7 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
UpdateStudStyleSource();
lcLoadDefaultCategories();
lcSynthInit();
lcTrainTrackInit(this);
lcTrainTrackInfo::Initialize(this);
return true;
}
@@ -1888,7 +1888,7 @@ bool lcPiecesLibrary::LoadBuiltinPieces()
lcLoadDefaultColors(lcStudStyle::Plain);
lcLoadDefaultCategories(true);
lcSynthInit();
lcTrainTrackInit(this);
lcTrainTrackInfo::Initialize(this);
return true;
}
+24 -3
View File
@@ -8,13 +8,14 @@
// todo:
// add the rest of the 9v and 12v tracks, look into 4.5v
// see if we should remove some of the 12v tracks to avoid bloat
// data driven sleepers
// lcView::GetPieceInsertTransform should use track connections when dragging a new track over an existing one
// better insert gizmo mouse detection
// auto replace cross when going over a straight section
// set focus connection after adding
void lcTrainTrackInit(lcPiecesLibrary* Library)
std::map<quint32, PieceInfo*> lcTrainTrackInfo::mSleepers;
void lcTrainTrackInfo::Initialize(lcPiecesLibrary* Library)
{
QFile ConfigFile(QLatin1String(":/resources/traintrack.json"));
@@ -73,6 +74,21 @@ void lcTrainTrackInit(lcPiecesLibrary* Library)
}
}
}
QJsonObject JsonSleepers = Root["Sleepers"].toObject();
mSleepers.clear();
for (QJsonObject::const_iterator SleepersIt = JsonSleepers.constBegin(); SleepersIt != JsonSleepers.constEnd(); ++SleepersIt)
{
quint32 Group = qHash(SleepersIt.key());
QString PartId = SleepersIt->toString();
PieceInfo* SleeperInfo = Library->FindPiece(PartId.toLatin1(), nullptr, false, false);
if (SleeperInfo)
mSleepers[Group] = SleeperInfo;
}
}
int lcTrainTrackInfo::GetPieceConnectionIndex(const lcPiece* Piece1, int ConnectionIndex1, const lcPiece* Piece2)
@@ -137,7 +153,12 @@ std::vector<lcTrainTrackInsert> lcTrainTrackInfo::GetPieceInsertTransforms(lcPie
if (CurrentConnectionType.Sleeper == lcTrainTrackConnectionSleeper::NeedsSleeper && NewConnections[NewConnectionIndex].Type.Sleeper == lcTrainTrackConnectionSleeper::NeedsSleeper)
{
PieceInfo* SleeperInfo = lcGetPiecesLibrary()->FindPiece("4166a.dat", nullptr, false, false); // todo: data driven
std::map<quint32, PieceInfo*>::const_iterator SleeperIt = mSleepers.find(CurrentConnectionType.Group);
if (SleeperIt == mSleepers.end())
return Pieces;
PieceInfo* SleeperInfo = SleeperIt->second;
if (!SleeperInfo)
return Pieces;
+2 -2
View File
@@ -37,6 +37,7 @@ class lcTrainTrackInfo
public:
lcTrainTrackInfo() = default;
static void Initialize(lcPiecesLibrary* Library);
static std::vector<lcTrainTrackInsert> GetPieceInsertTransforms(lcPiece* CurrentPiece, PieceInfo* Info, quint32 Section);
static std::optional<lcMatrix44> GetConnectionTransform(PieceInfo* CurrentInfo, const lcMatrix44& CurrentTransform, quint32 CurrentConnectionIndex, PieceInfo* Info, quint32 NewConnectionIndex);
static std::optional<lcMatrix44> CalculateTransformToConnection(const lcMatrix44& ConnectionTransform, PieceInfo* Info, quint32 ConnectionIndex);
@@ -83,6 +84,5 @@ protected:
}
std::vector<lcTrainTrackConnection> mConnections;
static std::map<quint32, PieceInfo*> mSleepers;
};
void lcTrainTrackInit(lcPiecesLibrary* Library);
+4
View File
@@ -297,5 +297,9 @@
}
]
}
},
"Sleepers":
{
"12V": "4166a.dat"
}
}