added example Compositions.xml, implemented most of newComposition() method

This commit is contained in:
Steffen Fündgens 2014-11-28 17:05:49 +01:00
parent 6b904894c6
commit 9f1a931b0b
4 changed files with 86 additions and 4 deletions

View 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>

View File

@ -6,17 +6,24 @@ using namespace tinyxml2;
Converter::Converter(std::string level){
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::ifstream src(xmlFile, std::ios::binary);
std::ofstream dst(backup, std::ios::binary);
dst << src.rdbuf();
//Load the xml file
//Load the Level xml file
const char* charXmlFile = xmlFile.c_str();
doc->LoadFile(charXmlFile);
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);
@ -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){
//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;
nextId[1] += 1;
if (nextId[1] == 256){

View File

@ -21,6 +21,7 @@ class Converter {
std::vector<unsigned int> nextId;
std::string xmlFile;
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);
};

View File

@ -5,6 +5,9 @@
#include <iostream>
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];
Converter conv = Converter(levelString);
bool idFound[256][256];