Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}