When adding volatile script, return the script object.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
d6858c2d44
commit
bfe83ef271
|
@ -153,11 +153,11 @@ void Battle::ValidateBattleState() {
|
|||
this->_battleResult = BattleResult::Conclusive(winningSide);
|
||||
EndBattle();
|
||||
}
|
||||
void Battle::AddVolatileScript(const ArbUt::StringView& key) {
|
||||
BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) {
|
||||
auto script = _volatile.Get(key);
|
||||
if (script.has_value()) {
|
||||
script.value()->Stack();
|
||||
return;
|
||||
return script.value();
|
||||
}
|
||||
script = _library->LoadScript(ScriptCategory::Battle, key);
|
||||
if (!script.has_value()) {
|
||||
|
@ -165,6 +165,6 @@ void Battle::AddVolatileScript(const ArbUt::StringView& key) {
|
|||
}
|
||||
return _volatile.Add(script.value().GetRaw());
|
||||
}
|
||||
void 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::DisplayText(const ArbUt::StringView& text) { TriggerEventListener<DisplayTextEvent>(text); }
|
||||
|
|
|
@ -92,8 +92,8 @@ namespace CreatureLib::Battling {
|
|||
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetVolatileScript(uint32_t keyHash) const noexcept {
|
||||
return _volatile.Get(keyHash);
|
||||
}
|
||||
void AddVolatileScript(const ArbUt::StringView& key);
|
||||
void AddVolatileScript(BattleScript* script);
|
||||
BattleScript* AddVolatileScript(const ArbUt::StringView& key);
|
||||
BattleScript* AddVolatileScript(BattleScript* script);
|
||||
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
||||
void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); }
|
||||
void RemoveVolatileScript(BattleScript* script);
|
||||
|
|
|
@ -279,20 +279,20 @@ namespace CreatureLib::Battling {
|
|||
_heldItem = v.value();
|
||||
}
|
||||
|
||||
void Creature::AddVolatileScript(const ArbUt::StringView& name) {
|
||||
BattleScript* Creature::AddVolatileScript(const ArbUt::StringView& name) {
|
||||
auto script = _volatile.Get(name);
|
||||
if (script.has_value()) {
|
||||
script.value()->Stack();
|
||||
return;
|
||||
return script.value();
|
||||
}
|
||||
script = this->_library->LoadScript(ScriptCategory::Creature, name);
|
||||
if (!script.has_value()) {
|
||||
THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'.");
|
||||
}
|
||||
_volatile.Add(script.value().GetRaw());
|
||||
return _volatile.Add(script.value().GetRaw());
|
||||
}
|
||||
|
||||
void Creature::AddVolatileScript(BattleScript* script) { _volatile.Add(script); }
|
||||
BattleScript* Creature::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); }
|
||||
void Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
||||
void Creature::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }
|
||||
bool Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||
|
|
|
@ -134,8 +134,8 @@ namespace CreatureLib::Battling {
|
|||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
void ClearVolatileScripts();
|
||||
void AddVolatileScript(const ArbUt::StringView& name);
|
||||
void AddVolatileScript(BattleScript* script);
|
||||
BattleScript* AddVolatileScript(const ArbUt::StringView& name);
|
||||
BattleScript* AddVolatileScript(BattleScript* script);
|
||||
void RemoveVolatileScript(const ArbUt::BasicStringView& name);
|
||||
void RemoveVolatileScript(BattleScript* script);
|
||||
bool HasVolatileScript(const ArbUt::BasicStringView& name) const;
|
||||
|
|
|
@ -15,16 +15,17 @@ namespace CreatureLib::Battling {
|
|||
static constexpr size_t defaultCapacity = 8;
|
||||
ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){};
|
||||
|
||||
void Add(BattleScript* script) {
|
||||
BattleScript* Add(BattleScript* script) {
|
||||
auto v = _lookup.TryGet(script->GetName());
|
||||
if (v.has_value()) {
|
||||
_scripts[v.value()]->Stack();
|
||||
delete script;
|
||||
return;
|
||||
return _scripts[v.value()];
|
||||
}
|
||||
|
||||
_scripts.Append(script);
|
||||
_lookup.Insert(script->GetName(), _scripts.Count() - 1);
|
||||
return script;
|
||||
}
|
||||
|
||||
std::optional<ArbUt::BorrowedPtr<BattleScript>> Get(const ArbUt::BasicStringView& key) const {
|
||||
|
|
Loading…
Reference in New Issue