コード例 #1
0
/**
  * This method is used to load the zone and all of it's sub elememnts
  * @param zoneNode The XML node to load the zone from
  * @param intoLevel The level to create the zone in
  * @return  0 , The file was loaded without problems
  *         -2 , If the file is corrupt
  */  
int CMapFileFilterXML::loadZone(QDomElement *zoneNode,CMapLevel *intoLevel)
{
	int gridWidth = m_mapManager->getMapData()->gridSize.width();
	int gridHeight = m_mapManager->getMapData()->gridSize.height();

	
	CMapZone *zone = NULL;

	if (intoLevel == NULL)
	{
		zone = m_mapManager->createZone(QPoint(-1,-1),NULL,false);
	}
	else
	{
		int x = zoneNode->attribute("X",QString::number(-1)).toInt();
		int y = zoneNode->attribute("Y",QString::number(-1)).toInt();

		if (x==-1 || y==-1)
		{
			kDebug() << "Unable to find zone pos ";
			return -2;
		}
		
		zone = m_mapManager->createZone(QPoint (x * gridWidth,y * gridHeight),intoLevel,false);
		zone->loadQDomElement(zoneNode);
		loadPluginPropertiesForElement(zone,zoneNode);
	}

	
	QDomNode n = zoneNode->firstChild();
	while (!n.isNull() )
	{
		QDomElement e = n.toElement();

		if (e.isNull() )
		{
			kDebug() << "Unable to find element ";
			return -2;
		}

		if (e.tagName()=="Level")
		{
			CMapLevel *level = m_mapManager->createLevel(UP,zone);
			QString id = e.attribute("ID","-2");
			if (id=="-2")
			{
				kDebug() << "Unable to find level ID";
				return -2;
			}
			level->setLevelID(id.toInt());

			QDomNode n2 = e.firstChild();
			while (!n2.isNull() )
			{
				QDomElement e2 = n2.toElement();

				if (e2.isNull() )
				{
					kDebug() << "Unable to find element ";
					return -2;
				}
			
				int x1 = e2.attribute("X",QString::number(-1)).toInt();
				int y1 = e2.attribute("Y",QString::number(-1)).toInt();			
				
				if (x1==-1 || y1==-1)
				{
					kDebug() << "Unable to find pos ";
					return -2;
				}

				if (e2.tagName()=="Zone")
				{
					loadZone(&e2,level);
				}
				else if (e2.tagName()=="Room")
				{
					CMapRoom *room = m_mapManager->createRoom(QPoint(x1 * gridWidth,y1 * gridHeight),level);
					
					room->loadQDomElement(&e2);
					loadPluginPropertiesForElement(room,&e2);
				}
				else if (e2.tagName()=="Text")
				{
					CMapText *text = m_mapManager->createText(QPoint (x1,y1),level,"");
					text->loadQDomElement(&e2);
					loadPluginPropertiesForElement(text,&e2);
				}
				else
				{
					kDebug() << "Unknown Type :  " << e2.tagName();
				}
				
				n2 = n2.nextSibling();
			}
		}
				

		n = n.nextSibling();
	}
	
	return 0;
}