diff options
Diffstat (limited to 'src/engine/TrackBrowser.cpp')
| -rw-r--r-- | src/engine/TrackBrowser.cpp | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/src/engine/TrackBrowser.cpp b/src/engine/TrackBrowser.cpp index 7d76a46bc..7fd5dddad 100644 --- a/src/engine/TrackBrowser.cpp +++ b/src/engine/TrackBrowser.cpp @@ -1,6 +1,7 @@ #include "TrackBrowser.h" #include "port/Engine.h" #include "engine/editor/SceneManager.h" +#include <imgui.h> TrackBrowser* TrackBrowser::Instance; @@ -8,65 +9,63 @@ void TrackBrowser::FindCustomTracks() { auto manager = GameEngine::Instance->context->GetResourceManager()->GetArchiveManager(); auto ptr2 = manager->ListDirectories("tracks/*"); - if (ptr2) { - auto dirs = *ptr2; - - for (const std::string& dir : dirs) { - std::string name = dir.substr(dir.find_last_of('/') + 1); - std::string sceneFile = dir + "/scene.json"; - std::string minimapFile = dir + "/minimap.png"; - - // The track has a valid scene file, add it to the registry - if (manager->HasFile(sceneFile)) { - auto archive = manager->GetArchiveFromFile(sceneFile); + if (!ptr2) { + return; + } + auto dirs = *ptr2; + + for (const std::string& dir : dirs) { + std::string name = dir.substr(dir.find_last_of('/') + 1); + std::string sceneFile = dir + "/scene.json"; + std::string minimapFile = dir + "/minimap.png"; + + // The track has a valid scene file, add it to the registry + if (manager->HasFile(sceneFile)) { + auto archive = manager->GetArchiveFromFile(sceneFile); + + TrackInfo info; + info.Path = dir; + TrackEditor::LoadTrackInfo(info, archive, sceneFile); + printf("[TrackBrowser] Added custom track %s\n", info.Name.c_str()); + gTrackRegistry.Add(info, [info, archive]() { + auto track = std::make_unique<Track>(); + track->ResourceName = info.ResourceName; + track->Archive = archive; + GetWorld()->SetCurrentTrack(std::move(track)); + }); + } else { // The track does not have a valid scene file + const std::string file = dir + "/data_track_sections"; + // If the track has a data_track_sections file, + // then it must at least be a valid track. + // So lets add it as an uninitialized track. + if (manager->HasFile(file)) { + printf("[TrackBrowser] [FindCustomTracks] Found a new custom track!\n"); + printf(" Creating scene.json so the track can be configured in the editor\n"); TrackInfo info; + std::string resName = std::string("mods:") + name; + info.ResourceName = resName; + info.Name = name; + info.DebugName = name; info.Path = dir; - Editor::LoadTrackInfo(info, archive, sceneFile); - printf("Added custom track %s\n", info.Name.c_str()); + + // Create the track + auto archive = manager->GetArchiveFromFile(file); + auto track = std::make_unique<Track>(); + track->Archive = archive; + track->ResourceName = info.ResourceName; + TrackEditor::SaveLevel(track.get(), static_cast<const TrackInfo*>(&info)); // Write scene file so it will show up in the track browser + printf("[TrackBrowser] [FindCustomTracks] Saved scene.json to new track!\n"); + + // Passing these through seems kinda bad. But it works? gTrackRegistry.Add(info, [info, archive]() { auto track = std::make_unique<Track>(); - track->ResourceName = info.ResourceName; track->Archive = archive; + track->ResourceName = info.ResourceName; GetWorld()->SetCurrentTrack(std::move(track)); }); - } else { // The track does not have a valid scene file - const std::string file = dir + "/data_track_sections"; - - // If the track has a data_track_sections file, - // then it must at least be a valid track. - // So lets add it as an uninitialized track. - if (manager->HasFile(file)) { - printf("[TrackBrowser] [FindCustomTracks] Found a new custom track!\n"); - printf(" Creating scene.json so the track can be configured in the editor\n"); - - TrackInfo info; - - std::string resName = std::string("mods:") + name; - info.ResourceName = resName; - info.Name = name; - info.DebugName = name; - info.Path = dir; - - auto archive = manager->GetArchiveFromFile(file); - //mNewTracks.push_back({info, "", dir, archive}); - auto track = std::make_unique<Track>(); - track->Archive = archive; - track->ResourceName = info.ResourceName; - Editor::SaveLevel(track.get(), &info); // Write scene file so it will show up in the track browser - printf("[TrackBrowser] [FindCustomTracks] Saved scene.json to new track!\n"); - - // Passing these through seems kinda bad. But it works? - gTrackRegistry.Add(info, [info, archive]() { - auto track = std::make_unique<Track>(); - track->Archive = archive; - track->ResourceName = info.ResourceName; - GetWorld()->SetCurrentTrack(std::move(track)); - }); - - } else { - printf("ContentBrowser.cpp: Track '%s' missing required track files. Cannot add to game\n Missing %s/data_track_sections file\n", name.c_str(), dir.c_str()); - } + } else { + printf("[TrackBrowser] Track '%s' missing required track files. Cannot add to game\n Missing %s/data_track_sections file\n", name.c_str(), dir.c_str()); } } } |
