- [NEW] aux_textfile()
- Implementant la càrrega del nivell
This commit is contained in:
57
source/aux_textfile.cpp
Normal file
57
source/aux_textfile.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "aux_textfile.h"
|
||||
|
||||
#include "jgame.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace textfile
|
||||
{
|
||||
char *buffer = nullptr;
|
||||
int fsize = 0;
|
||||
int p = 0;
|
||||
|
||||
const bool open(std::string filename)
|
||||
{
|
||||
buffer = file::getFileBuffer(filename.c_str());
|
||||
p = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
std::string getNextToken()
|
||||
{
|
||||
char token[255];
|
||||
int tpos = 0;
|
||||
|
||||
// Ignore whitespace
|
||||
while (p<fsize && buffer[p]<=32 ) p++;
|
||||
|
||||
// Grab token
|
||||
while (p<fsize && buffer[p]>32 ) token[tpos++]=buffer[p++];
|
||||
token[tpos]=0;
|
||||
|
||||
return std::string(token);
|
||||
}
|
||||
|
||||
const bool searchToken(std::string token)
|
||||
{
|
||||
while (p<fsize && getNextToken() != token) p++;
|
||||
return p<fsize;
|
||||
}
|
||||
|
||||
std::string getStringValue(std::string token)
|
||||
{
|
||||
textfile::searchToken(token);
|
||||
textfile::searchToken("=");
|
||||
return textfile::getNextToken();
|
||||
}
|
||||
|
||||
const int getIntValue(std::string token)
|
||||
{
|
||||
return std::stoi(getStringValue(token));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user