Search more locations for the colors.txt file
The colors.txt file can now be located: - in the directory of the world being mapped - in the user's private minetest directory ($HOME/.minetest) - in the current directory as a last resort The location can also be specified using a command-line option
This commit is contained in:
parent
56efa78cd3
commit
e97e19921c
12
README.rst
12
README.rst
@ -55,6 +55,18 @@ and `-o` (output image path).
|
|||||||
Parameters
|
Parameters
|
||||||
^^^^^^^^^^
|
^^^^^^^^^^
|
||||||
|
|
||||||
|
colors <file>:
|
||||||
|
Filename of the color definition file to use.
|
||||||
|
|
||||||
|
By default, a file 'colors.txt' is used, which may be located:
|
||||||
|
|
||||||
|
* In the directory of the world being mapped
|
||||||
|
|
||||||
|
* In the user's private directory ($HOME/.minetest)
|
||||||
|
|
||||||
|
* For compatibility, in the current directory as a last resort.
|
||||||
|
This causes a warning message to be printed.
|
||||||
|
|
||||||
bgcolor:
|
bgcolor:
|
||||||
Background color of image, `--bgcolor #ffffff`
|
Background color of image, `--bgcolor #ffffff`
|
||||||
|
|
||||||
|
57
mapper.cpp
57
mapper.cpp
@ -26,6 +26,7 @@ void usage()
|
|||||||
const char *usage_text = "minetestmapper [options]\n"
|
const char *usage_text = "minetestmapper [options]\n"
|
||||||
" -i/--input <world_path>\n"
|
" -i/--input <world_path>\n"
|
||||||
" -o/--output <output_image.png>\n"
|
" -o/--output <output_image.png>\n"
|
||||||
|
" --colors <file>\n"
|
||||||
" --bgcolor <color>\n"
|
" --bgcolor <color>\n"
|
||||||
" --scalecolor <color>\n"
|
" --scalecolor <color>\n"
|
||||||
" --playercolor <color>\n"
|
" --playercolor <color>\n"
|
||||||
@ -62,6 +63,7 @@ int main(int argc, char *argv[])
|
|||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"input", required_argument, 0, 'i'},
|
{"input", required_argument, 0, 'i'},
|
||||||
{"output", required_argument, 0, 'o'},
|
{"output", required_argument, 0, 'o'},
|
||||||
|
{"colors", required_argument, 0, 'C'},
|
||||||
{"bgcolor", required_argument, 0, 'b'},
|
{"bgcolor", required_argument, 0, 'b'},
|
||||||
{"scalecolor", required_argument, 0, 's'},
|
{"scalecolor", required_argument, 0, 's'},
|
||||||
{"origincolor", required_argument, 0, 'r'},
|
{"origincolor", required_argument, 0, 'r'},
|
||||||
@ -89,15 +91,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
string input;
|
string input;
|
||||||
string output;
|
string output;
|
||||||
|
string colorsFile;
|
||||||
bool foundGeometrySpec = false;
|
bool foundGeometrySpec = false;
|
||||||
|
|
||||||
TileGenerator generator;
|
TileGenerator generator;
|
||||||
try {
|
|
||||||
generator.parseColorsFile("colors.txt");
|
|
||||||
} catch(std::runtime_error e) {
|
|
||||||
std::cout<<"Exception: "<<e.what()<<std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
@ -121,6 +118,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'o':
|
case 'o':
|
||||||
output = optarg;
|
output = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
colorsFile = optarg;
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
generator.setBgColor(optarg);
|
generator.setBgColor(optarg);
|
||||||
break;
|
break;
|
||||||
@ -323,7 +323,51 @@ int main(int argc, char *argv[])
|
|||||||
std::cout<<"Command-line error: "<<e.what()<<std::endl;
|
std::cout<<"Command-line error: "<<e.what()<<std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!colorsFile.empty()) {
|
||||||
|
generator.parseColorsFile(colorsFile);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bool colorsFound = false;
|
||||||
|
char *homedir;
|
||||||
|
colorsFile = input + PATH_SEPARATOR + "colors.txt";
|
||||||
|
|
||||||
|
try {
|
||||||
|
generator.parseColorsFile(colorsFile);
|
||||||
|
colorsFound = true;
|
||||||
|
} catch (std::runtime_error e) {
|
||||||
|
// Ignore failure to locate world-specific colors file
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!colorsFound && (homedir = getenv("HOME"))) {
|
||||||
|
colorsFile = string(homedir) + PATH_SEPARATOR + ".minetest" + PATH_SEPARATOR + "colors.txt";
|
||||||
|
try {
|
||||||
|
generator.parseColorsFile(colorsFile);
|
||||||
|
colorsFound = true;
|
||||||
|
} catch (std::runtime_error e) {
|
||||||
|
// Ignore failure to locate user private colors file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: look for system-wide colors file (?) (e.g. /usr/share/games/minetest/colors.txt)
|
||||||
|
// (location should be subject to a build-time configuration of the installation directory)
|
||||||
|
|
||||||
|
if (!colorsFound) {
|
||||||
|
try {
|
||||||
|
generator.parseColorsFile("colors.txt");
|
||||||
|
// I hope this is not obnoxious to windows users ?
|
||||||
|
cerr << "Warning: Using colors.txt in current directory as a last resort." << std::endl
|
||||||
|
<< " Preferably, store the colors file in the world directory" << std::endl;
|
||||||
|
if (homedir)
|
||||||
|
cerr << " or in the private minetest directory ($HOME/.minetest)." << std::endl;
|
||||||
|
cerr << " It can also be specified on the command-line" << std::endl;
|
||||||
|
} catch(std::runtime_error e) {
|
||||||
|
throw std::runtime_error("Failed to find or failed to open a colors.txt file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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::cout<<"Exception: "<<e.what()<<std::endl;
|
||||||
@ -331,3 +375,4 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user