void ProjectReader::readProject(QIODevice *device, const QString &path) { xml.setDevice(device); QString mapPath = path + "/Maps"; QString scriptPath = path + "/Scripts"; if (xml.readNextStartElement() && xml.name() == QLatin1String("AuroraProject")) { const QXmlStreamAttributes atts = xml.attributes(); const int mapCount = atts.value(QLatin1String("mapCount")).toString().toInt(); const int scriptCount = atts.value(QLatin1String("scriptCount")).toString().toInt(); const int spriteCount = atts.value(QLatin1String("spriteCount")).toString().toInt(); const int tilesetCount = atts.value(QLatin1String("tilesetCount")).toString().toInt(); const int objectCount = atts.value(QLatin1String("objectCount")).toString().toInt(); mDocumentManager->setMapCount(mapCount); mDocumentManager->setScriptCount(scriptCount); mDocumentManager->setSpriteCount(spriteCount); mDocumentManager->setTilesetCount(tilesetCount); mDocumentManager->setObjectCount(objectCount); while (xml.readNextStartElement()) { const QXmlStreamAttributes att = xml.attributes(); //qDebug() << "look an element"; if (xml.name() == QLatin1String("Map")) { //qDebug() << "look a map"; QString name = att.value(QLatin1String("path")).toString(); readMaps(mapPath, name, true); } else if (xml.name() == QLatin1String("Script")) { //qDebug() << "look a script"; QString name = att.value(QLatin1String("path")).toString(); //qDebug() << "name" << name; readScripts(scriptPath, name, true); } else if (xml.name() == QLatin1String("Last")) { //qDebug() << "look a last"; readLastOpen(); } else { readUnknownElement(); } } } else { xml.raiseError(tr("Not a project file.")); } }
void ProjectReader::readProject() { Q_ASSERT(isStartElement() && name() == "project"); project = new Project(); bool dirExists; //message("readProject"); QDir::setCurrent(fileinfo.absolutePath()); // Since we need to load our bitmaps first, we just read in all of the filenames // and then load the actual resources last. That way, if <tilesets> isn't the // first section, there won't be any errors. while (!atEnd()) { readNext(); if (isEndElement()) break; if (isStartElement()) { if (name() == "name") { project->SetName(readElementText()); //message("Map name: " + map->GetName()); } else if (name() == "maps") { readMaps(); } else if (name() == "tilesets") { readTilesets(); } else if (name() == "sprites") { readSprites(); } else if (name() == "scripts") { readScripts(); } else { readUnknownElement(); } } } // Load bitmaps dirExists = QDir::setCurrent("tilesets"); BitmapReader bitmapReader; while(!tilesetlist.isEmpty()) { QString b = tilesetlist.takeFirst(); // load bitmap bitmapReader.read(b); } if(dirExists) QDir::setCurrent(".."); // load sprites dirExists = QDir::setCurrent("sprites"); SpriteReader spriteReader; while(!spritelist.isEmpty()) { QString s = spritelist.takeFirst(); // load sprite spriteReader.read(s); } if(dirExists) QDir::setCurrent(".."); // load maps dirExists = QDir::setCurrent("maps"); MapReader mapReader; while(!maplist.isEmpty()) { QString m = maplist.takeFirst(); // load map mapReader.read(m); } if(dirExists) QDir::setCurrent(".."); }