diff --git a/source/godot_tscn_format/lib/CMakeLists.txt b/source/godot_tscn_format/lib/CMakeLists.txt index 7970b44f7c..1a1b9a0446 100644 --- a/source/godot_tscn_format/lib/CMakeLists.txt +++ b/source/godot_tscn_format/lib/CMakeLists.txt @@ -8,7 +8,7 @@ target_sources(tactile-godot-tscn-format "src/gd3_document_converter.cpp" "src/gd3_scene_writer.cpp" "src/godot_scene_format.cpp" - "src/godot_tscn_format_plugin.cpp" + "src/godot_scene_format_plugin.cpp" PUBLIC FILE_SET "HEADERS" BASE_DIRS "inc" FILES "inc/tactile/godot_tscn_format/api.hpp" @@ -16,7 +16,7 @@ target_sources(tactile-godot-tscn-format "inc/tactile/godot_tscn_format/gd3_scene_writer.hpp" "inc/tactile/godot_tscn_format/gd3_types.hpp" "inc/tactile/godot_tscn_format/godot_scene_format.hpp" - "inc/tactile/godot_tscn_format/godot_tscn_format_plugin.hpp" + "inc/tactile/godot_tscn_format/godot_scene_format_plugin.hpp" ) tactile_prepare_target(tactile-godot-tscn-format) diff --git a/source/godot_tscn_format/lib/inc/tactile/godot_tscn_format/godot_tscn_format_plugin.hpp b/source/godot_tscn_format/lib/inc/tactile/godot_tscn_format/godot_scene_format_plugin.hpp similarity index 59% rename from source/godot_tscn_format/lib/inc/tactile/godot_tscn_format/godot_tscn_format_plugin.hpp rename to source/godot_tscn_format/lib/inc/tactile/godot_tscn_format/godot_scene_format_plugin.hpp index 944b9ee320..0728ca8c7d 100644 --- a/source/godot_tscn_format/lib/inc/tactile/godot_tscn_format/godot_tscn_format_plugin.hpp +++ b/source/godot_tscn_format/lib/inc/tactile/godot_tscn_format/godot_scene_format_plugin.hpp @@ -2,13 +2,16 @@ #pragma once +#include // unique_ptr + #include "tactile/base/prelude.hpp" #include "tactile/godot_tscn_format/api.hpp" +#include "tactile/godot_tscn_format/godot_scene_format.hpp" #include "tactile/runtime/plugin.hpp" -namespace tactile { +namespace tactile::godot { -class TACTILE_GODOT_API GodotTscnFormatPlugin final : public IPlugin +class TACTILE_GODOT_API GodotSceneFormatPlugin final : public IPlugin { public: void load(IRuntime* runtime) override; @@ -16,7 +19,8 @@ class TACTILE_GODOT_API GodotTscnFormatPlugin final : public IPlugin void unload() override; private: - IRuntime* mRuntime {}; + IRuntime* m_runtime {}; + std::unique_ptr m_format {}; }; extern "C" @@ -25,4 +29,4 @@ extern "C" TACTILE_GODOT_API void tactile_free_plugin(IPlugin* plugin); } -} // namespace tactile +} // namespace tactile::godot diff --git a/source/godot_tscn_format/lib/src/godot_scene_format_plugin.cpp b/source/godot_tscn_format/lib/src/godot_scene_format_plugin.cpp new file mode 100644 index 0000000000..94f759d2a2 --- /dev/null +++ b/source/godot_tscn_format/lib/src/godot_scene_format_plugin.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) + +#include "tactile/godot_tscn_format/godot_scene_format_plugin.hpp" + +#include // nothrow + +#include "tactile/base/runtime.hpp" +#include "tactile/runtime/logging.hpp" + +namespace tactile::godot { + +void GodotSceneFormatPlugin::load(IRuntime* runtime) +{ + log(LogLevel::kTrace, "Loading Godot TSCN format plugin"); + m_runtime = runtime; + + m_format = std::make_unique(m_runtime); + m_runtime->set_save_format(SaveFormatId::kGodotTscn, m_format.get()); +} + +void GodotSceneFormatPlugin::unload() +{ + log(LogLevel::kTrace, "Unloading Godot TSCN format plugin"); + + m_runtime->set_save_format(SaveFormatId::kGodotTscn, nullptr); + m_format.reset(); + + m_runtime = nullptr; +} + +auto tactile_make_plugin() -> IPlugin* +{ + return new (std::nothrow) GodotSceneFormatPlugin {}; +} + +void tactile_free_plugin(IPlugin* plugin) +{ + delete plugin; +} + +} // namespace tactile::godot diff --git a/source/godot_tscn_format/lib/src/godot_tscn_format_plugin.cpp b/source/godot_tscn_format/lib/src/godot_tscn_format_plugin.cpp deleted file mode 100644 index e9c58fea8e..0000000000 --- a/source/godot_tscn_format/lib/src/godot_tscn_format_plugin.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) - -#include "tactile/godot_tscn_format/godot_tscn_format_plugin.hpp" - -#include // nothrow - -#include "tactile/runtime/logging.hpp" - -namespace tactile { - -void GodotTscnFormatPlugin::load(IRuntime* runtime) -{ - log(LogLevel::kTrace, "Loading Godot TSCN format plugin"); - mRuntime = runtime; -} - -void GodotTscnFormatPlugin::unload() -{ - log(LogLevel::kTrace, "Unloading Godot TSCN format plugin"); - mRuntime = nullptr; -} - -auto tactile_make_plugin() -> IPlugin* -{ - return new (std::nothrow) GodotTscnFormatPlugin {}; -} - -void tactile_free_plugin(IPlugin* plugin) -{ - delete plugin; -} - -} // namespace tactile