3#include "spark/core/Application.h"
4#include "spark/core/Component.h"
5#include "spark/core/GameObject.h"
6#include "spark/core/Scene.h"
7#include "spark/core/components/Circle.h"
8#include "spark/core/components/Collider.h"
9#include "spark/core/components/Image.h"
10#include "spark/core/components/Rectangle.h"
11#include "spark/core/components/Text.h"
12#include "spark/core/components/Transform.h"
14#include "spark/math/Vector2.h"
16template <
typename SerializerType>
17struct experimental::ser::SerializerScheme<SerializerType, std::filesystem::path>
19 static void serialize(SerializerType& serializer,
const std::filesystem::path& obj)
21 serializer << obj.generic_string();
24 static void deserialize(SerializerType& deserializer, std::filesystem::path& obj)
32template <
typename SerializerType,
typename T>
33struct experimental::ser::SerializerScheme<SerializerType, std::optional<T>>
35 static void serialize(SerializerType& serializer,
const std::optional<T>& obj)
37 serializer << obj.has_value();
39 serializer << obj.value();
42 static void deserialize(SerializerType& deserializer, std::optional<T>& obj)
44 bool has_value =
false;
45 deserializer >> has_value;
49 deserializer >> value;
57template <
typename SerializerType,
typename T>
58struct experimental::ser::SerializerScheme<SerializerType, spark::math::Vector2<T>>
68 deserializer >> obj.x;
69 deserializer >> obj.y;
73template <
typename SerializerType,
typename T>
74struct experimental::ser::SerializerScheme<SerializerType, spark::math::Rectangle<T>>
78 serializer << obj.position;
79 serializer << obj.extent;
84 deserializer >> obj.position;
85 deserializer >> obj.extent;
100template <
typename SerializerType>
101struct experimental::ser::SerializerScheme<SerializerType, spark::core::GameObject>
108 for (
const auto* component : obj.
components())
110 serializer << component->rttiInstance().className();
114 serializer << obj.children().size();
115 for (
const auto* child : obj.children())
117 serializer << child->rttiInstance().className();
118 serializer << child->name();
127 std::size_t components_count;
128 deserializer >> components_count;
129 for (std::size_t i = 0; i < components_count; ++i)
132 deserializer >> type;
137 component = it->second.first;
147 std::size_t children_count;
148 deserializer >> children_count;
150 for (std::size_t i = 0; i < children_count; ++i)
152 std::string type, name;
153 deserializer >> type;
154 deserializer >> name;
158 auto children = obj.children();
159 if (
auto it = std::ranges::find_if(children,
163 }); it != children.end())
173template <
typename SerializerType>
174struct experimental::ser::SerializerScheme<SerializerType, spark::core::Scene>
178 serializer << *obj.m_root;
179 serializer << obj.m_isLoaded;
184 SPARK_ASSERT(obj.m_root !=
nullptr &&
"Root GameObject must be set before deserialization")
186 deserializer >> *obj.m_root;
187 deserializer >> obj.m_isLoaded;
static Application * Instance()
Gets the instance of the application.
Definition Application.cpp:53
Registries & registries()
Gets a reference to the registries for the application.
Definition Application.cpp:131
A component that can be attached to a GameObject to provide additional functionality.
Definition Component.h:20
A GameObject is any object in the game. It contains a list of components that provides functionality ...
Definition GameObject.h:26
const std::string & name() const
Gets the name of the GameObject.
Definition GameObject.cpp:58
void addComponent(Component *component, bool managed=false)
Adds a component to the GameObject.
Definition GameObject.cpp:68
bool isShown
A boolean indicating if the GameObject is shown in the scene.
Definition GameObject.h:195
std::vector< Component * > components() const
Gets all the components for this GameObject.
Definition GameObject.cpp:87
A simple component to render a circle.
Definition Circle.h:15
A component representing a square collider.
Definition Collider.h:22
A square collider that moves and checks for collisions with other colliders.
Definition Collider.h:88
A simple component to render an image.
Definition Image.h:13
A simple component to render a square/rectangle.
Definition Rectangle.h:16
A square collider that does not move and is only used for collision detection.
Definition Collider.h:73
Represents a rectangle in 2D space.
Definition Rectangle.h:15
A vector with two components.
Definition Vector2.h:13
BasePtr create(const Key &key, Args &&... args) const
Creates an object of type BaseType. Throws an exception if the type is not registered.
Definition Factory.h:21
virtual RttiBase & rttiInstance() const =0
static RttiBase * Get(const std::string &class_name)
Gets an RTTI instance by class name.
Definition RttiDatabase.cpp:5