From 949fc67831467c18982a358caab4b655fd6faba1 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 29 Oct 2021 21:31:01 +0200 Subject: [PATCH] Add support for saving and getting the owner of a script in script. Signed-off-by: Deukhoofd --- src/Battling/ScriptHandling/BattleScript.hpp | 6 +++++- tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp | 2 +- tests/BattleTests/ScriptTests/ScriptSetTests.cpp | 2 +- tests/BattleTests/ScriptTests/ScriptSourceTest.cpp | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index c966c95..11daf08 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -12,10 +12,14 @@ namespace CreatureLib::Battling { class Creature; class BattleScript { + ArbUt::OptionalBorrowedPtr _owner; + public: - BattleScript() = default; + BattleScript(ArbUt::OptionalBorrowedPtr owner) { _owner = owner; }; NO_COPY_OR_MOVE(BattleScript); + inline ArbUt::OptionalBorrowedPtr GetOwner() const noexcept { return _owner; } + virtual ~BattleScript() = default; virtual BattleScript* Clone() = 0; diff --git a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp index 61d6954..a966e7b 100644 --- a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp +++ b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp @@ -12,7 +12,7 @@ private: ArbUt::StringView _name; public: - explicit TestScript(const ArbUt::StringView& name) : _name(name){}; + explicit TestScript(const ArbUt::StringView& name) : BattleScript(nullptr), _name(name){}; const ArbUt::StringView& GetName() const noexcept override { return _name; } diff --git a/tests/BattleTests/ScriptTests/ScriptSetTests.cpp b/tests/BattleTests/ScriptTests/ScriptSetTests.cpp index adafdaf..9c48c9c 100644 --- a/tests/BattleTests/ScriptTests/ScriptSetTests.cpp +++ b/tests/BattleTests/ScriptTests/ScriptSetTests.cpp @@ -12,7 +12,7 @@ private: ArbUt::StringView _name; public: - explicit TestScript(const ArbUt::StringView& name) : _name(name){}; + explicit TestScript(const ArbUt::StringView& name) : BattleScript(nullptr), _name(name){}; const ArbUt::StringView& GetName() const noexcept override { return _name; } BattleScript* Clone() override { return new TestScript(_name); } diff --git a/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp b/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp index 2bb0eba..fe7466e 100644 --- a/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp +++ b/tests/BattleTests/ScriptTests/ScriptSourceTest.cpp @@ -11,7 +11,7 @@ private: ArbUt::StringView _name; public: - explicit TestScript(const ArbUt::StringView& name) : _name(name){}; + explicit TestScript(const ArbUt::StringView& name) : BattleScript(nullptr), _name(name){}; const ArbUt::StringView& GetName() const noexcept override { return _name; } void TestMethod(int& runCount) { runCount++; }