Use std::optional for BaseLibrary TryGet.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -265,18 +265,18 @@ namespace CreatureLib::Battling {
|
||||
return variant;
|
||||
}
|
||||
void Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) {
|
||||
ArbUt::BorrowedPtr<const Library::Item> item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemName.GetHash(), item)) {
|
||||
auto v = _library->GetItemLibrary()->TryGet(itemName.GetHash());
|
||||
if (!v.has_value()) {
|
||||
THROW("Item not found '" << itemName.c_str() << "'.");
|
||||
}
|
||||
_heldItem = item;
|
||||
_heldItem = v.value();
|
||||
}
|
||||
void Creature::SetHeldItem(uint32_t itemNameHash) {
|
||||
ArbUt::BorrowedPtr<const Library::Item> item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemNameHash, item)) {
|
||||
auto v = _library->GetItemLibrary()->TryGet(itemNameHash);
|
||||
if (!v.has_value()) {
|
||||
THROW("Item not found.");
|
||||
}
|
||||
_heldItem = item;
|
||||
_heldItem = v.value();
|
||||
}
|
||||
|
||||
void Creature::AddVolatileScript(const ArbUt::StringView& name) {
|
||||
|
||||
Reference in New Issue
Block a user