Skip to content

Commit

Permalink
chore: move serialization utils to tool plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
luishfonseca committed Sep 26, 2023
1 parent a110a17 commit 4a79a6b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 87 deletions.
1 change: 0 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ set(CUBOS_CORE_SOURCE
"src/cubos/core/al/oal_audio_device.hpp"

"src/cubos/core/ui/imgui.cpp"
"src/cubos/core/ui/serialization.cpp"

"src/cubos/core/ecs/entity_manager.cpp"
"src/cubos/core/ecs/component_manager.cpp"
Expand Down
1 change: 1 addition & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(CUBOS_ENGINE_SOURCE

"src/cubos/engine/imgui/plugin.cpp"

"src/cubos/engine/tools/utils/serialization.cpp"
"src/cubos/engine/tools/asset_explorer/plugin.cpp"
"src/cubos/engine/tools/settings_inspector/plugin.cpp"
"src/cubos/engine/tools/entity_selector/plugin.cpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/// @dir
/// @brief @ref utils-tool-plugin plugin directory.

/// @file
/// @brief Functions for showing and editing serializable objects in the UI.
/// @ingroup core-ui
/// @ingroup utils-tool-plugin

#pragma once

#include <cubos/core/data/package.hpp>

namespace cubos::core::ui
using Package = cubos::core::data::Package;

namespace cubos::engine::tools
{
/// @brief Shows a packaged object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -16,8 +21,8 @@ namespace cubos::core::ui
///
/// @param pkg Packaged object to show.
/// @param name Name of the object.
/// @ingroup core-ui
void showPackage(const data::Package& pkg, const std::string& name);
/// @ingroup utils-tool-plugin
void showPackage(const Package& pkg, const std::string& name);

/// @brief Shows a packaged object's properties in the UI, allowing the user to edit the
/// object. Should be called inside a `ImGui::BeginTable(3)` and `ImGui::EndTable()` block.
Expand All @@ -29,8 +34,8 @@ namespace cubos::core::ui
/// @param pkg Packaged object to edit.
/// @param name Name of the object.
/// @return True if the object was modified, false otherwise.
/// @ingroup core-ui
bool editPackage(data::Package& pkg, const std::string& name);
/// @ingroup utils-tool-plugin
bool editPackage(Package& pkg, const std::string& name);

/// @brief Shows a serializable object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -40,11 +45,11 @@ namespace cubos::core::ui
/// @tparam T Type of the serializable object.
/// @param object Object to show.
/// @param name Name of the object.
/// @ingroup core-ui
/// @ingroup utils-tool-plugin
template <typename T>
inline void show(const T& object, const std::string& name)
{
auto pkg = data::Package::from(object);
auto pkg = Package::from(object);
showPackage(pkg, name);
}

Expand All @@ -58,11 +63,11 @@ namespace cubos::core::ui
/// @param object Object to edit.
/// @param name Name of the object.
/// @return True if the object was edited, false otherwise.
/// @ingroup core-ui
/// @ingroup utils-tool-plugin
template <typename T>
inline bool edit(T& object, const std::string& name)
{
auto pkg = data::Package::from(object);
auto pkg = Package::from(object);
if (editPackage(pkg, name))
{
pkg.into(object);
Expand All @@ -71,4 +76,4 @@ namespace cubos::core::ui

return false;
}
} // namespace cubos::core::ui
} // namespace cubos::engine::tools
6 changes: 2 additions & 4 deletions engine/src/cubos/engine/tools/entity_inspector/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include <imgui.h>

#include <cubos/core/ui/serialization.hpp>

#include <cubos/engine/imgui/plugin.hpp>
#include <cubos/engine/tools/entity_inspector/plugin.hpp>
#include <cubos/engine/tools/entity_selector/plugin.hpp>
#include <cubos/engine/tools/utils/serialization.hpp>

using cubos::core::data::Context;
using cubos::core::data::SerializationMap;
using cubos::core::ecs::Entity;
using cubos::core::ecs::World;
using cubos::core::ecs::Write;
using cubos::core::ui::editPackage;
using namespace cubos::engine;

static void inspectEntity(Write<World> world)
Expand All @@ -26,7 +24,7 @@ static void inspectEntity(Write<World> world)
if (!selection.isNull() && world->isAlive(selection))
{
auto pkg = world->pack(selection);
if (editPackage(pkg, std::to_string(selection.index)))
if (tools::editPackage(pkg, std::to_string(selection.index)))
{
world->unpack(selection, pkg);
}
Expand Down
5 changes: 2 additions & 3 deletions engine/src/cubos/engine/tools/settings_inspector/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <imgui.h>

#include <cubos/core/ui/serialization.hpp>

#include <cubos/engine/imgui/plugin.hpp>
#include <cubos/engine/settings/plugin.hpp>
#include <cubos/engine/tools/settings_inspector/plugin.hpp>
#include <cubos/engine/tools/utils/serialization.hpp>

using cubos::core::ecs::Write;

Expand All @@ -25,7 +24,7 @@ static void inspector(Write<Settings> settings)
ImGui::BeginTable("split", 2, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable);
for (auto& setting : map)
{
cubos::core::ui::edit(setting.second, setting.first);
tools::edit(setting.second, setting.first);
}
ImGui::EndTable();
}
Expand Down
Loading

0 comments on commit 4a79a6b

Please sign in to comment.