mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-10 21:03:31 +00:00
STARK: Add a method to tell if a reference can be resolved
This commit is contained in:
parent
d29834d9a7
commit
563fa04f2c
@ -50,7 +50,7 @@ void ResourceReference::addPathElement(Resources::Type type, uint16 index) {
|
||||
Resources::Object *ResourceReference::resolve() const {
|
||||
Resources::Object *resource = nullptr;
|
||||
for (uint i = 0; i < _path.size(); i++) {
|
||||
PathElement element = _path[i];
|
||||
const PathElement &element = _path[i];
|
||||
|
||||
switch (element.getType().get()) {
|
||||
case Resources::Type::kLevel:
|
||||
@ -82,6 +82,49 @@ Resources::Object *ResourceReference::resolve() const {
|
||||
return resource;
|
||||
}
|
||||
|
||||
bool ResourceReference::canResolve() const {
|
||||
if (empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Resources::Object *level = nullptr;
|
||||
for (uint i = 0; i < _path.size(); i++) {
|
||||
const PathElement &element = _path[i];
|
||||
|
||||
switch (element.getType().get()) {
|
||||
case Resources::Type::kLevel:
|
||||
if (element.getIndex()) {
|
||||
level = StarkResourceProvider->getLevel(element.getIndex());
|
||||
} else {
|
||||
level = StarkGlobal->getLevel();
|
||||
}
|
||||
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case Resources::Type::kLocation: {
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Resources::Object *location = StarkResourceProvider->getLocation(level->getIndex(), element.getIndex());
|
||||
|
||||
if (!location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResourceReference::empty() const {
|
||||
return _path.empty();
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ public:
|
||||
/** Return true if this reference is a null pointer */
|
||||
bool empty() const;
|
||||
|
||||
/** Can this reference be resolved using currently loaded archives? */
|
||||
bool canResolve() const;
|
||||
private:
|
||||
void addPathElement(Resources::Type type, uint16 index);
|
||||
Resources::Object *resolve() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user