Fixes for ScriptSet throwing when adding a not yet found volatile script.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-03-27 20:20:49 +01:00
parent bfe83ef271
commit 1ddbfd2357
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 17 additions and 17 deletions

View File

@ -59,10 +59,10 @@ export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) {
export BattleScript* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) { export BattleScript* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key)); auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key));
if (!v.has_value()) { if (!v.HasValue()) {
return nullptr; return nullptr;
} }
return v.value(); return v.GetValue();
} }
export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) { export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) {
Try(p->AddVolatileScript(ArbUt::StringView(key));) Try(p->AddVolatileScript(ArbUt::StringView(key));)

View File

@ -155,15 +155,15 @@ void Battle::ValidateBattleState() {
} }
BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) { BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) {
auto script = _volatile.Get(key); auto script = _volatile.Get(key);
if (script.has_value()) { if (script.HasValue()) {
script.value()->Stack(); script.GetValue()->Stack();
return script.value(); return script.GetValue();
} }
script = _library->LoadScript(ScriptCategory::Battle, key); script = _library->LoadScript(ScriptCategory::Battle, key);
if (!script.has_value()) { if (!script.HasValue()) {
THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'."); 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); } BattleScript* Battle::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); }
void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); } void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }

View File

@ -86,10 +86,10 @@ namespace CreatureLib::Battling {
const ArbUt::UniquePtrList<BattleParty>& GetParties() const noexcept { return _parties; } const ArbUt::UniquePtrList<BattleParty>& GetParties() const noexcept { return _parties; }
const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; } const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; }
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetVolatileScript(const ArbUt::StringView& key) const { ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
return _volatile.Get(key); return _volatile.Get(key);
} }
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetVolatileScript(uint32_t keyHash) const noexcept { ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(uint32_t keyHash) const noexcept {
return _volatile.Get(keyHash); return _volatile.Get(keyHash);
} }
BattleScript* AddVolatileScript(const ArbUt::StringView& key); BattleScript* AddVolatileScript(const ArbUt::StringView& key);

View File

@ -281,15 +281,15 @@ namespace CreatureLib::Battling {
BattleScript* Creature::AddVolatileScript(const ArbUt::StringView& name) { BattleScript* Creature::AddVolatileScript(const ArbUt::StringView& name) {
auto script = _volatile.Get(name); auto script = _volatile.Get(name);
if (script.has_value()) { if (script.HasValue()) {
script.value()->Stack(); script.GetValue()->Stack();
return script.value(); return script.GetValue();
} }
script = this->_library->LoadScript(ScriptCategory::Creature, name); script = this->_library->LoadScript(ScriptCategory::Creature, name);
if (!script.has_value()) { if (!script.HasValue()) {
THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'."); 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); } BattleScript* Creature::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); }

View File

@ -28,14 +28,14 @@ namespace CreatureLib::Battling {
return script; return script;
} }
std::optional<ArbUt::BorrowedPtr<BattleScript>> Get(const ArbUt::BasicStringView& key) const { ArbUt::OptionalBorrowedPtr<BattleScript> Get(const ArbUt::BasicStringView& key) const {
return Get(key.GetHash()); return Get(key.GetHash());
} }
std::optional<ArbUt::BorrowedPtr<BattleScript>> Get(uint32_t keyHash) const noexcept { ArbUt::OptionalBorrowedPtr<BattleScript> Get(uint32_t keyHash) const noexcept {
auto v = _lookup.TryGet(keyHash); auto v = _lookup.TryGet(keyHash);
if (v.has_value()) { if (v.has_value()) {
return _scripts[v.value()]; return _scripts[v.value()].GetRaw();
} }
return {}; return {};
} }