I am preparing myself for the Global Game Jam. I am working on a map editor for my game engine, but some problems can't be solved with my own fingers.
When I am drawing stuff on the screen (with my mouse), if I draw like a sign on one place, and later draw a sign at the same place, then I won't write that down in my map file again.
So, I am searching for this text "sign:x,y" (which is part of a comment), and if that's already written, I wont go further with my code.
But somehow, it can never find what I am searching for, so it's constantly writing the same shit over and over.
Code: Select all
if(leftClick == true)
{
if(tile == "sign")
{
// Read
ifstream myFileRead;
myFileRead.open("mainMap.txt");
string strFile;
myFileRead >> strFile; // put the file content inside a string
myFileRead.close();
// Converting the x and y position to a string
ostringstream ostr;
ostr << x;
string str_x = ostr.str();
ostringstream ostr2;
ostr2 << y;
string str_y = ostr2.str();
string pos = "sign:" + str_x + "," + str_y; // This is the text we should be looking for
size_t found = strFile.find(pos); // Will be used to check if "pos" has already been written
if(found == string::npos) // if "pos" is not found, go on and write down the drawing function
{
// Write
ofstream myFileWrite;
myFileWrite.open("mainMap.txt", ios_base::app);
myFileWrite << "sign.draw(" << x <<" - camera.x, " << y << " - camera.y, buffer); // " << pos << endl; // Writing our drawing function with the new image's position, into our map file
myFileWrite.close();
}
}
}
Is there someone out there who can spot any mistakes?