mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-12-26 02:40:37 +01:00
Allow specifying location of colors.txt file
This commit is contained in:
parent
ab167d1c68
commit
73dab34d7c
@ -230,9 +230,8 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
|
|||||||
{
|
{
|
||||||
ifstream in;
|
ifstream in;
|
||||||
in.open(fileName.c_str(), ifstream::in);
|
in.open(fileName.c_str(), ifstream::in);
|
||||||
if (!in.is_open()) {
|
if (!in.is_open())
|
||||||
return;
|
throw std::runtime_error("Specified colors file could not be found.");
|
||||||
}
|
|
||||||
parseColorsStream(in);
|
parseColorsStream(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
43
mapper.cpp
43
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 <cstdlib>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -16,8 +7,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "TileGenerator.h"
|
#include "TileGenerator.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
const char *usage_text = "minetestmapper [options]\n"
|
const char *usage_text = "minetestmapper [options]\n"
|
||||||
@ -37,10 +26,17 @@ void usage()
|
|||||||
" --backend <backend>\n"
|
" --backend <backend>\n"
|
||||||
" --geometry x:y+w+h\n"
|
" --geometry x:y+w+h\n"
|
||||||
" --zoom <zoomlevel>\n"
|
" --zoom <zoomlevel>\n"
|
||||||
|
" --colors <colors.txt>\n"
|
||||||
"Color format: '#000000'\n";
|
"Color format: '#000000'\n";
|
||||||
std::cout << usage_text;
|
std::cout << usage_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string search_colors()
|
||||||
|
{
|
||||||
|
// TBD
|
||||||
|
return "colors.txt";
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
@ -61,14 +57,15 @@ int main(int argc, char *argv[])
|
|||||||
{"geometry", required_argument, 0, 'g'},
|
{"geometry", required_argument, 0, 'g'},
|
||||||
{"min-y", required_argument, 0, 'a'},
|
{"min-y", required_argument, 0, 'a'},
|
||||||
{"max-y", required_argument, 0, 'c'},
|
{"max-y", required_argument, 0, 'c'},
|
||||||
{"zoom", required_argument, 0, 'z'}
|
{"zoom", required_argument, 0, 'z'},
|
||||||
|
{"colors", required_argument, 0, 'C'},
|
||||||
};
|
};
|
||||||
|
|
||||||
string input;
|
std::string input;
|
||||||
string output;
|
std::string output;
|
||||||
|
std::string colors = "";
|
||||||
|
|
||||||
TileGenerator generator;
|
TileGenerator generator;
|
||||||
generator.parseColorsFile("colors.txt");
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -122,7 +119,7 @@ int main(int argc, char *argv[])
|
|||||||
generator.setBackend(optarg);
|
generator.setBackend(optarg);
|
||||||
break;
|
break;
|
||||||
case 'a': {
|
case 'a': {
|
||||||
istringstream iss;
|
std::istringstream iss;
|
||||||
iss.str(optarg);
|
iss.str(optarg);
|
||||||
int miny;
|
int miny;
|
||||||
iss >> miny;
|
iss >> miny;
|
||||||
@ -130,7 +127,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'c': {
|
case 'c': {
|
||||||
istringstream iss;
|
std::istringstream iss;
|
||||||
iss.str(optarg);
|
iss.str(optarg);
|
||||||
int maxy;
|
int maxy;
|
||||||
iss >> maxy;
|
iss >> maxy;
|
||||||
@ -138,7 +135,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'g': {
|
case 'g': {
|
||||||
istringstream geometry;
|
std::istringstream geometry;
|
||||||
geometry.str(optarg);
|
geometry.str(optarg);
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
char c;
|
char c;
|
||||||
@ -151,21 +148,27 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'z': {
|
case 'z': {
|
||||||
istringstream iss;
|
std::istringstream iss;
|
||||||
iss.str(optarg);
|
iss.str(optarg);
|
||||||
int zoom;
|
int zoom;
|
||||||
iss >> zoom;
|
iss >> zoom;
|
||||||
generator.setZoom(zoom);
|
generator.setZoom(zoom);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
colors = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(colors == "")
|
||||||
|
colors = search_colors();
|
||||||
try {
|
try {
|
||||||
|
generator.parseColorsFile(colors);
|
||||||
generator.generate(input, output);
|
generator.generate(input, output);
|
||||||
} catch(std::runtime_error e) {
|
} catch(std::runtime_error e) {
|
||||||
std::cout<<"Exception: "<<e.what()<<std::endl;
|
std::cerr << "Exception: " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user