Use std::optional for BaseLibrary TryGet.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-12-12 12:42:28 +01:00
parent 5c39694f19
commit 185ec40ba5
4 changed files with 28 additions and 17 deletions

View File

@@ -48,9 +48,11 @@ Creature* CreateCreature::Create() {
}
ArbUt::BorrowedPtr<const Library::Item> heldItem;
if (!this->_heldItem.IsEmpty()) {
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.GetHash(), heldItem)) {
auto val = _library->GetItemLibrary()->TryGet(this->_heldItem.GetHash());
if (!val.has_value()) {
THROW("Invalid held item '" << this->_heldItem.c_str() << "'.");
}
heldItem = val.value();
}
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);