mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-22 07:23:46 +01:00
Fix color parsing code (prev. commit)
Also make sure there's enough parameters: Name, R, G and B
This commit is contained in:
parent
173dd75b31
commit
0bf0d8e035
@ -261,24 +261,29 @@ void TileGenerator::generate(const std::string &input, const std::string &output
|
|||||||
|
|
||||||
void TileGenerator::parseColorsStream(std::istream &in)
|
void TileGenerator::parseColorsStream(std::istream &in)
|
||||||
{
|
{
|
||||||
char line[128], *p;
|
char line[128];
|
||||||
while (in.good()) {
|
while (in.good()) {
|
||||||
in.getline(line, 128);
|
in.getline(line, 128);
|
||||||
while(*p++ != '\0') {
|
|
||||||
|
for(char *p = line; *p; p++) {
|
||||||
if(*p != '#')
|
if(*p != '#')
|
||||||
continue;
|
continue;
|
||||||
*p = '\0'; // Cut off at the first #
|
*p = '\0'; // Cut off at the first #
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(strlen(line) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
char name[64];
|
char name[64];
|
||||||
unsigned int r, g, b, a, t;
|
unsigned int r, g, b, a, t;
|
||||||
a = 255;
|
a = 255;
|
||||||
t = 0;
|
t = 0;
|
||||||
|
int items = sscanf(line, "%64s %u %u %u %u %u", name, &r, &g, &b, &a, &t);
|
||||||
sscanf(line, "%64s %u %u %u %u %u", name, &r, &g, &b, &a, &t);
|
if(items < 4) {
|
||||||
if(strlen(name) == 0)
|
std:cerr << "Failed to parse color entry '" << line << "'." << std::endl;
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ColorEntry color = ColorEntry(r, g, b, a, t);
|
ColorEntry color = ColorEntry(r, g, b, a, t);
|
||||||
m_colorMap[name] = color;
|
m_colorMap[name] = color;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user