/* * ===================================================================================== * * Filename: EntityConverter.hpp * * Description: Convert reflex entities to xonotic entities * - Simple; operates on single entity at a time * - Only context provided is information on what entities are related. * (i.e. a teleport and it's destination) Can get this information * through the pre-scan constructor of the .map file or by providing * a queue of all the entities in the file. * - Throws exceptions upon encountering malformed entities and when * IO errors occur during object instantiation * * Version: 1.0 * Created: 05/27/2017 08:21:14 AM * Revision: none * Compiler: gcc * * Author: suhrke@teknik.io * * ===================================================================================== */ #ifndef ENTITY_CONVERTER_HPP #define ENTITY_CONVERTER_HPP #include #include #include #include class EntityConverter { public: /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: Constructor * Description: Creates entity format mapping * CAUTION: Requires matchRelated method to be called after this * Requires: .ent filename for mapping entities from reflex format to xonotic format * THROWS: runtime_error on .ent format error * THROWS: std::ios::failure on IO failure *-------------------------------------------------------------------------------------- */ EntityConverter(std::string entityMapFile); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: Constructor * Description: Creates entity format mapping and pre-scans for related entities * Parameter: string entityMapFile, file maps source to target entity formats * Parameter: string reflexMapFile, for pre-scan * THROWS: runtime_error on .ent format error * THROWS: std::ios::failure on IO failure *-------------------------------------------------------------------------------------- */ EntityConverter(std::string entityMapFile, std::string reflexMapFile); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: EntityConverter :: convert * Description: Converts a single entity from reflex to xonotic format * Parameter: vector of strings lines, lines that comprise a single entity * Return: vector of strings, single entity in the converted format * THROWS: runtime_error on malformed .map file * THROWS: runtime_error when called before related entities are matched *-------------------------------------------------------------------------------------- */ std::vector convert(std::vector lines); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: EntityConverter :: matchRelated * Description: Finds related entities (targets of teleports, etc), call after parsing * the entire .map * Parameter: queue of vector of string entities, ALL entities in a .map file * THROWS: runtime_error when encountering malformed entity *-------------------------------------------------------------------------------------- */ void matchRelated(std::queue> entities); protected: private: /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: EntityConverter :: getAttributeType * Description: Extracts the type from a line * Parameter: string "line", entity keyword followed by the type *-------------------------------------------------------------------------------------- */ std::string getAttributeType(std::string line); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: EntityConverter :: mapEntities * Description: Prepare pickupMapping_ * Parameter: string mapFile, filename of pickup mapping * Return: true if no error, false if error *-------------------------------------------------------------------------------------- */ void mapEntities(std::string mapFile); /* *-------------------------------------------------------------------------------------- * Class: EntityConverter * Method: EntityConverter :: convert~EntityName~ * Description: Multiple methods to convert entity from reflex to xonotic format * Parameter: vector of strings entity, multi-lined entity * Return: vector of strings, the converted entity *-------------------------------------------------------------------------------------- */ std::vector convertPickup(std::vector &entity); std::vector convertPlayerSpawn(std::vector &entity); std::vector convertJumpPad(std::vector &entity); std::vector convertTeleporter(std::vector &entity); std::vector convertTarget(std::vector &entity); std::vector convertRaceStart(std::vector &entity); std::vector convertRaceFinish(std::vector &entity); void printMapping(); //DEBUG void printTargetSources(); //DEBUG // Related entities must be matched prior to entity conversion bool areEntitiesMatched_; // Map Reflex pickup IDs to Xonotic pickup identifiers std::map pickupMapping_; // Map targets (by name) to their source type std::map targetMap_; }; #endif //ENTITY_CONVERTER_HPP