mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-12-26 02:40:37 +01:00
Added parsing of colors.txt.
This commit is contained in:
parent
e370ff0a42
commit
375812ea15
50
mapper.cpp
50
mapper.cpp
@ -7,13 +7,59 @@
|
||||
* =====================================================================
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Color {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
map<string, Color> parse_colors()
|
||||
{
|
||||
map<string, Color> parsed;
|
||||
|
||||
ifstream in;
|
||||
in.open("colors.txt", ifstream::in);
|
||||
if (!in.is_open()) {
|
||||
std::cerr << "File colors.txt does not exist" << std::endl;
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
while (in.good()) {
|
||||
string name;
|
||||
Color color;
|
||||
in >> name;
|
||||
if (name[0] == '#') {
|
||||
in.ignore(65536, '\n');
|
||||
in >> name;
|
||||
}
|
||||
while (name == "\n" && in.good()) {
|
||||
in >> name;
|
||||
}
|
||||
int r, g, b;
|
||||
in >> r;
|
||||
in >> g;
|
||||
in >> b;
|
||||
if (in.good()) {
|
||||
parsed[name] = color;
|
||||
color.r = r;
|
||||
color.g = g;
|
||||
color.b = b;
|
||||
}
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
void usage()
|
||||
{
|
||||
const char *usage_text = "minetestmapper.py [options]\n\
|
||||
@ -108,4 +154,6 @@ int main(int argc, char *argv[])
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
map<string, Color> colors = parse_colors();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user