Further work on better exceptions.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-07-26 17:41:11 +02:00
parent 29eb7c603a
commit 36f1e5beeb
12 changed files with 30 additions and 37 deletions

View File

@@ -137,9 +137,7 @@ void Battle::AddVolatileScript(const ArbUt::StringView& key) {
}
script = _library->LoadScript(ScriptCategory::Battle, key);
if (script == nullptr) {
std::stringstream ss;
ss << "Invalid volatile script requested for battle: '" << key.c_str() << "'.";
throw CreatureException(ss.str());
THROW_CREATURE("Invalid volatile script requested for battle: '" << key.c_str() << "'.");
}
return _volatile.Add(script.GetRaw());
}

View File

@@ -30,7 +30,7 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
AssertNotNull(choice)
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
if (find == _creatures.end())
throw CreatureException("User not found");
THROW_CREATURE("User not found");
uint8_t index = std::distance(_creatures.begin(), find);
_choices[index] = std::shared_ptr<BaseTurnChoice>(choice);
_choicesSet++;

View File

@@ -59,7 +59,7 @@ namespace CreatureLib::Battling {
if (_creatures[i] == c)
return i;
}
throw CreatureException("Unable to find creature on field.");
THROW_CREATURE("Unable to find creature on field.");
}
void MarkSlotAsUnfillable(const ArbUt::BorrowedPtr<Creature>& creature) noexcept {

View File

@@ -22,7 +22,7 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves())
throw CreatureException("You have already set the maximum amount of allowed moves.");
THROW_CREATURE("You have already set the maximum amount of allowed moves.");
auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash());
_attacks.Append(std::tuple(attackData, learnMethod));
@@ -50,7 +50,7 @@ Creature* CreateCreature::Create() {
ArbUt::BorrowedPtr<const Library::Item> heldItem;
if (!this->_heldItem.Empty()) {
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.GetHash(), heldItem)) {
throw CreatureException("Invalid held item.");
THROW_CREATURE("Invalid held item '" << this->_heldItem.c_str() << "'.");
}
}
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);

View File

@@ -227,14 +227,14 @@ ArbUt::BorrowedPtr<const Library::SpeciesVariant> Battling::Creature::GetDisplay
void Battling::Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) {
ArbUt::BorrowedPtr<const Library::Item> item;
if (!_library->GetItemLibrary()->TryGet(itemName.GetHash(), item)) {
throw CreatureException("Item not found.");
THROW_CREATURE("Item not found '" << itemName.c_str() << "'.");
}
_heldItem = item;
}
void Battling::Creature::SetHeldItem(uint32_t itemNameHash) {
ArbUt::BorrowedPtr<const Library::Item> item;
if (!_library->GetItemLibrary()->TryGet(itemNameHash, item)) {
throw CreatureException("Item not found.");
THROW_CREATURE("Item not found.");
}
_heldItem = item;
}
@@ -247,9 +247,7 @@ void Battling::Creature::AddVolatileScript(const ArbUt::StringView& name) {
}
script = this->_library->LoadScript(ScriptCategory::Creature, name);
if (script == nullptr) {
std::stringstream ss;
ss << "Invalid volatile script requested for creature: '" << name.c_str() << "'.";
throw CreatureException(ss.str());
THROW_CREATURE("Invalid volatile script requested for creature: '" << name.c_str() << "'.");
}
_volatile.Add(script.GetRaw());
}

View File

@@ -66,7 +66,7 @@ namespace CreatureLib::Battling {
return _hits[i * _numberHits + hit];
}
}
throw CreatureException("Invalid target requested.");
THROW_CREATURE("Invalid target requested.");
}
HitData* GetTargetIteratorBegin(Creature* creature) {
@@ -75,7 +75,7 @@ namespace CreatureLib::Battling {
return &_hits[i * _numberHits * sizeof(HitData)];
}
}
throw CreatureException("Invalid target requested.");
THROW_CREATURE("Invalid target requested.");
}
bool IsCreatureTarget(Creature* creature) noexcept {