Fix new track bug (#593)
This commit is contained in:
parent
7bc8d6f4be
commit
2995361eb1
|
|
@ -37,22 +37,30 @@ void TrackBrowser::FindCustomTracks() {
|
|||
// 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>();
|
||||
Editor::SaveLevel(track.get()); // Write scene file so it will show up in the track browser
|
||||
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->ResourceName = info.ResourceName;
|
||||
track->Archive = archive;
|
||||
track->ResourceName = info.ResourceName;
|
||||
GetWorld()->SetCurrentTrack(std::move(track));
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -34,17 +34,25 @@ extern "C" {
|
|||
}
|
||||
|
||||
namespace Editor {
|
||||
void SaveLevel(Track* track) {
|
||||
void SaveLevel(Track* track, const TrackInfo* info) {
|
||||
nlohmann::json data;
|
||||
|
||||
/**
|
||||
* Save track properties, static mesh actors, actors, and tour camera
|
||||
*/
|
||||
data["Props"] = track->Props.to_json();
|
||||
try {
|
||||
data["Props"] = track->Props.to_json();
|
||||
} catch (...) {
|
||||
SPDLOG_ERROR("[SceneManager] [SaveLevel] Failed serializing track Props");
|
||||
}
|
||||
|
||||
nlohmann::json staticMesh;
|
||||
SaveStaticMeshActors(staticMesh);
|
||||
data["StaticMeshActors"] = staticMesh;
|
||||
try {
|
||||
nlohmann::json staticMesh;
|
||||
SaveStaticMeshActors(staticMesh);
|
||||
data["StaticMeshActors"] = staticMesh;
|
||||
} catch (...) {
|
||||
SPDLOG_ERROR("[SceneManager] [SaveLevel] Failed serializing StaticMeshActors");
|
||||
}
|
||||
|
||||
|
||||
nlohmann::json actors;
|
||||
|
|
@ -75,7 +83,6 @@ namespace Editor {
|
|||
std::vector<uint8_t> bytes; // Turn the str into raw data
|
||||
bytes.assign(jsonStr.begin(), jsonStr.end());
|
||||
|
||||
const TrackInfo* info = gTrackRegistry.GetInfo(track->ResourceName);
|
||||
std::string sceneFile = info->Path + "/scene.json";
|
||||
|
||||
// Write file to disk
|
||||
|
|
@ -304,8 +311,8 @@ namespace Editor {
|
|||
}
|
||||
|
||||
void SaveFog(nlohmann::json& fog) {
|
||||
fog["EnableFog"] = bFog;
|
||||
if (bFog) {
|
||||
fog["EnableFog"] = bFog;
|
||||
fog["Colour"]["R"] = gFogColour.r;
|
||||
fog["Colour"]["G"] = gFogColour.g;
|
||||
fog["Colour"]["B"] = gFogColour.b;
|
||||
|
|
@ -331,27 +338,34 @@ namespace Editor {
|
|||
}
|
||||
|
||||
void LoadPaths(Track* track, const std::string& trackPath) {
|
||||
SPDLOG_INFO("[SceneManager] [LoadPaths] Loading Paths...");
|
||||
std::string path_file = (trackPath + "/data_paths").c_str();
|
||||
|
||||
auto res = std::dynamic_pointer_cast<MK64::Paths>(ResourceLoad(path_file.c_str()));
|
||||
if (nullptr == res) {
|
||||
SPDLOG_ERROR(" Unable to load path file (data_paths)");
|
||||
SPDLOG_ERROR(" This file is required for custom tracks to work ");
|
||||
SPDLOG_ERROR(" Make sure the first path point is at coordinates 0,0,0");
|
||||
SPDLOG_ERROR(" In blender you may need to apply transformations and then move the point to 0,0,0");
|
||||
}
|
||||
|
||||
if (res != nullptr) {
|
||||
auto& paths = res->PathList;
|
||||
auto& paths = res->PathList;
|
||||
|
||||
size_t i = 0;
|
||||
u16* ptr = &track->Props.PathSizes.unk0;
|
||||
for (auto& path : paths) {
|
||||
if (i >= ARRAY_COUNT(track->Props.PathTable2)) {
|
||||
printf("[Track.cpp] The game can only import 5 paths. Found more than 5. Skipping the rest\n");
|
||||
break; // Only 5 paths allowed. 4 track, 1 vehicle
|
||||
}
|
||||
ptr[i] = path.size();
|
||||
track->Props.PathTable2[i] = (TrackPathPoint*) path.data();
|
||||
|
||||
i += 1;
|
||||
size_t i = 0;
|
||||
u16* ptr = &track->Props.PathSizes.unk0;
|
||||
for (auto& path : paths) {
|
||||
if (i >= ARRAY_COUNT(track->Props.PathTable2)) {
|
||||
SPDLOG_INFO(" The game can only import 5 paths. Found more than 5. Skipping the rest");
|
||||
break; // Only 5 paths allowed. 4 track, 1 vehicle
|
||||
}
|
||||
ptr[i] = path.size();
|
||||
track->Props.PathTable2[i] = (TrackPathPoint*) path.data();
|
||||
SPDLOG_INFO(" Added path {}", i);
|
||||
|
||||
i += 1;
|
||||
}
|
||||
gVehiclePathSize = track->Props.PathSizes.unk0; // This is likely incorrect.
|
||||
SPDLOG_INFO("[SceneManager] [LoadPaths] Path Loading Complete!");
|
||||
}
|
||||
|
||||
void LoadTrackInfoData(TrackInfo& info, nlohmann::json& data) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace Editor {
|
||||
void SaveLevel(Track* track);
|
||||
void SaveLevel(Track* track, const TrackInfo* info);
|
||||
void LoadTrackDataFromJson(Track* track, const std::string& trackPath);
|
||||
void LoadTrackInfo(TrackInfo& info, std::shared_ptr<Ship::Archive> archive, std::string sceneFile);
|
||||
void Load_AddStaticMeshActor(const nlohmann::json& actorJson);
|
||||
|
|
|
|||
|
|
@ -352,6 +352,7 @@ bool IsTriangleWindingInverted() {
|
|||
|
||||
|
||||
Track::Track() {
|
||||
Props.SetText(Props.ResourceName, "mod:blank_track", sizeof(Props.ResourceName));
|
||||
Props.SetText(Props.Name, "Blank Track", sizeof(Props.Name));
|
||||
Props.SetText(Props.DebugName, "blnktrck", sizeof(Props.DebugName));
|
||||
Props.SetText(Props.TrackLength, "100m", sizeof(Props.TrackLength));
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace Editor {
|
|||
// Save button
|
||||
if (ImGui::Button(ICON_FA_FLOPPY_O, ImVec2(50, 25))) {
|
||||
if (gEditor.IsPaused()) {
|
||||
SaveLevel(GetWorld()->GetTrack());
|
||||
SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
|
||||
} else {
|
||||
printf("[Editor] Cannot save during simulation\n Please switch back to edit mode!\n\n");
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ namespace Editor {
|
|||
ImGui::PushStyleColor(ImGuiCol_Button, defaultColor);
|
||||
if (ImGui::Button(gEditor.IsPaused() ? ICON_FA_PLAY : ICON_FA_STOP, ImVec2(50, 25))) {
|
||||
if (gEditor.IsPaused()) {
|
||||
SaveLevel(GetWorld()->GetTrack());
|
||||
SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
|
||||
CVarSetInteger("gFreecam", false);
|
||||
CM_SetFreeCamera(false);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue