diff --git a/Levels/ObjectSetups/Compositions.xml b/Levels/ObjectSetups/Compositions.xml
new file mode 100644
index 0000000..6fcee7c
--- /dev/null
+++ b/Levels/ObjectSetups/Compositions.xml
@@ -0,0 +1,39 @@
+
+ 1
+
+
+
+
+ 2
+
+
+
+
+
+ 3
+
+
diff --git a/converter/converter.cc b/converter/converter.cc
index 7f42248..61c8032 100644
--- a/converter/converter.cc
+++ b/converter/converter.cc
@@ -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 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("" + itoa(nextId[1]) + "");
+ XMLElement* idGreen = doc->NewElement("" + itoa(nextId[0]) + "");
+ XMLElement* zPos = doc->NewElement("" + itoa(posZ) + "");
+ XMLElement* yOffset = doc->NewElement("0.0");
+ XMLElement* xPos = doc->NewElement("" + itoa(posX) + "");
+ XMLElement* zRot = doc->NewElement("0.0");
+ XMLElement* yRot = doc->NewElement("0.0");
+ XMLElement* xRot = doc->NewElement("0.0");
+ XMLElement* scale = doc->NewElement("1.0");
+
+ 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 ret = nextId;
nextId[1] += 1;
if (nextId[1] == 256){
diff --git a/converter/converter.hh b/converter/converter.hh
index dc9253a..e625ee2 100644
--- a/converter/converter.hh
+++ b/converter/converter.hh
@@ -21,6 +21,7 @@ class Converter {
std::vector 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);
};
diff --git a/converter/main.cc b/converter/main.cc
index 3885f2e..53060e3 100644
--- a/converter/main.cc
+++ b/converter/main.cc
@@ -5,6 +5,9 @@
#include
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];