8#include <nlohmann/json.hpp>
10#include "galaxy/core/ServiceLocator.hpp"
15#include "galaxy/scripting/JSON.hpp"
27 : m_rendersystem_index {0}
46 m_scenes[hash] = std::make_unique<Scene>(name);
50 GALAXY_LOG(GALAXY_WARNING,
"Tried to add a duplicate scene '{0}'.", name);
92 const auto data = core::ServiceLocator<fs::VirtualFileSystem>::ref().read(appdata_file);
95 const auto decoded_zlib = math::decode_zlib(data);
96 if (!decoded_zlib.empty())
100 if (!decoded_base64.empty())
102 const auto parsed = nlohmann::json::parse(decoded_base64);
133 if (!json::write(file, json))
201 nlohmann::json json =
"{\"scenes\":{}}"_json;
203 for (
auto& [name, scene] :
m_scenes)
205 json[
"scenes"][scene->m_name] = scene->serialize();
220 const auto& scenes = json.at(
"scenes");
223 for (
const auto& [name, data] : scenes.items())
225 auto scene =
add(name);
228 scene->deserialize(data);
232 if (json.contains(
"current"))
#define GALAXY_LOG(level, msg,...)
entt::registry m_entt
Scene entities.
core::Registry m_registry
Map entities.
map::Map * get_active() const
Get currently active map.
void create_system(Args &&... args)
Add a system to the manager.
void only_update_rendering()
Only update rendering.
void save_app(const std::string &file)
Save all active scenes and sub data within those scenes.
bool has(const std::string &name)
Does a scene exist.
scene::Scene * current() const
Get current scene.
virtual ~SceneManager()
Destructor.
std::size_t m_rendersystem_index
Rendersystem index.
SystemContainer m_systems
Stores systems.
void clear()
Deletes all scene data.
void deserialize(const nlohmann::json &json) override
Deserializes from object.
void update()
Handle events and update logic.
void render()
Handle rendering.
nlohmann::json serialize() override
Serializes object.
void load_app(const std::string &appdata_file)
Load app data file into scene manager.
Scene * get(const std::string &name)
Get a specific scene.
Scene * add(const std::string &name)
Add a new scene.
ankerl::unordered_dense::map< std::uint64_t, std::unique_ptr< Scene > > Map
void set_scene(const std::string &name)
Scene to set to currently active.
SceneManager()
Constructor.
void remove(const std::string &name)
Remove a specific scene.
bool empty() const
Are there any scenes.
const Map & map() const
Get all scenes.
scene::Scene * m_current
Current scene.
Represents a scene in a game. Like the menu, game, etc. Does not share resources.
map::World m_world
LDTK world.
virtual void render()
Render scene.
virtual void update()
Process events and updates.
std::string m_name
Scene name for debug purposes.
core::Registry m_registry
Entity data.
constexpr std::uint64_t fnv1a_64(const char *const str) noexcept
Convert string to 64bit hash.
std::string decode_base64(const std::string &input)
Decompresses string into Base64.