Defensive programming for Party
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
fcdc58176f
commit
86ed173d30
|
@ -16,8 +16,8 @@ export uint8_t CreatureLib_CreatureParty_GetAtIndex(Creature*& out, const Creatu
|
||||||
export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) }
|
export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) }
|
||||||
export uint8_t CreatureLib_CreatureParty_PackParty(CreatureParty* p) { Try(p->PackParty();) }
|
export uint8_t CreatureLib_CreatureParty_PackParty(CreatureParty* p) { Try(p->PackParty();) }
|
||||||
|
|
||||||
export Creature* CreatureLib_CreatureParty_SwapInto(CreatureParty* p, size_t index, Creature* creature) {
|
export uint8_t CreatureLib_CreatureParty_SwapInto(Creature*& out, CreatureParty* p, size_t index, Creature* creature) {
|
||||||
return p->SwapInto(index, creature);
|
Try(out = p->SwapInto(index, creature);)
|
||||||
}
|
}
|
||||||
|
|
||||||
export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty* p) {
|
export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty* p) {
|
||||||
|
|
|
@ -24,6 +24,9 @@ namespace CreatureLib::Battling {
|
||||||
void Switch(size_t a, size_t b) noexcept { _party.Swap(a, b); }
|
void Switch(size_t a, size_t b) noexcept { _party.Swap(a, b); }
|
||||||
|
|
||||||
Creature* SwapInto(size_t index, Creature* creature) {
|
Creature* SwapInto(size_t index, Creature* creature) {
|
||||||
|
if (index >= _party.Count()) {
|
||||||
|
THROW("Index was out of bounds for party.")
|
||||||
|
}
|
||||||
auto p = _party.TakeOwnership(index);
|
auto p = _party.TakeOwnership(index);
|
||||||
_party.Set(index, creature);
|
_party.Set(index, creature);
|
||||||
return p;
|
return p;
|
||||||
|
|
Loading…
Reference in New Issue