2017-04-12 12:48:29 +05:30
|
|
|
#include "v8mapparser.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2017-04-06 16:00:53 +05:30
|
|
|
using namespace std;
|
2017-04-12 12:48:29 +05:30
|
|
|
const bool V8MapParser::LoadMap(const char* _kpcFileName) {
|
2017-04-05 18:08:54 +05:30
|
|
|
std::ifstream InFile;
|
|
|
|
EParserState eState = PARSERSTATE_UNKNOWN;
|
|
|
|
|
|
|
|
InFile.open(_kpcFileName, std::ios::in);
|
|
|
|
if(InFile.is_open())
|
|
|
|
{
|
|
|
|
std::string Line;
|
|
|
|
bool bAdvance = true;
|
|
|
|
bool bGoing = true;
|
|
|
|
while(bGoing)
|
|
|
|
{
|
|
|
|
if(bAdvance)
|
|
|
|
{
|
|
|
|
if(!std::getline(InFile, Line))
|
|
|
|
{
|
|
|
|
bGoing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bAdvance = true;
|
|
|
|
if(eState == PARSERSTATE_UNKNOWN)
|
|
|
|
{
|
2017-04-07 05:35:11 +05:30
|
|
|
if(Line.find(KEYWORD_ENTITY) != string::npos)
|
2017-04-05 18:08:54 +05:30
|
|
|
{
|
|
|
|
eState = PARSERSTATE_ENTITY;
|
|
|
|
continue;
|
2017-04-07 05:35:11 +05:30
|
|
|
} else if (Line.find(KEYWORD_PREFAB) != string::npos || Line.find(KEYWORD_GLOBAL) != string::npos) {
|
2017-04-05 18:08:54 +05:30
|
|
|
// prefab and global share an indentation level
|
|
|
|
// both encapsulate similar objects
|
|
|
|
eState = PARSERSTATE_PREFAB;
|
|
|
|
continue;
|
2017-04-06 16:00:53 +05:30
|
|
|
} else {
|
|
|
|
cout << "Warning: PARSERSTATE_UNKNOWN and no cases met." << endl;
|
2017-04-05 18:08:54 +05:30
|
|
|
}
|
|
|
|
} else if (eState == PARSERSTATE_PREFAB) {
|
|
|
|
eState = this->ParsePrefab(Line);
|
|
|
|
}
|
|
|
|
else if(eState == PARSERSTATE_ENTITY)
|
|
|
|
{
|
|
|
|
eState = this->ParseEntity(Line);
|
|
|
|
}
|
|
|
|
else if(eState == PARSERSTATE_WORLDSPAWN)
|
|
|
|
{
|
|
|
|
eState = this->ParseWorldSpawn(Line);
|
|
|
|
}
|
|
|
|
else if(eState == PARSERSTATE_BRUSH)
|
|
|
|
{
|
|
|
|
eState = this->ParseBrush(Line);
|
|
|
|
//bAdvance = false;
|
|
|
|
}
|
|
|
|
else if(eState == PARSERSTATE_VERTEX)
|
|
|
|
{
|
|
|
|
eState = this->ParseVertex(Line);
|
|
|
|
if(eState != PARSERSTATE_VERTEX)
|
|
|
|
{
|
|
|
|
bAdvance = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(eState == PARSERSTATE_FACE)
|
|
|
|
{
|
|
|
|
eState = this->ParseFace(Line);
|
|
|
|
if(eState != PARSERSTATE_FACE)
|
|
|
|
{
|
|
|
|
bAdvance = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InFile.close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2017-04-12 12:48:29 +05:30
|
|
|
EParserState V8MapParser::ParsePrefab(const std::string _Line) {
|
2017-04-05 18:08:54 +05:30
|
|
|
// this is going with the idea that its possible to correctly parse the map file
|
|
|
|
// if prefabs are simply broken and de-indented.
|
|
|
|
|
|
|
|
// typically entities are listed first, then brushes, but just in case.
|
2017-04-07 05:35:11 +05:30
|
|
|
if (_Line.find(KEYWORD_ENTITY) != string::npos) {
|
2017-04-05 18:08:54 +05:30
|
|
|
return PARSERSTATE_ENTITY;
|
|
|
|
} else {
|
|
|
|
return PARSERSTATE_BRUSH;
|
|
|
|
}
|
|
|
|
}
|