aboutsummaryrefslogtreecommitdiff
path: root/source/30-game/Level.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/30-game/Level.cpp')
-rw-r--r--source/30-game/Level.cpp65
1 files changed, 59 insertions, 6 deletions
diff --git a/source/30-game/Level.cpp b/source/30-game/Level.cpp
index 5881084..076e5d5 100644
--- a/source/30-game/Level.cpp
+++ b/source/30-game/Level.cpp
@@ -1,21 +1,24 @@
#include "Level.hpp"
#include "AppConfig.hpp"
-#include "PodVector.hpp"
-#include "RapidJsonHelper.hpp"
-#include "ScopeGuard.hpp"
-#include "Utils.hpp"
+#include <PodVector.hpp>
+#include <RapidJsonHelper.hpp>
+#include <ScopeGuard.hpp>
+#include <Utils.hpp>
+
+#include <imgui.h>
#include <rapidjson/document.h>
#include <rapidjson/filereadstream.h>
#include <rapidjson/filewritestream.h>
-#include <rapidjson/writer.h>
+#include <rapidjson/prettywriter.h>
#include <cstdio>
#include <filesystem>
using namespace std::literals;
namespace fs = std::filesystem;
+constexpr auto kParentToRootObject = std::numeric_limits<size_t>::max();
constexpr auto kInvalidEntryId = std::numeric_limits<size_t>::max();
struct Level::InstanciationEntry {
@@ -29,6 +32,23 @@ Level::Level() = default;
Level::~Level() = default;
void Level::Instanciate(GameObject* relRoot) const {
+ auto objectsLut = std::make_unique<GameObject*[]>(mEntries.size());
+ for (auto& entry : mEntries) {
+ GameObject* parent;
+ if (entry.parentId == kParentToRootObject) {
+ parent = relRoot;
+ } else {
+ parent = objectsLut[entry.parentId];
+ }
+
+ // TODO deser object
+ }
+}
+
+void Level::ShowInstanciationEntries(IEditor& editor) {
+ for (auto& entry : mEntries) {
+ // TODO
+ }
}
void LevelManager::DiscoverFilesDesignatedLocation() {
@@ -92,6 +112,7 @@ Level* LevelManager::LoadLevel(const Uid& uid) {
ldObj.level.Attach(level = new Level());
level->mMan = this;
+ level->mUid = uid;
#if defined(BRUSSEL_DEV_ENV)
BRUSSEL_JSON_GET_DEFAULT(root, "Name", std::string, ldObj.name, BRUSSEL_DEF_LEVEL_NAME);
@@ -123,8 +144,9 @@ void LevelManager::PrepareLevel(const Uid& uid) {
}
LevelManager::LoadableObject& LevelManager::AddLevel(const Uid& uid) {
- auto&& [iter, inserted] = mObjByUid.try_emplace(uid, LoadableObject{});
+ auto&& [iter, inserted] = mObjByUid.try_emplace(uid);
auto& ldObj = iter->second;
+ ldObj.level->mUid = uid;
#if defined(BRUSSEL_DEV_ENV)
ldObj.name = BRUSSEL_DEF_LEVEL_NAME;
ldObj.description = BRUSSEL_DEF_LEVEL_DESC;
@@ -132,6 +154,37 @@ LevelManager::LoadableObject& LevelManager::AddLevel(const Uid& uid) {
return ldObj;
}
+void LevelManager::SaveLevel(const Uid& uid) const {
+ auto iter = mObjByUid.find(uid);
+ if (iter == mObjByUid.end()) return;
+ auto& obj = iter->second;
+
+ SaveLevelImpl(obj, obj.filePath);
+}
+
+void LevelManager::SaveLevel(const Uid& uid, const std::filesystem::path& path) const {
+ auto iter = mObjByUid.find(uid);
+ if (iter == mObjByUid.end()) return;
+ auto& obj = iter->second;
+
+ SaveLevelImpl(obj, path);
+}
+
+void LevelManager::SaveLevelImpl(const LoadableObject& obj, const std::filesystem::path& path) const {
+ rapidjson::Document root;
+
+ // TODO
+
+ auto file = Utils::OpenCstdioFile(path, Utils::WriteTruncate);
+ if (!file) return;
+ DEFER { fclose(file); };
+
+ char writerBuffer[65536];
+ rapidjson::FileWriteStream stream(file, writerBuffer, sizeof(writerBuffer));
+ rapidjson::Writer<rapidjson::FileWriteStream> writer(stream);
+ root.Accept(writer);
+}
+
LevelWrapperObject::LevelWrapperObject(GameWorld* world)
: GameObject(KD_LevelWrapper, world) //
{