added example Compositions.xml, implemented most of newComposition() method
This commit is contained in:
parent
20e7c732e2
commit
f6bdf5dc32
39
Levels/ObjectSetups/Compositions.xml
Normal file
39
Levels/ObjectSetups/Compositions.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<composition>
|
||||||
|
<typeID>1</typeID>
|
||||||
|
<object>
|
||||||
|
<filePath>../Levels/Geometry/1.obj</filePath>
|
||||||
|
<xOffset>0.0</xOffset>
|
||||||
|
<yOffset>0.0</yOffset>
|
||||||
|
<zOffset>0.0</zOffset>
|
||||||
|
<scale>1.0</scale>
|
||||||
|
</object>
|
||||||
|
</composition>
|
||||||
|
|
||||||
|
<composition>
|
||||||
|
<typeID>2</typeID>
|
||||||
|
<object>
|
||||||
|
<filePath>../Levels/Geometry/2.obj</filePath>
|
||||||
|
<xOffset>0.0</xOffset>
|
||||||
|
<yOffset>0.0</yOffset>
|
||||||
|
<zOffset>0.0</zOffset>
|
||||||
|
<scale>1.0</scale>
|
||||||
|
</object>
|
||||||
|
<object>
|
||||||
|
<filePath>../Levels/Geometry/3.obj</filePath>
|
||||||
|
<xOffset>0.0</xOffset>
|
||||||
|
<yOffset>1.0</yOffset>
|
||||||
|
<zOffset>2.0</zOffset>
|
||||||
|
<scale>1.0</scale>
|
||||||
|
</object>
|
||||||
|
</composition>
|
||||||
|
|
||||||
|
<composition>
|
||||||
|
<typeID>3</typeID>
|
||||||
|
<object>
|
||||||
|
<filePath>../Levels/Geometry/4.obj</filePath>
|
||||||
|
<xOffset>0.0</xOffset>
|
||||||
|
<yOffset>0.0</yOffset>
|
||||||
|
<zOffset>0.0</zOffset>
|
||||||
|
<scale>1.0</scale>
|
||||||
|
</object>
|
||||||
|
</composition>
|
@ -6,17 +6,24 @@ using namespace tinyxml2;
|
|||||||
Converter::Converter(std::string level){
|
Converter::Converter(std::string level){
|
||||||
xmlFile = "../Levels/ObjectSetups/Level" + level + ".xml";
|
xmlFile = "../Levels/ObjectSetups/Level" + level + ".xml";
|
||||||
|
|
||||||
//Create a backup of the current xml file
|
//Load Compositions
|
||||||
|
const char* charCompositions = "../Levels/ObjectSetups/Compositions.xml";
|
||||||
|
compositions->LoadFile(charCompositions);
|
||||||
|
if (compositions->ErrorID()!=0){
|
||||||
|
printf("Could not open Compositions!!!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create a backup of the current Level xml file
|
||||||
std::string backup = "../Levels/ObjectSetups/BackupLevel" + level + ".xml";
|
std::string backup = "../Levels/ObjectSetups/BackupLevel" + level + ".xml";
|
||||||
std::ifstream src(xmlFile, std::ios::binary);
|
std::ifstream src(xmlFile, std::ios::binary);
|
||||||
std::ofstream dst(backup, std::ios::binary);
|
std::ofstream dst(backup, std::ios::binary);
|
||||||
dst << src.rdbuf();
|
dst << src.rdbuf();
|
||||||
|
|
||||||
//Load the xml file
|
//Load the Level xml file
|
||||||
const char* charXmlFile = xmlFile.c_str();
|
const char* charXmlFile = xmlFile.c_str();
|
||||||
doc->LoadFile(charXmlFile);
|
doc->LoadFile(charXmlFile);
|
||||||
if (doc->ErrorID()!=0){
|
if (doc->ErrorID()!=0){
|
||||||
printf("Could not open xml, creating new xml.");
|
printf("Could not open xml, creating new xml.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
nextId.push_back(1);
|
nextId.push_back(1);
|
||||||
@ -35,7 +42,39 @@ void Converter::updateComposition(unsigned int idG, unsigned int idB, unsigned i
|
|||||||
|
|
||||||
|
|
||||||
std::vector<unsigned int> Converter::newComposition(unsigned int type, unsigned int posX, unsigned int posZ){
|
std::vector<unsigned int> Converter::newComposition(unsigned int type, unsigned int posX, unsigned int posZ){
|
||||||
//TODO
|
XMLNode* thisComposition = compositions->FirstChild();
|
||||||
|
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement()){
|
||||||
|
int thisType;
|
||||||
|
XMLElement* thisCompositionElement = thisComposition->ToElement();
|
||||||
|
thisCompositionElement->QueryIntAttribute("typeID", &thisType);
|
||||||
|
if(thisType == type){
|
||||||
|
//XMLElement* newComposition = doc.NewElement();
|
||||||
|
//newComposition = thisComposition;
|
||||||
|
//XMLElement* newComposition = thisComposition->Clone(); //TODO write own clone function
|
||||||
|
doc->InsertFirstChild(newComposition);
|
||||||
|
|
||||||
|
XMLElement* idBlue = doc->NewElement("<idBlue>" + itoa(nextId[1]) + "</idBlue>");
|
||||||
|
XMLElement* idGreen = doc->NewElement("<idGreen>" + itoa(nextId[0]) + "</idGreen>");
|
||||||
|
XMLElement* zPos = doc->NewElement("<zPos>" + itoa(posZ) + "</zPos>");
|
||||||
|
XMLElement* yOffset = doc->NewElement("<yOffset>0.0</yOffset>");
|
||||||
|
XMLElement* xPos = doc->NewElement("<xPos>" + itoa(posX) + "</xPos>");
|
||||||
|
XMLElement* zRot = doc->NewElement("<zRot>0.0</zRot>");
|
||||||
|
XMLElement* yRot = doc->NewElement("<yRot>0.0</yRot>");
|
||||||
|
XMLElement* xRot = doc->NewElement("<xRot>0.0</xRot>");
|
||||||
|
XMLElement* scale = doc->NewElement("<scale>1.0</scale>");
|
||||||
|
|
||||||
|
newComposition->InsertFirstChild(idBlue);
|
||||||
|
newComposition->InsertFirstChild(idGreen);
|
||||||
|
newComposition->InsertFirstChild(zPos);
|
||||||
|
newComposition->InsertFirstChild(yOffset);
|
||||||
|
newComposition->InsertFirstChild(xPos);
|
||||||
|
newComposition->InsertFirstChild(zRot);
|
||||||
|
newComposition->InsertFirstChild(yRot);
|
||||||
|
newComposition->InsertFirstChild(xRot);
|
||||||
|
newComposition->InsertFirstChild(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<unsigned int> ret = nextId;
|
std::vector<unsigned int> ret = nextId;
|
||||||
nextId[1] += 1;
|
nextId[1] += 1;
|
||||||
if (nextId[1] == 256){
|
if (nextId[1] == 256){
|
||||||
|
@ -21,6 +21,7 @@ class Converter {
|
|||||||
std::vector<unsigned int> nextId;
|
std::vector<unsigned int> nextId;
|
||||||
std::string xmlFile;
|
std::string xmlFile;
|
||||||
XMLDocument* doc = new XMLDocument();
|
XMLDocument* doc = new XMLDocument();
|
||||||
|
XMLDocument* compositions = new XMLDocument();
|
||||||
void newObject(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ);
|
void newObject(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main( int argc, char *argv[] ){
|
int main( int argc, char *argv[] ){
|
||||||
|
if (argc <= 1){
|
||||||
|
std::cout << "Converter needs the level (1,2,...) as input." << std::endl;
|
||||||
|
}
|
||||||
std::string levelString = argv[1];
|
std::string levelString = argv[1];
|
||||||
Converter conv = Converter(levelString);
|
Converter conv = Converter(levelString);
|
||||||
bool idFound[256][256];
|
bool idFound[256][256];
|
||||||
|
Loading…
Reference in New Issue
Block a user