示例#1
0
	void ResourceManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
	{
		FactoryManager& factory = FactoryManager::getInstance();

		VectorGuid vector_guid;
		// берем детей и крутимся, основной цикл
		xml::ElementEnumerator root = _node->getElementEnumerator();
		while (root.next(XML_TYPE))
		{
			// парсим атрибуты
			std::string id, type, name;
			root->findAttribute("type", type);
			root->findAttribute("name", name);
			root->findAttribute("id", id);

			Guid guid(id);
			if (!guid.empty())
			{
				if (mResourcesID.find(guid) != mResourcesID.end())
				{
					MYGUI_LOG(Warning, "dublicate resource id " << guid.print());
				}
			}

			if (mResources.find(name) != mResources.end())
			{
				MYGUI_LOG(Warning, "dublicate resource name '" << name << "'");
			}

			vector_guid.push_back(guid);

			IObject* object = factory.createObject(XML_TYPE, type);
			if (object == nullptr)
			{
				MYGUI_LOG(Error, "resource type '" << type << "' not found");
				continue;
			}

			IResourcePtr resource = object->castType<IResource>();
			resource->deserialization(root.current(), _version);

			if (!guid.empty()) mResourcesID[guid] = resource;
			if (!name.empty()) mResources[name] = resource;
		}

		if (!vector_guid.empty())
		{
			mListFileGuid[_file] = vector_guid;
		}

	}
示例#2
0
	void ResourceManager::loadFromXmlNode(xml::ElementPtr _node, const std::string& _file, Version _version)
	{
		FactoryManager& factory = FactoryManager::getInstance();

		// берем детей и крутимся, основной цикл
		xml::ElementEnumerator root = _node->getElementEnumerator();
		while (root.next(XML_TYPE))
		{
			// парсим атрибуты
			std::string type, name;
			root->findAttribute("type", type);
			root->findAttribute("name", name);

			if (name.empty())
				continue;

			MapResource::iterator item = mResources.find(name);
			if (item != mResources.end())
			{
				MYGUI_LOG(Warning, "dublicate resource name '" << name << "'");

				// ресурсами могут пользоваться
				mRemovedResoures.push_back((*item).second);
				mResources.erase(item);
			}

			IObject* object = factory.createObject(XML_TYPE, type);
			if (object == nullptr)
			{
				MYGUI_LOG(Error, "resource type '" << type << "' not found");
				continue;
			}

			IResourcePtr resource = object->castType<IResource>();
			resource->deserialization(root.current(), _version);

			mResources[name] = resource;
		}
	}