queue scan added, Catch added for EntityConverter tests
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@ -49,25 +50,8 @@ EntityConverter::EntityConverter(std::string entityMapFile, std::string reflexMa
|
||||
if ( fin.is_open() ) {
|
||||
//Extract the source type of targets (teleporters or jump pads)
|
||||
std::string line;
|
||||
std::string trash;
|
||||
std::string targetName;
|
||||
while (std::getline(fin, line)) {
|
||||
if ( line.find("type Teleporter") != std::string::npos) {
|
||||
std::getline(fin, line);
|
||||
std::istringstream iss(line);
|
||||
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||
throw std::runtime_error( "format error in .map file");
|
||||
}
|
||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "Teleporter") );
|
||||
}
|
||||
else if ( line.find("type JumpPad") != std::string::npos) {
|
||||
std::getline(fin, line);
|
||||
std::istringstream iss(line);
|
||||
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||
throw std::runtime_error( "format error in .map file");
|
||||
}
|
||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "JumpPad") );
|
||||
}
|
||||
addIfRelated(line, fin);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -85,7 +69,11 @@ EntityConverter::EntityConverter(std::string entityMapFile, std::string reflexMa
|
||||
|
||||
/*
|
||||
*--------------------------------------------------------------------------------------
|
||||
* !-- Not sure if this is used the same way as the pre-scan was --!
|
||||
* Class: EntityConverter
|
||||
* Method: EntityConverter :: matchRelated
|
||||
* Description: Read through entities, matching related as necessary
|
||||
* Note: For now, accomplishes the same goal as the pre-scan
|
||||
* constructor
|
||||
*--------------------------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
@ -95,8 +83,22 @@ EntityConverter::matchRelated(std::queue<std::vector<std::string>> entities)
|
||||
std::cerr << "Related entities are already matched, doing nothing" << std::endl;
|
||||
}
|
||||
else {
|
||||
//Same as pre-scan or convert and pass back all converted entities?
|
||||
while ( ! entities.empty() ) {
|
||||
std::vector<std::string> entity = entities.front();
|
||||
entities.pop();
|
||||
|
||||
std::stringstream ss;
|
||||
std::copy(entity.begin(), entity.end(),
|
||||
std::ostream_iterator<std::string>(ss, "\n"));
|
||||
|
||||
std::string nextLine;
|
||||
if ( getline(ss, nextLine )) {
|
||||
addIfRelated(nextLine, ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
areEntitiesMatched_ = true;
|
||||
}
|
||||
|
||||
|
||||
@ -197,6 +199,32 @@ EntityConverter::mapEntities(std::string mapFile)
|
||||
|
||||
|
||||
|
||||
void
|
||||
EntityConverter::addIfRelated(std::string &line, std::istream &is)
|
||||
{
|
||||
std::string trash;
|
||||
std::string targetName;
|
||||
if ( line.find("type Teleporter") != std::string::npos) {
|
||||
std::getline(is, line);
|
||||
std::istringstream iss(line);
|
||||
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||
throw std::runtime_error( "format error in .map file");
|
||||
}
|
||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "Teleporter") );
|
||||
}
|
||||
else if ( line.find("type JumpPad") != std::string::npos) {
|
||||
std::getline(is, line);
|
||||
std::istringstream iss(line);
|
||||
if ( ! (iss >> trash >> trash >> targetName)) {
|
||||
throw std::runtime_error( "format error in .map file");
|
||||
}
|
||||
targetMap_.insert ( std::pair<std::string, std::string>(targetName, "JumpPad") );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
EntityConverter::convertPickup(std::vector<std::string> &lines)
|
||||
{
|
||||
|
Reference in New Issue
Block a user