diff options
author | rtk0c <[email protected]> | 2022-06-03 22:58:28 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-03 22:58:28 -0700 |
commit | 8510a85f79f706b93982b4e398b187b5f77081dd (patch) | |
tree | 996c27f54f748d940f58454f7ef1e1570d1a31d5 /source/30-game/Level.cpp | |
parent | bd07ae3f4e1bcdedc3e373460671ca9713a03de5 (diff) |
Changeset: 61 [BUGGED] Move object kind enums to use generated ToString and FromStrong
The old mechanism rely on a specific prefix to Ires and GameObject string representations, but the generator currently leaves the enum value. Therefore all editor (e.g. drag & drop) and IO (e.g. ires loading) mechanisms are broken.
Diffstat (limited to 'source/30-game/Level.cpp')
-rw-r--r-- | source/30-game/Level.cpp | 65 |
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) // { |