From 3e94ecb3dac5003a3d58210ed1a4d1f1cb2083d1 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 12 Nov 2024 22:43:32 +0100 Subject: add script unit tests + major refactoring --- src/crepe/api/Animator.cpp | 4 ++-- src/crepe/api/Animator.h | 3 ++- src/crepe/api/BehaviorScript.cpp | 4 ++++ src/crepe/api/BehaviorScript.h | 20 ++++++++++++++++++-- src/crepe/api/BehaviorScript.hpp | 4 ++-- src/crepe/api/CMakeLists.txt | 10 +++++----- src/crepe/api/Camera.cpp | 7 ++----- src/crepe/api/Camera.h | 2 +- src/crepe/api/GameObject.cpp | 9 +++++---- src/crepe/api/GameObject.h | 17 ++++++++++++----- src/crepe/api/GameObject.hpp | 2 +- src/crepe/api/Metadata.cpp | 4 ++-- src/crepe/api/Metadata.h | 2 +- src/crepe/api/ParticleEmitter.cpp | 4 ++-- src/crepe/api/ParticleEmitter.h | 2 +- src/crepe/api/Rigidbody.cpp | 4 ++-- src/crepe/api/Rigidbody.h | 2 +- src/crepe/api/Script.cpp | 1 + src/crepe/api/Script.h | 15 ++++++++++++--- src/crepe/api/Script.hpp | 6 ++++-- src/crepe/api/Sprite.cpp | 4 ++-- src/crepe/api/Sprite.h | 2 +- src/crepe/api/Transform.cpp | 4 ++-- src/crepe/api/Transform.h | 2 +- 24 files changed, 86 insertions(+), 48 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 58fee2a..ad60981 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -9,8 +9,8 @@ using namespace crepe; -Animator::Animator(uint32_t id, Sprite & ss, int row, int col, int col_animator) - : Component(id), +Animator::Animator(const Component::Data & data, Sprite & ss, int row, int col, int col_animator) + : Component(data), spritesheet(ss), row(row), col(col) { diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index def0240..f66dc1a 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -6,6 +6,7 @@ #include "Sprite.h" namespace crepe { + class AnimatorSystem; class SDLContext; @@ -35,7 +36,7 @@ public: * * This constructor sets up the Animator with the given parameters, and initializes the animation system. */ - Animator(uint32_t id, Sprite & spritesheet, int row, int col, + Animator(const Component::Data & data, Sprite & spritesheet, int row, int col, int col_animate); ~Animator(); // dbg_trace diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index e69de29..ce1cfde 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -0,0 +1,4 @@ +#include "BehaviorScript.h" + +using namespace crepe; + diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 6b1fec7..8d21a72 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -12,19 +12,35 @@ class Script; class BehaviorScript : public Component { protected: - friend class crepe::ComponentManager; using Component::Component; + //! Only ComponentManager is allowed to instantiate BehaviorScript + friend class ComponentManager; public: virtual ~BehaviorScript() = default; public: + /** + * \brief Set the concrete script of this component + * + * \tparam T Concrete script type (derived from \c crepe::Script) + * + * \returns Reference to BehaviorScript component (`*this`) + */ template BehaviorScript & set_script(); protected: - friend class crepe::ScriptSystem; + //! ScriptSystem needs direct access to the script instance + friend class ScriptSystem; + //! Flag to indicate if script->init() has been called already + bool initialized = false; std::unique_ptr