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

@@ -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) {