Skip to content

Commit

Permalink
Allow specifying location of colors.txt file
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Aug 9, 2016
1 parent ab167d1 commit 73dab34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
5 changes: 2 additions & 3 deletions TileGenerator.cpp
Expand Up @@ -230,9 +230,8 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
{
ifstream in;
in.open(fileName.c_str(), ifstream::in);
if (!in.is_open()) {
return;
}
if (!in.is_open())
throw std::runtime_error("Specified colors file could not be found.");
parseColorsStream(in);
}

Expand Down
43 changes: 23 additions & 20 deletions mapper.cpp
@@ -1,12 +1,3 @@
/*
* =====================================================================
* Version: 1.0
* Created: 22.08.2012 15:15:54
* Author: Miroslav Bendík
* Company: LinuxOS.sk
* =====================================================================
*/

#include <cstdlib>
#include <getopt.h>
#include <iostream>
Expand All @@ -16,8 +7,6 @@
#include <stdexcept>
#include "TileGenerator.h"

using namespace std;

void usage()
{
const char *usage_text = "minetestmapper [options]\n"
Expand All @@ -37,10 +26,17 @@ void usage()
" --backend <backend>\n"
" --geometry x:y+w+h\n"
" --zoom <zoomlevel>\n"
" --colors <colors.txt>\n"
"Color format: '#000000'\n";
std::cout << usage_text;
}

std::string search_colors()
{
// TBD
return "colors.txt";
}

int main(int argc, char *argv[])
{
static struct option long_options[] =
Expand All @@ -61,14 +57,15 @@ int main(int argc, char *argv[])
{"geometry", required_argument, 0, 'g'},
{"min-y", required_argument, 0, 'a'},
{"max-y", required_argument, 0, 'c'},
{"zoom", required_argument, 0, 'z'}
{"zoom", required_argument, 0, 'z'},
{"colors", required_argument, 0, 'C'},
};

string input;
string output;
std::string input;
std::string output;
std::string colors = "";

TileGenerator generator;
generator.parseColorsFile("colors.txt");
int option_index = 0;
int c = 0;
while (1) {
Expand Down Expand Up @@ -122,23 +119,23 @@ int main(int argc, char *argv[])
generator.setBackend(optarg);
break;
case 'a': {
istringstream iss;
std::istringstream iss;
iss.str(optarg);
int miny;
iss >> miny;
generator.setMinY(miny);
}
break;
case 'c': {
istringstream iss;
std::istringstream iss;
iss.str(optarg);
int maxy;
iss >> maxy;
generator.setMaxY(maxy);
}
break;
case 'g': {
istringstream geometry;
std::istringstream geometry;
geometry.str(optarg);
int x, y, w, h;
char c;
Expand All @@ -151,21 +148,27 @@ int main(int argc, char *argv[])
}
break;
case 'z': {
istringstream iss;
std::istringstream iss;
iss.str(optarg);
int zoom;
iss >> zoom;
generator.setZoom(zoom);
}
break;
case 'C':
colors = optarg;
break;
default:
exit(1);
}
}
if(colors == "")
colors = search_colors();
try {
generator.parseColorsFile(colors);
generator.generate(input, output);
} catch(std::runtime_error e) {
std::cout<<"Exception: "<<e.what()<<std::endl;
std::cerr << "Exception: " << e.what() << std::endl;
return 1;
}
return 0;
Expand Down

0 comments on commit 73dab34

Please sign in to comment.