Esempio n. 1
0
/*
 int m_score;
 Point2i m_offset;
 int m_cols;
 int m_rows;
 enColor map[EDIT_GRAPH_ROW][EDIT_GRAPH_COL];
 */
void GraphDataStorageXML::save(const char* path, const GraphData& data, const StageBaseData* baseData) {
    cocos2d::log("save_crazysnow map path=%s", path);
    try {
        XMLDocument doc;
        XMLDocument *myDocument = &doc;
        
        {
            XMLElement* property = myDocument->NewElement("property");
            myDocument->LinkEndChild(property);
            
            //property->SetAttribute("score", data.score);
            property->SetAttribute("cols", data.cols);
            property->SetAttribute("rows", data.rows);
        }
        {
            XMLElement* map = myDocument->NewElement("map");
            myDocument->LinkEndChild(map);
            
            for (size_t row = 0; row < data.rows; ++row)
                for (size_t col = 0; col < data.cols; ++col) {
                    char buf[200]; sprintf(buf, "%ld_%ld", row, col);
                    map->SetAttribute(buf, data.map[row][col].catgy.color);
                }
        }
        
        myDocument->SaveFile(path);
    } catch (std::string& e) {
        cocos2d::log("%s\n", e.c_str());
    }
}
Esempio n. 2
0
void PanelMundo::crearArchivoMundos() const {
	// Creo el nodo Mundos
	XMLNode* nodoMundos = new XMLNode("Mundos");
	// Creo un Documento y guardo el archivo.
	XMLDocument doc;
	XMLDeclaration* decl = new XMLDeclaration("1.0", "UTF-8", "");
	doc.LinkEndChild(decl);
	doc.LinkEndChild(nodoMundos);
	doc.SaveFile(pathFileMundos);
}
Esempio n. 3
0
void createStorageFile(const string& path) {	
  XMLDocument doc;
  doc.SetValue("files");
  auto root = doc.NewElement("files");
  doc.LinkEndChild(root);

  int width = 42;
  fs::path current(path);
  fs::recursive_directory_iterator end;
  cout << "Go to directory iterator: " << current.string() << " -> " << endl;
  for (fs::recursive_directory_iterator item(current); item != end; ++item) {
    if (!fs::is_directory(item->status())) {
      string filename = item->path().string();	
      if ((int)filename.size()>width) {
	cout << "[file]: ..." << filename.substr(filename.size()-width) << endl;
      }
      else cout << "[file]: " << filename << endl;

      auto file = doc.NewElement("file");
      file->SetAttribute("name", filename.substr(current.string().size()).c_str());
      file->SetAttribute("last_modif", to_string(fs::last_write_time(filename)).c_str());
      root->LinkEndChild(file);
    }
  }
  
  doc.SaveFile(gStorage.c_str());
}
Esempio n. 4
0
void PanelMundo::botonCrearClickeado() {
	if (creador->nombreVacio()) {
		informable->nombreSeleccionadoVacio();
		return;
	}
	if (creador->nombreExistente()) {
		informable->nombreSeleccionadoYaExistente();
		return;
	}

	// Creo el nodo del nombre
	XMLNode* nodoNombre = new XMLNode("Nombre");
	XMLText* textNombre = new XMLText(creador->getNombreElegido());
	nodoNombre->LinkEndChild(textNombre);

	// Creo el nodo de la cantidad de jugadores
	XMLNode* nodoJugadores = new XMLNode("Jugadores");
	std::string sJugadores = cfd::intToString(creador->getCantidadJugadores());
	XMLText* textJugadores = new XMLText(sJugadores);
	nodoJugadores->LinkEndChild(textJugadores);

	// Creo el nodo de niveles vacío
	XMLNode* nodoNiveles = new XMLNode("Niveles");

	// Creo el nodo del mundo y linkeo los hijos
	XMLNode* nodoMundo = new XMLNode("Mundo");
	nodoMundo->LinkEndChild(nodoNombre);
	nodoMundo->LinkEndChild(nodoJugadores);
	nodoMundo->LinkEndChild(nodoNiveles);

	// Creo un Documento XML
	XMLDocument doc;
	XMLDeclaration* decl = new XMLDeclaration("1.0", "UTF-8", "");
	doc.LinkEndChild(decl);
	doc.LinkEndChild(nodoMundo);

	// Establezco la ruta donde guardar el XML y lo guardo.
	std::string ruta = RUTA_CARPETA_MUNDOS + creador->getNombreElegido() + ".xml";
	doc.SaveFile(ruta);

	// Actualizo la lista de mundos
	this->actualizarArchivoMundos(ruta);

	// Ahora procedo a editar el mundo recien creado
	informable->editarMundo(ruta);
}
Esempio n. 5
0
//生成文件
void Xmller:: giveBirthTo(std::string xmlfile){

    std::string filePath = FileUtils::getInstance()->getWritablePath() + xmlfile;
    log("生成文件=%s",filePath.c_str());
    XMLDocument *pDoc = new XMLDocument();
    
    //xml 声明(参数可选)
    XMLDeclaration *pDel = pDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\"");
    
    pDoc->LinkEndChild(pDel);
    
    //添加plist节点
    XMLElement *plistElement = pDoc->NewElement("Chapters");
//    plistElement->SetAttribute("version", "1.0");
    pDoc->LinkEndChild(plistElement);
    
//    XMLComment *commentElement = pDoc->NewComment("this is xml comment");
//    plistElement->LinkEndChild(commentElement);
    
    //添加dic节点
//    XMLElement *dicElement = pDoc->NewElement("dic");
//    plistElement->LinkEndChild(dicElement);
    
    //添加key节点
//    XMLElement *keyElement = pDoc->NewElement("key");
//    keyElement->LinkEndChild(pDoc->NewText("Text"));
//    dicElement->LinkEndChild(keyElement);
    
    XMLElement *arrayElement = pDoc->NewElement("Chapter");
    plistElement->LinkEndChild(arrayElement);
    
//    for (int i = 0; i<3; i++) {
//        XMLElement *elm = pDoc->NewElement("name");
//        elm->LinkEndChild(pDoc->NewText("Cocos2d-x"));
//        arrayElement->LinkEndChild(elm);
//    }
    
    XMLElement* elm = pDoc->NewElement("Level");     //标签
     elm->LinkEndChild(pDoc->NewText("0"));             //数值
     arrayElement->LinkEndChild(elm);
    
    XMLElement* elm1 = pDoc->NewElement("Score");
    elm1->LinkEndChild(pDoc->NewText("0"));
    arrayElement->LinkEndChild(elm1);
    
    XMLElement* elm2 = pDoc->NewElement("BulletNumber");
    elm2->LinkEndChild(pDoc->NewText("0"));
    arrayElement->LinkEndChild(elm2);
    
    XMLElement* elm3 = pDoc->NewElement("gun");
    elm3->LinkEndChild(pDoc->NewText("0"));
    arrayElement->LinkEndChild(elm3);
    
    XMLElement* elm4 = pDoc->NewElement("level05");
    elm4->LinkEndChild(pDoc->NewText("0"));
    arrayElement->LinkEndChild(elm4);
    
    XMLElement* elm5 = pDoc->NewElement("level06");
    elm5->LinkEndChild(pDoc->NewText("0"));
    arrayElement->LinkEndChild(elm5);
    
    pDoc->SaveFile(filePath.c_str());
    pDoc->Print();
    
    delete pDoc;
}