aboutsummaryrefslogtreecommitdiff
path: root/source/GameObject.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-05-22 23:05:03 -0700
committerrtk0c <[email protected]>2022-05-22 23:05:03 -0700
commit123f741e3f5374b93ac39887b62bfa0d66762ae2 (patch)
treecedbc4b2dd87e2caadfde48a0c12a0336672bdd3 /source/GameObject.cpp
parentc568f0a8c9f0aef00c770b494ee1ff3a89ab48de (diff)
Changeset: 36 Add basic machinery for levels (no saving/loading yet)
Diffstat (limited to 'source/GameObject.cpp')
-rw-r--r--source/GameObject.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/source/GameObject.cpp b/source/GameObject.cpp
index ce515bd..8bb3ec7 100644
--- a/source/GameObject.cpp
+++ b/source/GameObject.cpp
@@ -1,15 +1,29 @@
#include "GameObject.hpp"
+#include "Level.hpp"
#include "Player.hpp"
+#include "RapidJsonHelper.hpp"
#include "SceneThings.hpp"
#include "World.hpp"
+#include <rapidjson/document.h>
#include <string_view>
#include <utility>
using namespace std::literals;
namespace ProjectBrussel_UNITY_ID {
+GameObject* CreateGameObject(GameObject::Kind kind, GameWorld* world) {
+ switch (kind) {
+ case GameObject::KD_Generic: return new GameObject(world);
+ case GameObject::KD_SimpleGeometry: return new SimpleGeometryObject(world);
+ case GameObject::KD_Building: return new BuildingObject(world);
+ case GameObject::KD_LevelWrapper: return new LevelWrapperObject(world);
+ default: break;
+ }
+ return nullptr;
+}
+
bool ValidateGameObjectChild(GameObject* parent, GameObject* child) {
return parent->GetWorld() == child->GetWorld();
}
@@ -187,6 +201,41 @@ void GameObject::Resleep() {
void GameObject::Update() {
}
+rapidjson::Value GameObject::Serialize(GameObject* obj, rapidjson::Document& root) {
+ rapidjson::Value result(rapidjson::kObjectType);
+
+ result.AddMember("Type", rapidjson::StringRef(ToString(obj->GetKind())), root.GetAllocator());
+
+ rapidjson::Value rvValue(rapidjson::kObjectType);
+ obj->WriteSaveFormat(rvValue, root);
+ result.AddMember("Value", rvValue, root.GetAllocator());
+
+ return result;
+}
+
+std::unique_ptr<GameObject> GameObject::Deserialize(const rapidjson::Value& value, GameWorld* world) {
+ using namespace ProjectBrussel_UNITY_ID;
+
+ auto rvType = rapidjson::GetProperty(value, rapidjson::kStringType, "Type"sv);
+ if (!rvType) return nullptr;
+
+ auto rvValue = rapidjson::GetProperty(value, rapidjson::kObjectType, "Value"sv);
+ if (!rvValue) return nullptr;
+
+ auto kind = FromString(rapidjson::AsStringView(*rvType));
+ auto obj = std::unique_ptr<GameObject>(CreateGameObject(kind, world));
+ if (!obj) return nullptr;
+ obj->ReadSaveFormat(*rvValue);
+
+ return obj;
+}
+
+void GameObject::ReadSaveFormat(const rapidjson::Value& value) {
+}
+
+void GameObject::WriteSaveFormat(rapidjson::Value& value, rapidjson::Document& root) {
+}
+
void GameObject::SetParent(GameObject* parent) {
if (mParent != parent) {
mParent = parent;