From a4fc18f944fcb697b062b2f3524f38a54e69ce64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Mon, 24 Nov 2014 13:21:52 +0100 Subject: [PATCH] converter now takes the Level to convert as input --- Levels/ObjectSetups/Lvl1.png | Bin 0 -> 88 bytes converter/main.cc | 98 ++++++++++++++++------------------- 2 files changed, 45 insertions(+), 53 deletions(-) create mode 100644 Levels/ObjectSetups/Lvl1.png diff --git a/Levels/ObjectSetups/Lvl1.png b/Levels/ObjectSetups/Lvl1.png new file mode 100644 index 0000000000000000000000000000000000000000..e216392e8d5a3ffbf01a109fb950c24be1949b57 GIT binary patch literal 88 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-UBp4!QuJ{S0 #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); } } }