//---------------------------------------------------------------------------// // LoadMaterialNeon // //---------------------------------------------------------------------------// bool CMaterial::LoadMaterialNeon(const string &sFile) { bool bRes = false; // XML Document TiXmlDocument XMLDoc(sFile.c_str()); if (XMLDoc.LoadFile() && XMLDoc.FirstChild("material")) { // Material completo bRes = true; m_bMaterial = true; TiXmlNode *pNode = XMLDoc.FirstChild("material"); // NumTexturas if (GetNumSameChilds(pNode, "texture") > MAX_TEXTURES) GLOG(("WAR: Material %s specified more than %d textures\n", sFile.c_str(), MAX_TEXTURES)); // Texturas TiXmlNode *pIter = NULL; int i = 0; do { pIter = pNode->IterateChildren("texture", pIter); if (pIter) { const char *pValue = pIter->ToElement()->Attribute("file"); if (pValue && pValue[0]) { // Añadir al gestor materiales m_pTexturas[i] = g_pGestorMateriales->AddTextura(pValue, 0); if (m_pTexturas[i] < 0) GLOG(("ERR: Can't load texture %s on Material %s\n", pValue, sFile.c_str())); } else GLOG(("ERR: Texture file not specified on Material %s\n", sFile.c_str())); m_iNumTexturas++; } i++; } while (pIter && i < MAX_TEXTURES); // Shader pIter = pNode->FirstChild("shader"); if (pIter) { const char *pValue = pIter->ToElement()->Attribute("file"); if (pValue && pValue[0]) { m_iShader = g_pGestorMateriales->AddShader(pValue); if (m_iShader < 0) GLOG(("ERR: Can't load Shader %s on Material %s\n", pValue, sFile.c_str())); } else GLOG(("ERR: Shader file not specified on Material %s\n", sFile.c_str())); } } return bRes; }
void OptionsDB::GetXML(XMLDoc& doc) const { doc = XMLDoc(); std::vector<XMLElement*> elem_stack; elem_stack.push_back(&doc.root_node); for (const std::map<std::string, Option>::value_type& option : m_options) { if (!option.second.storable) continue; std::string::size_type last_dot = option.first.find_last_of('.'); std::string section_name = last_dot == std::string::npos ? "" : option.first.substr(0, last_dot); std::string name = option.first.substr(last_dot == std::string::npos ? 0 : last_dot + 1); while (1 < elem_stack.size()) { std::string prev_section = PreviousSectionName(elem_stack); if (prev_section == section_name) { section_name = ""; break; } else if (section_name.find(prev_section + '.') == 0) { section_name = section_name.substr(prev_section.size() + 1); break; } elem_stack.pop_back(); } if (!section_name.empty()) { std::string::size_type last_pos = 0; std::string::size_type pos = 0; while ((pos = section_name.find('.', last_pos)) != std::string::npos) { XMLElement temp(section_name.substr(last_pos, pos - last_pos)); elem_stack.back()->children.push_back(temp); elem_stack.push_back(&elem_stack.back()->Child(temp.Tag())); last_pos = pos + 1; } XMLElement temp(section_name.substr(last_pos)); elem_stack.back()->children.push_back(temp); elem_stack.push_back(&elem_stack.back()->Child(temp.Tag())); } XMLElement temp(name); if (option.second.validator) { temp.SetText(option.second.ValueToString()); } else if (option.second.flag) { if (!boost::any_cast<bool>(option.second.value)) continue; } elem_stack.back()->children.push_back(temp); elem_stack.push_back(&elem_stack.back()->Child(temp.Tag())); } }
void LevelDesignerController::saveLevel(const QString& fileName) { // Write xml file ParserXML parser; parser.initFileName(fileName); PolygonList polygonList(_model->getPolygonList()); for (const poc::Polygon& polygon: polygonList) { parser.addPolygon(polygon); } parser.setLinesCount(_model->getLinesCount()); parser.setPartsCount(_model->getPartsCount()); parser.setMaxGapToWin(_model->getMaxGapToWin()); parser.setStarsCount(0); parser.setTolerances(0); parser.writeXML(); // Rename fileName QString newFileName = "resources/levels/"+fileName.split("resources/levels/").last(); // Create thumbbnail ThumbnailCreator thumbnailCreator(_model->getPolygonList()); QString thumbnailName = newFileName; thumbnailName.replace(QRegExp(".xml"), ".png"); thumbnailCreator.makeThumbnail("../PieceOfCake/"+thumbnailName); // Update levels file QStringList levelPackPath = newFileName.split("/"); levelPackPath.removeLast(); QString xmlFileName = "../PieceOfCake/"+levelPackPath.join("/")+"/levels.xml"; QFile XMLDoc(xmlFileName); if (!XMLDoc.exists()) { qDebug() << "Error:" << xmlFileName << "file not found"; return; } if(!XMLDoc.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Cannot open XML file in LevelDesignerController::saveLevel(const QString& fileName)"; return; } QDomDocument doc("PieceOfCakeLevelsML"); if(!doc.setContent(&XMLDoc)) { XMLDoc.close(); qDebug() << "Cannot set content of dom in LevelDesignerController::saveLevel(const QString& fileName)"; return; } XMLDoc.close(); QDomElement root = doc.firstChildElement("levels"); QDomNodeList levelList = root.elementsByTagName("level"); for (int k = 0; k < levelList.size(); ++k) { QDomElement level = levelList.at(k).toElement(); // No need to register several times the same level, // especially if this method is called to update thumbnail and level.xml file if (level.attribute("image").split("/").last() == thumbnailName.split("/").last()) { qDebug() << "No need to update levels.xml"; return; } } QDomElement level = doc.createElement("level"); level.setAttribute("id", root.elementsByTagName("level").size()); level.setAttribute("stars", "0"); level.setAttribute("image", thumbnailName); level.setAttribute("name", newFileName); root.appendChild(level); if(!XMLDoc.open(QIODevice::WriteOnly | QIODevice::Text)) { qDebug() << "Cannot open XML file in LevelDesignerController::saveLevel(const QString& fileName)"; return; } QTextStream inFile(&XMLDoc); inFile << doc.toString(2); XMLDoc.close(); }