converter now takes the Level to convert as input
This commit is contained in:
parent
088ae1d494
commit
91099d91a0
BIN
Levels/ObjectSetups/Lvl1.png
Normal file
BIN
Levels/ObjectSetups/Lvl1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 88 B |
@ -4,64 +4,56 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
//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<unsigned char> 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<unsigned int> 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<unsigned char> 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<unsigned int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user