Adds functions to add, remove, and get volatile scripts from a BattleSide.
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
47c3429295
commit
19375c2f87
|
@ -42,3 +42,27 @@ export void CreatureLib_BattleSide_MarkAsFled(BattleSide* p) { p->MarkAsFled();
|
||||||
export u8 CreatureLib_BattleSide_SwapPositions(u8& out, BattleSide* p, u8 a, u8 b) {
|
export u8 CreatureLib_BattleSide_SwapPositions(u8& out, BattleSide* p, u8 a, u8 b) {
|
||||||
Try(out = p->SwapPositions(a, b);)
|
Try(out = p->SwapPositions(a, b);)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export BattleScript* CreatureLib_BattleSide_GetVolatileScript(BattleSide* p, const char* key) {
|
||||||
|
auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key));
|
||||||
|
if (!v.HasValue()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return v.GetValue();
|
||||||
|
}
|
||||||
|
export uint8_t CreatureLib_BattleSide_AddVolatileScriptByName(BattleSide* p, const char* key) {
|
||||||
|
Try(p->AddVolatileScript(ArbUt::StringView(key));)
|
||||||
|
}
|
||||||
|
export uint8_t CreatureLib_BattleSide_AddVolatileScript(BattleSide* p, BattleScript* script) {
|
||||||
|
Try(p->AddVolatileScript(script);)
|
||||||
|
}
|
||||||
|
|
||||||
|
export uint8_t CreatureLib_BattleSide_RemoveVolatileScript(BattleSide* p, const char* key) {
|
||||||
|
Try(p->RemoveVolatileScript(ArbUt::StringView::CalculateHash(key));)
|
||||||
|
}
|
||||||
|
export uint8_t CreatureLib_BattleSide_RemoveVolatileScriptWithScript(BattleSide* p, BattleScript* script) {
|
||||||
|
Try(p->RemoveVolatileScript(script);)
|
||||||
|
}
|
||||||
|
export bool CreatureLib_BattleSide_HasVolatileScript(BattleSide* p, const char* key) {
|
||||||
|
return p->HasVolatileScript(ArbUt::StringView::CalculateHash(key));
|
||||||
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ namespace CreatureLib::Battling {
|
||||||
ArbUt::OptionalBorrowedPtr<BattleParty> FindPartyForCreature(const ArbUt::BorrowedPtr<Creature>&);
|
ArbUt::OptionalBorrowedPtr<BattleParty> FindPartyForCreature(const ArbUt::BorrowedPtr<Creature>&);
|
||||||
|
|
||||||
const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; }
|
const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; }
|
||||||
|
|
||||||
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
|
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
|
||||||
return _volatile.Get(key);
|
return _volatile.Get(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,3 +132,18 @@ BattleSide* BattleSide::CloneWithoutCreatures(ArbUt::BorrowedPtr<Battle> battle)
|
||||||
side->_hasFled = _hasFled;
|
side->_hasFled = _hasFled;
|
||||||
return side;
|
return side;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BattleScript* BattleSide::AddVolatileScript(const ArbUt::StringView& key) {
|
||||||
|
auto script = _volatile.Get(key);
|
||||||
|
if (script.HasValue()) {
|
||||||
|
script.GetValue()->Stack();
|
||||||
|
return script.GetValue();
|
||||||
|
}
|
||||||
|
script = _battle->GetLibrary()->LoadScript(ScriptCategory::Battle, key);
|
||||||
|
if (!script.HasValue()) {
|
||||||
|
THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'.");
|
||||||
|
}
|
||||||
|
return _volatile.Add(script.GetValue());
|
||||||
|
}
|
||||||
|
BattleScript* BattleSide::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); }
|
||||||
|
void BattleSide::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }
|
||||||
|
|
|
@ -92,6 +92,20 @@ namespace CreatureLib::Battling {
|
||||||
bool SwapPositions(u8 a, u8 b);
|
bool SwapPositions(u8 a, u8 b);
|
||||||
|
|
||||||
BattleSide* CloneWithoutCreatures(ArbUt::BorrowedPtr<Battle> battle) const;
|
BattleSide* CloneWithoutCreatures(ArbUt::BorrowedPtr<Battle> battle) const;
|
||||||
|
|
||||||
|
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
|
||||||
|
return _volatile.Get(key);
|
||||||
|
}
|
||||||
|
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(uint32_t keyHash) const noexcept {
|
||||||
|
return _volatile.Get(keyHash);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||||
|
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue