Resources::Object *ResourceReference::resolve() const {
	Resources::Object *resource = nullptr;
	for (uint i = 0; i < _path.size(); i++) {
		PathElement element = _path[i];

		switch (element.getType().get()) {
		case Resources::Type::kLevel:
			if (element.getIndex()) {
				resource = StarkResourceProvider->getLevel(element.getIndex());
			} else {
				resource = StarkGlobal->getLevel();
			}

			if (!resource) {
				error("Level '%d' not found", element.getIndex());
			}

			break;
		case Resources::Type::kLocation:
			resource = StarkResourceProvider->getLocation(resource->getIndex(), element.getIndex());

			if (!resource) {
				error("Location '%d' not found in level '%d'", element.getIndex(), resource->getIndex());
			}

			break;
		default:
			resource = resource->findChildWithIndex(element.getType(), element.getIndex());
			break;
		}
	}

	return resource;
}
Exemple #2
0
void DefinitionRegistry::registerReference(const ResourceReference &reference) {
	if (!reference.canResolve()) {
		// The reference uses archives that are not currently loaded
		return;
	}

	Resources::Object *object = reference.resolve<Resources::Object>();
	if (!_definitions.contains(object)) {
		// TODO: There is no guarantee the definition is unique
		_definitions[object] = object->getType().getName() + stringToCamelCase(object->getName());;
	}
}
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;
}
Exemple #4
0
bool Console::Cmd_ListScripts(int argc, const char **argv) {
	Common::Array<Resources::Script *> scripts = listAllLocationScripts();

	for (uint i = 0; i < scripts.size(); i++) {
		Resources::Script *script = scripts[i];

		debugPrintf("%d: %s - enabled: %d", i, script->getName().c_str(), script->isEnabled());

		// Print which resource is causing the script to wait
		if (script->isSuspended()) {
			Resources::Object *suspending = script->getSuspendingResource();
			if (suspending) {
				debugPrintf(", waiting for: %s (%s)", suspending->getName().c_str(), suspending->getType().getName());
			} else {
				debugPrintf(", paused");
			}
		}

		debugPrintf("\n");
	}

	return true;
}
Resources::Object *ResourceReference::resolve() const {
	Resources::Object *level = nullptr;
	Resources::Object *resource = nullptr;
	for (uint i = 0; i < _path.size(); i++) {
		const PathElement &element = _path[i];

		switch (element.getType().get()) {
		case Resources::Type::kLevel:
			if (StarkStaticProvider->isStaticLocation()) {
				resource = level = StarkStaticProvider->getLevel();
				assert(resource->getIndex() == element.getIndex());
			} else if (element.getIndex()) {
				resource = level = StarkResourceProvider->getLevel(element.getIndex());
			} else {
				resource = level = StarkGlobal->getLevel();
			}

			if (!level) {
				error("Level '%d' not found", element.getIndex());
			}

			break;
		case Resources::Type::kLocation:
			if (!level) {
				error("Cannot resolve location '%d' without resolving a level first", element.getIndex());
			}

			if (StarkStaticProvider->isStaticLocation()) {
				resource = StarkStaticProvider->getLocation();
				assert(resource->getIndex() == element.getIndex());
			} else {
				resource = StarkResourceProvider->getLocation(level->getIndex(), element.getIndex());
			}

			if (!resource) {
				error("Location '%d' not found in level '%d'", element.getIndex(), level->getIndex());
			}

			break;
		default:
			resource = resource->findChildWithIndex(element.getType(), element.getIndex());
			break;
		}
	}

	return resource;
}