From 1ef50fd3a68d718e211ee995792752545fd318d5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 2 Jun 2020 15:03:31 +0200 Subject: [PATCH] Use unique pointers in scriptset. --- CInterface/Battling/Battle.cpp | 2 +- src/Battling/Models/Battle.cpp | 2 +- src/Battling/Models/Battle.hpp | 4 ++-- src/Battling/Models/Creature.cpp | 2 +- .../ScriptHandling/ScriptAggregator.hpp | 4 ++-- src/Battling/ScriptHandling/ScriptSet.hpp | 19 ++++++++----------- .../ScriptTests/ScriptSetTests.cpp | 14 +++++++------- 7 files changed, 22 insertions(+), 25 deletions(-) diff --git a/CInterface/Battling/Battle.cpp b/CInterface/Battling/Battle.cpp index 0a73868..85f1424 100644 --- a/CInterface/Battling/Battle.cpp +++ b/CInterface/Battling/Battle.cpp @@ -56,7 +56,7 @@ export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) { } export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) { - return p->GetVolatileScript(ConstString::GetHash(key)); + return p->GetVolatileScript(ConstString::GetHash(key)).GetRaw(); } export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) { Try(p->AddVolatileScript(ConstString(key));) diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index bed0e85..d7fa0d3 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -137,7 +137,7 @@ void Battle::AddVolatileScript(const ConstString& key) { ss << "Invalid volatile script requested for battle: '" << key.c_str() << "'."; throw CreatureException(ss.str()); } - return _volatile.Add(script); + return _volatile.Add(script.GetRaw()); } void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); } void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); } diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index e6b77e1..d701fa5 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -82,8 +82,8 @@ namespace CreatureLib::Battling { const ArbUt::UniquePtrList& GetParties() const noexcept { return _parties; } const ArbUt::UniquePtrList& GetSides() const noexcept { return _sides; } - Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); } - Script* GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); } + ArbUt::BorrowedPtr