EntityConverter Target handled by pre-scan
This commit is contained in:
parent
096cffb115
commit
98abd5c184
@ -24,19 +24,16 @@
|
||||
|
||||
|
||||
|
||||
EntityConverter::EntityConverter(std::string entityMapFile)
|
||||
EntityConverter::EntityConverter(std::string entityMapFile, std::string reflexMapFile)
|
||||
{
|
||||
//Open .ent mapping file
|
||||
std::ifstream fin;
|
||||
fin.open(entityMapFile);
|
||||
|
||||
if ( ! fin.is_open() ) {
|
||||
throw std::ios::failure( "Error opening .ent file" );
|
||||
}
|
||||
std::ifstream entFin;
|
||||
entFin.open(entityMapFile);
|
||||
|
||||
if ( entFin.is_open() ) {
|
||||
//Read .ent contents into pickup map
|
||||
std::string line;
|
||||
while (std::getline(fin, line)) {
|
||||
while (std::getline(entFin, line)) {
|
||||
std::istringstream iss(line);
|
||||
// Reflex ID corresponds to xonotic pickup name
|
||||
int id;
|
||||
@ -44,19 +41,69 @@ EntityConverter::EntityConverter(std::string entityMapFile)
|
||||
if ( ! (iss >> id >> pickup)) {
|
||||
throw std::runtime_error( "format error in .ent file" );
|
||||
}
|
||||
pickupMapping.insert ( std::pair<int, std::string>(id, pickup) );
|
||||
pickupMapping_.insert ( std::pair<int, std::string>(id, pickup) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw std::ios::failure( "Error: EntityConverter failed to open .ent file" );
|
||||
}
|
||||
entFin.close();
|
||||
|
||||
|
||||
//Open .map file
|
||||
std::ifstream mapFin;
|
||||
mapFin.open(reflexMapFile);
|
||||
|
||||
if ( mapFin.is_open() ) {
|
||||
//Extract the source type of targets (teleporters or jump pads)
|
||||
std::string line;
|
||||
std::string trash;
|
||||
std::string targetName;
|
||||
while (std::getline(mapFin, line)) {
|
||||
if ( line.find("type Teleporter") != std::string::npos) {
|
||||
std::getline(mapFin, 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(mapFin, 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") );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw std::ios::failure( "Error: EntityConverter failed to open .map file" );
|
||||
}
|
||||
mapFin.close();
|
||||
|
||||
//DEBUG
|
||||
//printMapping();
|
||||
//printTargetSources();
|
||||
}
|
||||
|
||||
|
||||
// DEBUG
|
||||
void EntityConverter::printMapping()
|
||||
{
|
||||
std::map<int, std::string>::iterator it;
|
||||
for (it=pickupMapping.begin(); it!=pickupMapping.end(); ++it)
|
||||
for (it=pickupMapping_.begin(); it!=pickupMapping_.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << std::endl;
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
void EntityConverter::printTargetSources()
|
||||
{
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for (it=targetMap_.begin(); it!=targetMap_.end(); ++it)
|
||||
std::cout << it->first << " => " << it->second << std::endl;
|
||||
}
|
||||
|
||||
|
||||
std::string EntityConverter::getAttributeType(std::string line)
|
||||
@ -127,7 +174,7 @@ std::vector<std::string> EntityConverter::convert(std::vector<std::string> lines
|
||||
|
||||
if ( havePosition && havePickupID ) {
|
||||
std::stringstream oss;
|
||||
oss << "\"classname\" \"" << pickupMapping[pickupID] << "\"" << std::endl;
|
||||
oss << "\"classname\" \"" << pickupMapping_[pickupID] << "\"" << std::endl;
|
||||
convertedLines.push_back ( oss.str() );
|
||||
// coordinates reordered to x, z, y
|
||||
std::stringstream oss2;
|
||||
@ -157,7 +204,7 @@ std::vector<std::string> EntityConverter::convert(std::vector<std::string> lines
|
||||
convertedLines.push_back ( oss.str() );
|
||||
}
|
||||
else if ( type == "Teleporter" ) { ///TELEPORTER
|
||||
/* if ( lines.size() < 2 ) {
|
||||
if ( lines.size() < 2 ) {
|
||||
throw std::runtime_error("error: Teleport entity requires at least 2 lines");
|
||||
}
|
||||
std::istringstream iss2(lines[1]);
|
||||
@ -215,7 +262,12 @@ std::vector<std::string> EntityConverter::convert(std::vector<std::string> lines
|
||||
|
||||
if ( havePosition && haveName) {
|
||||
//**! no way to tell if teleporter or jump pad dest from targetName alone
|
||||
if ( targetMap_[targetName] == "Teleporter") {
|
||||
convertedLines.push_back ( "\"classname\" \"misc_teleporter_dest\"\n" );
|
||||
}
|
||||
else if ( targetMap_[targetName] == "JumpPad") {
|
||||
convertedLines.push_back ( "\"classname\" \"target_push\"\n" );
|
||||
}
|
||||
std::stringstream oss;
|
||||
oss << "\"targetname\" \"" << targetName << "\"\n";
|
||||
convertedLines.push_back ( oss.str() );
|
||||
@ -232,7 +284,6 @@ std::vector<std::string> EntityConverter::convert(std::vector<std::string> lines
|
||||
convertedLines.push_back (oss3.str() );
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if ( type == "Effect" ) { ///EFFECT
|
||||
// to be implemented
|
||||
|
@ -63,13 +63,18 @@
|
||||
class EntityConverter
|
||||
{
|
||||
public:
|
||||
EntityConverter(std::string entityMapFile);
|
||||
EntityConverter(std::string entityMapFile, std::string reflexMapFile);
|
||||
std::vector<std::string> convert(std::vector<std::string> lines);
|
||||
void printMapping(); //DEBUG
|
||||
protected:
|
||||
private:
|
||||
std::string getAttributeType(std::string line);
|
||||
std::map<int, std::string> pickupMapping;
|
||||
void printMapping(); //DEBUG
|
||||
void printTargetSources(); //DEBUG
|
||||
|
||||
// Map Reflex pickup IDs to Xonotic pickup identifiers
|
||||
std::map<int, std::string> pickupMapping_;
|
||||
// Map targets (by name) to their source type
|
||||
std::map<std::string, std::string> targetMap_;
|
||||
};
|
||||
|
||||
#endif //ENTITY_CONVERTER_HPP
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "oopless-parser.hpp"
|
||||
#include "brushdef.hpp"
|
||||
#include "EntityConverter.hpp"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
Loading…
Reference in New Issue
Block a user