2014-11-21 14:43:27 +00:00
|
|
|
#include "converter.hh"
|
2014-11-25 12:51:25 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
using namespace tinyxml2;
|
|
|
|
|
|
|
|
Converter::Converter(std::string level){
|
|
|
|
xmlFile = "../Levels/ObjectSetups/Level" + level + ".xml";
|
|
|
|
|
|
|
|
//Create a backup of the current xml file
|
|
|
|
std::string backup = "../Levels/ObjectSetups/BackupLevel" + level + ".xml";
|
|
|
|
std::ifstream src(xmlFile, std::ios::binary);
|
|
|
|
std::ofstream dst(backup, std::ios::binary);
|
|
|
|
dst << src.rdbuf();
|
|
|
|
|
|
|
|
//Load the xml file
|
|
|
|
const char* charXmlFile = xmlFile.c_str();
|
|
|
|
doc->LoadFile(charXmlFile);
|
|
|
|
if (doc->ErrorID()!=0){
|
|
|
|
printf("Could not open xml, creating new xml.");
|
|
|
|
}
|
|
|
|
|
|
|
|
nextId.push_back(1);
|
|
|
|
nextId.push_back(250); //TODO
|
|
|
|
}
|
2014-11-21 14:43:27 +00:00
|
|
|
|
|
|
|
Converter::Converter(){
|
|
|
|
}
|
|
|
|
|
|
|
|
Converter::~Converter(){
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:51:25 +00:00
|
|
|
void Converter::updateComposition(unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ){
|
2014-11-21 14:43:27 +00:00
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned int> Converter::newComposition(unsigned int type, unsigned int posX, unsigned int posZ){
|
|
|
|
//TODO
|
2014-11-25 12:51:25 +00:00
|
|
|
std::vector<unsigned int> ret = nextId;
|
|
|
|
nextId[1] += 1;
|
|
|
|
if (nextId[1] == 256){
|
|
|
|
nextId[1] = 1;
|
|
|
|
nextId[0] +=1;
|
|
|
|
}
|
2014-11-21 14:43:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Converter::deleteComposition(unsigned int idG, unsigned int idB){
|
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:51:25 +00:00
|
|
|
void Converter::save(){
|
|
|
|
const char* charXmlFile = xmlFile.c_str();
|
|
|
|
doc->SaveFile(charXmlFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<unsigned int> Converter::getNextId(){
|
|
|
|
return nextId;
|
|
|
|
}
|
2014-11-21 14:43:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Converter::newObject(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ){
|
|
|
|
//TODO
|
|
|
|
}
|