diff --git a/Levels/ObjectSetups/Lvl1.png b/Levels/ObjectSetups/Lvl1.png new file mode 100644 index 0000000..e216392 Binary files /dev/null and b/Levels/ObjectSetups/Lvl1.png differ diff --git a/converter/main.cc b/converter/main.cc index cd23435..44c81da 100644 --- a/converter/main.cc +++ b/converter/main.cc @@ -4,64 +4,56 @@ #include #include -//global variable level: -unsigned int level; - -int main( int argc, char *argv[] ){ - //TODO: always update this: - unsigned int numLevels=1; +int main( int argc, char *argv[] ){ + unsigned int level=atoi(argv[1]); Converter conv; - //iterate over all Levels - for (level=1; level<=numLevels; level++){ - bool idFound[256][256]; - for (int i=0; i<256; i++){ - for (int j=0; j<256; j++){ - idFound[i][j] = false; - } + bool idFound[256][256]; + for (int i=0; i<256; i++){ + for (int j=0; j<256; j++){ + idFound[i][j] = false; } - //read the setup png - char levelChar[2]; - sprintf (levelChar,"%i", level); - std::string levelString = levelChar; - std::string filePath = "../Levels/setupLvl" + levelString + ".png"; -//printf("%s", filePath); - std::vector image; //the raw pixels - unsigned int width, height; - unsigned error = lodepng::decode(image, width, height, filePath); - if (error) { - std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; - } - //iterate over all pixels of the image - for(unsigned int rowNum = 0; rowNum < height; rowNum++){ - for(unsigned int columnNum = 0; columnNum < width; columnNum++){ - unsigned int pixel = (rowNum*width+columnNum)*4; - //if there is a composition here, adjust the xml and image - if(image[pixel]!=0){ - if(image[pixel+1]==0 && image[pixel+2]==0){ - std::vector temp; - temp = conv.newComposition(image[pixel], rowNum, columnNum); - idFound[temp[0]][temp[1]] = true; - image[pixel+1] = temp[0]; - image[pixel+2] = temp[1]; - }else{ - conv.updateComposition(image[pixel], image[pixel+1], image[pixel+2], rowNum, columnNum); - idFound[image[pixel+1]][image[pixel+2]] = true; - } + } + //read the setup png + char levelChar[2]; + sprintf (levelChar,"%i", level); + std::string levelString = levelChar; + std::string filePath = "../Levels/ObjectSetups/Lvl" + levelString + ".png"; + std::vector image; //the raw pixels + unsigned int width, height; + unsigned error = lodepng::decode(image, width, height, filePath); + if (error) { + std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; + } + //iterate over all pixels of the image + for(unsigned int rowNum = 0; rowNum < height; rowNum++){ + for(unsigned int columnNum = 0; columnNum < width; columnNum++){ + unsigned int pixel = (rowNum*width+columnNum)*4; + //if there is a composition here, adjust the xml and image + if(image[pixel]!=0){ + if(image[pixel+1]==0 && image[pixel+2]==0){ + std::vector temp; + temp = conv.newComposition(image[pixel], rowNum, columnNum); + idFound[temp[0]][temp[1]] = true; + image[pixel+1] = temp[0]; + image[pixel+2] = temp[1]; + }else{ + conv.updateComposition(image[pixel], image[pixel+1], image[pixel+2], rowNum, columnNum); + idFound[image[pixel+1]][image[pixel+2]] = true; } } } - //write ids back to the setup png - error = lodepng::encode(filePath, image, width, height); - if(error) { - std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; - } - //delete compositions that were not in the png anymore - for (int i=0; i<256; i++){ - for (int j=0; j<256; j++){ - if (idFound[i][j] == false){ - //TODO if (exists)? - conv.deleteComposition(i,j); - } + } + //write ids back to the setup png + error = lodepng::encode(filePath, image, width, height); + if(error) { + std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; + } + //delete compositions that were not in the png anymore + for (int i=0; i<256; i++){ + for (int j=0; j<256; j++){ + if (idFound[i][j] == false){ + //TODO if (exists)? + conv.deleteComposition(i,j); } } }