mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-05-23 06:54:37 -04:00
Fix editor loading and finishline duplication (#653)
* Fix editor loading and finishline duplication * Update SceneManager.cpp
This commit is contained in:
@@ -81,11 +81,12 @@ void RaceManager::BeginPlay() {
|
||||
if ((gGamestate != CREDITS_SEQUENCE) && (gModeSelection != BATTLE)) {
|
||||
if (track->bSpawnFinishline) {
|
||||
if (track->FinishlineSpawnPoint.has_value()) {
|
||||
AFinishline::Spawn(track->FinishlineSpawnPoint.value(), IRotator(0, 0, 0));
|
||||
AFinishline* finishline = AFinishline::Spawn(track->FinishlineSpawnPoint.value(), IRotator(0, 0, 0));
|
||||
finishline->bIsFinishline = true;
|
||||
} else {
|
||||
AFinishline::Spawn();
|
||||
AFinishline* finishline = AFinishline::Spawn();
|
||||
finishline->bIsFinishline = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
gEditor.AddLight("Sun", nullptr, D_800DC610[1].l->l.dir);
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
virtual void Collision(Player* player, AActor* actor) override;
|
||||
virtual bool IsMod() override;
|
||||
|
||||
bool bIsFinishline = false;
|
||||
|
||||
static size_t _count;
|
||||
bool PickedUp = false;
|
||||
uint32_t Timer = 0;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "engine/vehicles/Train.h"
|
||||
|
||||
#include "engine/actors/Finishline.h"
|
||||
#include "engine/objects/Object.h"
|
||||
#include "engine/objects/Thwomp.h"
|
||||
#include "engine/objects/Snowman.h"
|
||||
@@ -86,15 +87,11 @@ namespace TrackEditor {
|
||||
|
||||
std::string sceneFile = info->Path + "/scene.json";
|
||||
|
||||
Ship::ResourceIdentifier id(sceneFile, 0, track->Archive);
|
||||
// Write file to disk
|
||||
bool wrote = GameEngine::Instance->context->GetResourceManager()->GetArchiveManager()->WriteFile(track->Archive, sceneFile, bytes);
|
||||
if (wrote) {
|
||||
// Tell the cache this file needs to be reloaded
|
||||
auto resource = GameEngine::Instance->context->GetResourceManager()->GetCachedResource(sceneFile);
|
||||
if (resource) {
|
||||
resource->Dirty();
|
||||
}
|
||||
} else {
|
||||
auto rm = GameEngine::Instance->context->GetResourceManager();
|
||||
bool wrote = rm->WriteResource(id, bytes, true);
|
||||
if (!wrote) {
|
||||
SPDLOG_INFO("[SceneManager] [SaveLevel] Failed to write scene file!");
|
||||
}
|
||||
} catch (const nlohmann::json::exception& e) {
|
||||
@@ -129,8 +126,9 @@ namespace TrackEditor {
|
||||
initData->ResourceVersion = 0;
|
||||
|
||||
// Load the scene file and return the json data
|
||||
Ship::ResourceIdentifier id(sceneFile, 0, track->Archive);
|
||||
nlohmann::json data = std::static_pointer_cast<Ship::Json>(
|
||||
GameEngine::Instance->context->GetResourceManager()->LoadResource(sceneFile, true, initData))->Data;
|
||||
GameEngine::Instance->context->GetResourceManager()->LoadResource(id, true, initData))->Data;
|
||||
|
||||
// Check that the data is valid
|
||||
if (data.is_null() || !data.is_object() || data.empty()) {
|
||||
@@ -169,8 +167,9 @@ namespace TrackEditor {
|
||||
initData->ResourceVersion = 0;
|
||||
|
||||
// Load the scene file and return the json data
|
||||
Ship::ResourceIdentifier id(sceneFile, 0, archive);
|
||||
nlohmann::json data = std::static_pointer_cast<Ship::Json>(
|
||||
GameEngine::Instance->context->GetResourceManager()->LoadResource(sceneFile, true, initData))->Data;
|
||||
GameEngine::Instance->context->GetResourceManager()->LoadResource(id, true, initData))->Data;
|
||||
|
||||
// Check that the data is valid
|
||||
if (data.is_null() || !data.is_object() || data.empty()) {
|
||||
@@ -279,6 +278,11 @@ namespace TrackEditor {
|
||||
if (!alreadyProcessed) {
|
||||
actor->SetSpawnParams(params);
|
||||
if (!params.Name.empty()) {
|
||||
if (AFinishline* finishline = dynamic_cast<AFinishline*>(actor.get())) {
|
||||
if (finishline->bIsFinishline == true) {
|
||||
continue; // Do not add the default spawn finishline
|
||||
}
|
||||
}
|
||||
actorList.push_back(params.to_json());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
extern "C" {
|
||||
#include "code_800029B0.h"
|
||||
#include "code_80057C60.h"
|
||||
#include "actors.h"
|
||||
}
|
||||
|
||||
namespace TrackEditor {
|
||||
@@ -146,6 +147,14 @@ namespace TrackEditor {
|
||||
TrackBrowser::Instance->Refresh(gTrackRegistry);
|
||||
CVarSetInteger("gFreecam", false);
|
||||
CM_SetFreeCamera(false);
|
||||
|
||||
// Reload scene file
|
||||
const TrackInfo* info = gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName);
|
||||
if (info) {
|
||||
TrackEditor::LoadTrackDataFromJson(GetWorld()->GetTrack(), info->Path);
|
||||
} else {
|
||||
printf("[Tools.cpp] Failed load scenefile, TrackInfo nullptr\n");
|
||||
}
|
||||
} else {
|
||||
CM_ResetAudio();
|
||||
CVarSetInteger("gFreecam", true);
|
||||
@@ -226,6 +235,8 @@ namespace TrackEditor {
|
||||
// Defer deletion until race_logic_loop
|
||||
bCleanWorld = true;
|
||||
gEditor.ResetGizmo();
|
||||
destroy_all_actors();
|
||||
GetWorld()->GetTrack()->SpawnList.clear();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
Reference in New Issue
Block a user