feat: add scene loading imgui testing things
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <destrum/Components/Physics/Rigidbody.h>
|
||||
#include <destrum/Components/Physics/BoxCollider.h>
|
||||
#include <destrum/Scene/Scene.h>
|
||||
#include <destrum/Serialization/SceneSerializer.h>
|
||||
|
||||
#include "destrum/Components/MeshRendererComponent.h"
|
||||
#include "destrum/Components/Rotator.h"
|
||||
@@ -17,12 +18,27 @@
|
||||
|
||||
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "destrum/Components/Physics/SphereCollider.h"
|
||||
#include "destrum/Util/ModelDocUtils.h"
|
||||
|
||||
namespace {
|
||||
std::filesystem::path ResolveScenePath(std::string_view value) {
|
||||
if (value.empty()) {
|
||||
throw std::invalid_argument("Scene path cannot be empty");
|
||||
}
|
||||
|
||||
if (value.find("://") != std::string_view::npos) {
|
||||
return AssetFS::GetInstance().GetFullPath(value);
|
||||
}
|
||||
|
||||
return std::filesystem::path{value};
|
||||
}
|
||||
}
|
||||
|
||||
LightKeeper::LightKeeper() : App()
|
||||
{
|
||||
@@ -478,6 +494,66 @@ void LightKeeper::customUpdate(float dt)
|
||||
SceneManager::GetInstance().GetCurrentScene().GetPhysics().RefreshGameObject(*sphere);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Scene Debug");
|
||||
ImGui::InputText("Scene path", scenePath, sizeof(scenePath));
|
||||
ImGui::InputText("New scene name", newSceneName, sizeof(newSceneName));
|
||||
|
||||
if (ImGui::Button("Save Current Scene")) {
|
||||
try {
|
||||
const auto path = ResolveScenePath(scenePath);
|
||||
const auto parent = path.parent_path();
|
||||
if (!parent.empty()) {
|
||||
std::filesystem::create_directories(parent);
|
||||
}
|
||||
|
||||
if (SceneSerializer::Save(
|
||||
SceneManager::GetInstance().GetCurrentScene(),
|
||||
path)) {
|
||||
sceneStatus = "Saved scene to " + path.string();
|
||||
} else {
|
||||
sceneStatus = "Failed to save scene to " + path.string();
|
||||
}
|
||||
} catch (const std::exception& exception) {
|
||||
sceneStatus = std::string{"Save failed: "} + exception.what();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Load Scene")) {
|
||||
try {
|
||||
const auto path = ResolveScenePath(scenePath);
|
||||
if (SceneSerializer::Load(
|
||||
SceneManager::GetInstance().GetCurrentScene(),
|
||||
path)) {
|
||||
sceneStatus = "Loaded scene from " + path.string();
|
||||
} else {
|
||||
sceneStatus = "Failed to load scene from " + path.string();
|
||||
}
|
||||
} catch (const std::exception& exception) {
|
||||
sceneStatus = std::string{"Load failed: "} + exception.what();
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Button("New Empty Scene")) {
|
||||
try {
|
||||
const std::string name = newSceneName[0] != '\0'
|
||||
? newSceneName
|
||||
: "EmptyScene";
|
||||
auto& sceneManager = SceneManager::GetInstance();
|
||||
const int newSceneIndex = sceneManager.GetSceneCount();
|
||||
sceneManager.CreateScene(name);
|
||||
sceneManager.SwitchScene(newSceneIndex);
|
||||
sceneStatus = "Created and switched to scene '" + name + "'";
|
||||
} catch (const std::exception& exception) {
|
||||
sceneStatus = std::string{"New scene failed: "} + exception.what();
|
||||
}
|
||||
}
|
||||
|
||||
if (!sceneStatus.empty()) {
|
||||
ImGui::TextWrapped("%s", sceneStatus.c_str());
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void LightKeeper::customDraw()
|
||||
|
||||
Reference in New Issue
Block a user