mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-06-06 11:47:59 -04:00
make id of cup more robust and fix a mistake (#604)
* fix id koopa troopa beach * make id of cup more robust
This commit is contained in:
@@ -45,3 +45,22 @@ void Cup::ShuffleTracks() {
|
||||
// std::mt19937 g(rd());
|
||||
//std::shuffle(mTracks.begin(), mTracks.end(), g);
|
||||
}
|
||||
|
||||
void Cup::ValidateTrackIds(const Registry<TrackInfo>& registry) const {
|
||||
std::vector<std::string> invalidTracks;
|
||||
|
||||
for (const auto& trackId : mTracks) {
|
||||
if (!registry.Find(trackId)) {
|
||||
invalidTracks.push_back(trackId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!invalidTracks.empty()) {
|
||||
std::string errorMsg = "Cup '" + Id + "' contains invalid track IDs: ";
|
||||
for (size_t i = 0; i < invalidTracks.size(); ++i) {
|
||||
if (i > 0) errorMsg += ", ";
|
||||
errorMsg += "'" + invalidTracks[i] + "'";
|
||||
}
|
||||
throw std::invalid_argument(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "tracks/Track.h"
|
||||
#include "registry/Registry.h"
|
||||
|
||||
class Track; // <-- Forward declare
|
||||
|
||||
@@ -17,6 +18,9 @@ public:
|
||||
|
||||
explicit Cup(std::string id, const char* name, std::vector<std::string> tracks);
|
||||
|
||||
// Valide que tous les IDs de tracks existent dans le registre
|
||||
void ValidateTrackIds(const Registry<TrackInfo>& registry) const;
|
||||
|
||||
virtual void ShuffleTracks();
|
||||
|
||||
virtual void Next();
|
||||
|
||||
@@ -74,7 +74,7 @@ void RegisterTracks(Registry<TrackInfo>& r) {
|
||||
r.Add(info, []() { GetWorld()->SetCurrentTrack(std::make_unique<FrappeSnowland>()); });
|
||||
|
||||
info = {
|
||||
.ResourceName = "mk:koopa_beach",
|
||||
.ResourceName = "mk:koopa_troopa_beach",
|
||||
.Name = "koopa troopa beach",
|
||||
.DebugName = "beach",
|
||||
.Length = "691m",
|
||||
|
||||
@@ -52,7 +52,7 @@ KoopaTroopaBeach::KoopaTroopaBeach() {
|
||||
Props.Minimap.FinishlineY = 0;
|
||||
ResizeMinimap(&Props.Minimap);
|
||||
|
||||
ResourceName = "mk:koopa_beach";
|
||||
ResourceName = "mk:koopa_troopa_beach";
|
||||
Props.SetText(Props.Name, "koopa troopa beach", sizeof(Props.Name));
|
||||
Props.SetText(Props.DebugName, "beach", sizeof(Props.DebugName));
|
||||
Props.SetText(Props.TrackLength, "691m", sizeof(Props.TrackLength));
|
||||
|
||||
@@ -135,6 +135,13 @@ void CustomEngineInit() {
|
||||
"mk:skyscraper"
|
||||
});
|
||||
|
||||
/* Validate Cup Track IDs */
|
||||
gMushroomCup->ValidateTrackIds(gTrackRegistry);
|
||||
gFlowerCup->ValidateTrackIds(gTrackRegistry);
|
||||
gStarCup->ValidateTrackIds(gTrackRegistry);
|
||||
gSpecialCup->ValidateTrackIds(gTrackRegistry);
|
||||
gBattleCup->ValidateTrackIds(gTrackRegistry);
|
||||
|
||||
/* Instantiate Cups */
|
||||
GetWorld()->AddCup(gMushroomCup);
|
||||
GetWorld()->AddCup(gFlowerCup);
|
||||
|
||||
Reference in New Issue
Block a user