diff --git a/source/aux_textfile.cpp b/source/aux_textfile.cpp index 1db7cf5..cb17782 100644 --- a/source/aux_textfile.cpp +++ b/source/aux_textfile.cpp @@ -9,9 +9,20 @@ namespace textfile int fsize = 0; int p = 0; + const int toInt(std::string token) + { + int value = 0; + for (std::size_t i=0; i57) return 0; + value = (value*10) + (token[i]-48); + } + return value; + } + const bool open(std::string filename) { - buffer = file::getFileBuffer(filename.c_str()); + buffer = file::getFileBuffer(filename.c_str(), &fsize); p = 0; return true; @@ -52,6 +63,6 @@ namespace textfile const int getIntValue(std::string token) { - return std::stoi(getStringValue(token)); + return toInt(getStringValue(token)); } } diff --git a/source/aux_textfile.h b/source/aux_textfile.h index f0d2ff4..a5178b2 100644 --- a/source/aux_textfile.h +++ b/source/aux_textfile.h @@ -4,6 +4,8 @@ namespace textfile { + const int toInt(std::string token); + const bool open(std::string filename); void close(); diff --git a/source/proc_mapa.cpp b/source/proc_mapa.cpp index 6dcd965..48b96a8 100644 --- a/source/proc_mapa.cpp +++ b/source/proc_mapa.cpp @@ -42,7 +42,7 @@ namespace mapa do { textfile::searchToken("LEVEL"); - } while (std::stoi(textfile::getNextToken()) != game::getConfig("fase")); + } while (textfile::toInt(textfile::getNextToken()) != game::getConfig("fase")); const int tileset = textfile::getIntValue("tileset"); arounders::orientacio_inicial = textfile::getIntValue("orientacio"); @@ -58,10 +58,10 @@ namespace mapa accions::corda = textfile::getIntValue("corda"); ini_x = textfile::getIntValue("inici"); - ini_y = std::stoi(textfile::getNextToken()); + ini_y = textfile::toInt(textfile::getNextToken()); fin_x = textfile::getIntValue("final"); - fin_y = std::stoi(textfile::getNextToken()); + fin_y = textfile::toInt(textfile::getNextToken()); //int tilemap[200]; //for (int y=0; y<10; ++y) for (int x=0; x<10; ++x) fscanf(f, "%i", &tilemap[x+y*20]); @@ -76,13 +76,13 @@ namespace mapa for (int y=0; y<10; ++y) for (int x=0; x<10; ++x) { - int tile; fscanf(f, "%i", &tile); + int tile = textfile::toInt(textfile::getNextToken()); if (tile > 0) draw::draw(x*16, y*16, 16, 16, (tile-1)*16, tileset*16); } draw::freeSurface(tiles); - textfile::fclose(); + textfile::close(); draw::surface *marcador = draw::loadSurface("marcador.gif"); draw::setSource(marcador);