diff --git a/CInterface/Battling/Battle.cpp b/CInterface/Battling/Battle.cpp index e55e6c8..be28c42 100644 --- a/CInterface/Battling/Battle.cpp +++ b/CInterface/Battling/Battle.cpp @@ -59,10 +59,10 @@ export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) { export BattleScript* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) { auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key)); - if (!v.has_value()) { + if (!v.HasValue()) { return nullptr; } - return v.value(); + return v.GetValue(); } export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) { Try(p->AddVolatileScript(ArbUt::StringView(key));) diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index 855511a..88c83f1 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -155,15 +155,15 @@ void Battle::ValidateBattleState() { } BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) { auto script = _volatile.Get(key); - if (script.has_value()) { - script.value()->Stack(); - return script.value(); + if (script.HasValue()) { + script.GetValue()->Stack(); + return script.GetValue(); } script = _library->LoadScript(ScriptCategory::Battle, key); - if (!script.has_value()) { + if (!script.HasValue()) { THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'."); } - return _volatile.Add(script.value().GetRaw()); + return _volatile.Add(script.GetValue()); } BattleScript* Battle::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); } void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); } diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index 2cb59d2..ec746cc 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -86,10 +86,10 @@ namespace CreatureLib::Battling { const ArbUt::UniquePtrList& GetParties() const noexcept { return _parties; } const ArbUt::UniquePtrList& GetSides() const noexcept { return _sides; } - std::optional> GetVolatileScript(const ArbUt::StringView& key) const { + ArbUt::OptionalBorrowedPtr GetVolatileScript(const ArbUt::StringView& key) const { return _volatile.Get(key); } - std::optional> GetVolatileScript(uint32_t keyHash) const noexcept { + ArbUt::OptionalBorrowedPtr GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); } BattleScript* AddVolatileScript(const ArbUt::StringView& key); diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index d8b11df..0291fbd 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -281,15 +281,15 @@ namespace CreatureLib::Battling { BattleScript* Creature::AddVolatileScript(const ArbUt::StringView& name) { auto script = _volatile.Get(name); - if (script.has_value()) { - script.value()->Stack(); - return script.value(); + if (script.HasValue()) { + script.GetValue()->Stack(); + return script.GetValue(); } script = this->_library->LoadScript(ScriptCategory::Creature, name); - if (!script.has_value()) { + if (!script.HasValue()) { THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'."); } - return _volatile.Add(script.value().GetRaw()); + return _volatile.Add(script.GetValue()); } BattleScript* Creature::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); } diff --git a/src/Battling/ScriptHandling/ScriptSet.hpp b/src/Battling/ScriptHandling/ScriptSet.hpp index 54e411e..f4d86f8 100644 --- a/src/Battling/ScriptHandling/ScriptSet.hpp +++ b/src/Battling/ScriptHandling/ScriptSet.hpp @@ -28,14 +28,14 @@ namespace CreatureLib::Battling { return script; } - std::optional> Get(const ArbUt::BasicStringView& key) const { + ArbUt::OptionalBorrowedPtr Get(const ArbUt::BasicStringView& key) const { return Get(key.GetHash()); } - std::optional> Get(uint32_t keyHash) const noexcept { + ArbUt::OptionalBorrowedPtr Get(uint32_t keyHash) const noexcept { auto v = _lookup.TryGet(keyHash); if (v.has_value()) { - return _scripts[v.value()]; + return _scripts[v.value()].GetRaw(); } return {}; }