diff --git a/ReflexToQ3/main.cpp b/ReflexToQ3/main.cpp index acb2693..7bf7284 100644 --- a/ReflexToQ3/main.cpp +++ b/ReflexToQ3/main.cpp @@ -13,10 +13,15 @@ #include "oopless-parser.hpp" #include "brushdef.hpp" -#define ARG_INPUT_SHORTALIAS "i" -#define ARG_OUTPUT_SHORTALIAS "o" using namespace std; +//ease of reading function pointer +typedef void (*brushdef) (std::stringstream &, + const std::vector &); + +#define ARG_INPUT_SHORTALIAS "i" +#define ARG_OUTPUT_SHORTALIAS "o" +#define ARG_BRUSHFORMAT "gtk" cxxopts::Options arguments(int ac, char ** av) { vector parg = {"input", "output"}; cxxopts::Options o("reflex2q3", @@ -29,7 +34,7 @@ cxxopts::Options arguments(int ac, char ** av) { ("o,output", "required, output map file, for idTech 3 or similar map editors", cxxopts::value(), "FILE") - ("gtk", + (ARG_BRUSHFORMAT, "optional, output in GTK Radiant's brush definition format") ("e,ent", "optional, convert game entities given a table of equivalents", @@ -50,12 +55,9 @@ cxxopts::Options arguments(int ac, char ** av) { bool convert_worldspawn(const cxxopts::Options &o, queue > &q) { -//ease of reading -typedef void (*brushdef) (std::stringstream &, - const std::vector &); bool is_ok = false; brushdef fn = &brushdef_net; - if (o.count("gtk")) { + if (o.count(ARG_BRUSHFORMAT)) { fn = &brushdef_gtk; } try { @@ -81,26 +83,48 @@ typedef void (*brushdef) (std::stringstream &, return is_ok; } -// wip: current a print out of all entities -bool convert_entities(const cxxopts::Options &o, queue > &q) { - vector entity; +void print_entities(queue > &q) { + vector entity; do { entity = q.front(); + cout << "--------------------------" << endl; for (const string &s : entity) { cout << s << endl; } + cout << "--------------------------" << endl; q.pop(); - } while (!q.empty()); - return true; + } while (!q.empty()); +} + + +void convert_entities(const cxxopts::Options &o, queue > &q) { + string entfile = o["e"].as(); + if (entfile.empty()) { + cout << "No entity data file given" + "- skipping entity conversion" << endl; + return; + } + EntityConverter e(entfile, o[ARG_INPUT_SHORTALIAS].as()); + ofstream fout(o[ARG_OUTPUT_SHORTALIAS].as(), ios::app); + brushdef fn = &brushdef_net; + vector entity; + if (o.count(ARG_BRUSHFORMAT)) { + fn = &brushdef_gtk; + } + do { + entity = q.front(); + write(entity, fout, fn, e); + q.pop(); + } while(!q.empty()); } int main(int argc, char** argv) { - string entityfile; cxxopts::Options p = arguments(argc, argv); queue > entities; bool is_ok = convert_worldspawn(p, entities); +// print_entities(entities); convert_entities(p, entities); return(0); }