Skip to content
Permalink
Browse files

Allow specifying location of colors.txt file

  • Loading branch information
sfan5 committed Aug 9, 2016
1 parent ab167d1 commit 73dab34d7cbe9490ee9e030f164e5f3df57a4829
Showing with 25 additions and 23 deletions.
  1. +2 −3 TileGenerator.cpp
  2. +23 −20 mapper.cpp
@@ -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);
}

@@ -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>
@@ -16,8 +7,6 @@
#include <stdexcept>
#include "TileGenerator.h"

using namespace std;

void usage()
{
const char *usage_text = "minetestmapper [options]\n"
@@ -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[] =
@@ -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) {
@@ -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;
@@ -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;

0 comments on commit 73dab34

Please sign in to comment.
You can’t perform that action at this time.