Adjusted the converter to be robust against IDs being overwritten with zeros in the png. Sucessfully ran it.
This commit is contained in:
parent
087d36aa15
commit
320b765951
@ -178,6 +178,34 @@ Converter::~Converter(){
|
||||
}
|
||||
|
||||
std::vector<int> Converter::newComposition(int type, float posX, float posZ){
|
||||
int oldIDGreen, oldIDBlue;
|
||||
bool alreadyExists = false;
|
||||
XMLElement* thisComposition = doc->FirstChildElement("composition");
|
||||
for(; thisComposition; thisComposition=thisComposition->NextSiblingElement("composition")){
|
||||
float xPos = queryFloat(thisComposition, "xPos");
|
||||
float zPos = queryFloat(thisComposition, "zPos");
|
||||
int typeID = queryInt(thisComposition, "typeID");
|
||||
if(xPos == posX && zPos == posZ && typeID == type){
|
||||
if(alreadyExists){
|
||||
std::cout << "At the position " << xPos << "," << zPos << " multiple compositions with the ID " << typeID << " exist in the xml." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
oldIDGreen = queryInt(thisComposition, "idGreen");
|
||||
oldIDBlue = queryInt(thisComposition, "idBlue");
|
||||
alreadyExists = true;
|
||||
}
|
||||
}
|
||||
if (alreadyExists){
|
||||
if (! idUsed[oldIDGreen][oldIDBlue]){
|
||||
std::cout << "The composition with ID " << oldIDGreen << "," << oldIDBlue << " exists in the xml but the converter thinks it does not." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
std::vector<int> oldID;
|
||||
oldID.push_back(oldIDGreen);
|
||||
oldID.push_back(oldIDBlue);
|
||||
return oldID;
|
||||
}
|
||||
|
||||
bool full = false;
|
||||
while(idUsed[nextID[0]][nextID[1]]){
|
||||
nextID[1] += 1;
|
||||
@ -194,6 +222,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XMLElement* newComposition = doc->NewElement("composition");
|
||||
XMLElement* typeID = doc->NewElement("typeID");
|
||||
XMLElement* idBlue = doc->NewElement("idBlue");
|
||||
@ -322,6 +351,28 @@ void Converter::save(){
|
||||
doc->SaveFile(charXmlFile);
|
||||
}
|
||||
|
||||
float Converter::queryFloat(XMLElement* element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
float ret;
|
||||
errorCheck(attributeElement->QueryFloatText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
float Converter::queryFloat(XMLDocument*& element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
std::cout << "XMLError: Attribute " << attribute << " does not exist." << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
float ret;
|
||||
errorCheck(attributeElement->QueryFloatText(&ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Converter::queryInt(XMLElement* element, const char* attribute){
|
||||
XMLElement* attributeElement = element->FirstChildElement(attribute);
|
||||
if (attributeElement == NULL){
|
||||
|
@ -16,12 +16,13 @@ class Converter {
|
||||
void deleteComposition(int idG, int idB);
|
||||
void save(); //writes the xml to file
|
||||
private:
|
||||
|
||||
std::vector<int> nextID;
|
||||
bool idUsed[256][256];
|
||||
std::string xmlFile;
|
||||
XMLDocument* doc = new XMLDocument();
|
||||
XMLDocument* compositions = new XMLDocument();
|
||||
float queryFloat(XMLElement* element, const char* attribute);
|
||||
float queryFloat(XMLDocument*& element, const char* attribute);
|
||||
int queryInt(XMLElement* element, const char* attribute);
|
||||
int queryInt(XMLDocument*& element, const char* attribute);
|
||||
bool queryBool(XMLElement* element, const char* attribute);
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 3.5 KiB |
@ -1,3 +1,32 @@
|
||||
<composition>
|
||||
<scale>1.0</scale>
|
||||
<xRot>0.0</xRot>
|
||||
<yRot>0.0</yRot>
|
||||
<zRot>0.0</zRot>
|
||||
<manualPos>false</manualPos>
|
||||
<xPos>58.500000</xPos>
|
||||
<yOffset>0.0</yOffset>
|
||||
<zPos>-172.500000</zPos>
|
||||
<idGreen>0</idGreen>
|
||||
<idBlue>112</idBlue>
|
||||
<typeID>221</typeID>
|
||||
<trigger>
|
||||
<name>-</name>
|
||||
<xPosition>0</xPosition>
|
||||
<yPosition>0</yPosition>
|
||||
<zPosition>0</zPosition>
|
||||
<targetIdGreen>-</targetIdGreen>
|
||||
<targetIdBlue>-</targetIdBlue>
|
||||
<distance>1.0</distance>
|
||||
<isBiggerThan>false</isBiggerThan>
|
||||
<objectNum>0</objectNum>
|
||||
<luaScript>-</luaScript>
|
||||
<toChangeIdGreen>0</toChangeIdGreen>
|
||||
<toChangeIdBlue>0</toChangeIdBlue>
|
||||
<toChangeObjNum>0</toChangeObjNum>
|
||||
</trigger>
|
||||
</composition>
|
||||
|
||||
<composition>
|
||||
<scale>1.0</scale>
|
||||
<xRot>0.0</xRot>
|
||||
|
BIN
data/levels/Level1Backup.png
Normal file
BIN
data/levels/Level1Backup.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
8312
data/levels/Level1Backup.xml
Normal file
8312
data/levels/Level1Backup.xml
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user