Commits

minirop  committed e62f07e

load complete

  • Participants
  • Parent commits 08326cd

Comments (0)

Files changed (1)

File GameWidget.cpp

 
 void GameWidget::load(const QString& savefile)
 {
-	Q_UNUSED(savefile);
+	QDomDocument doc("savegame");
+	QFile file("saves/"+savefile+".xml");
 	
-	setPixmap(QPixmap(lastLoadedBackground));
+	if(!file.open(QIODevice::ReadOnly))
+	{
+		QMessageBox::critical(this, "Error", "Can't open this savegame for reading. exiting");
+		QTimer::singleShot(0, qApp, SLOT(quit()));
+		MainWindow::isClosing = true;
+		return;
+	}
+	if(!doc.setContent(&file))
+	{
+		QMessageBox::critical(this, "Error", "Can't read savegame. corrupted ? exiting");
+		QTimer::singleShot(0, qApp, SLOT(quit()));
+		file.close();
+		MainWindow::isClosing = true;
+		return;
+	}
+	
+	file.close();
+	
+	QDomElement docElem = doc.documentElement();
+	QDomElement elems = docElem.firstChildElement();
+	while(!elems.isNull())
+	{
+		if(elems.tagName() == "character")
+		{
+			QString name = elems.attribute("name");
+			if(m_characters.contains(name))
+			{
+				Character * c = m_characters[name];
+				c->setExpression(elems.attribute("expression"));
+				c->move(elems.attribute("x", "0").toInt(), elems.attribute("y", "0").toInt());
+				c->setVisible(elems.attribute("show", "0").toInt() > 0);
+			}
+		}
+		else if(elems.tagName() == "background")
+		{
+			lastLoadedBackground = elems.attribute("src");
+			setPixmap(QPixmap(lastLoadedBackground));
+		}
+		else if(elems.tagName() == "arc")
+		{
+			lastLoadedArc = elems.attribute("name");
+			currentArc = lastLoadedArc;
+		}
+		else if(elems.tagName() == "variable")
+		{
+			setVariable(elems.attribute("name"), elems.attribute("value"));
+		}
+		else if(elems.tagName() == "saved")
+		{
+			QStringList pushed = elems.attribute("values").split(",");
+			foreach(QString push, pushed)
+			{
+				savedPositions.push_back(push.toInt());
+			}
+		}
+		
+		elems = elems.nextSiblingElement();
+	}
+	
+	/*
+	loadArc();
+	if(!MainWindow::isClosing)
+		evaluate();
+	*/
 }
 
 void GameWidget::loadArc()
 		i.value()->setDefaultExpression();
 	}
 	
+	load("1");
+	
 	loadArc();
 	if(!MainWindow::isClosing)
 		evaluate();
 	if(currentSavedPos < savedPositions.size())
 	{
 		i = savedPositions[ currentSavedPos ];
-		qDebug() << "loading evaluateList" << i;
 	}
 	else
 	{
 		
 		savedPositions[ currentSavedPos ] = i;
 		
-		qDebug() << currentSavedPos << savedPositions;
-		
 		QDomNode node = list.item(i);
 		if(!node.isNull())
 		{