Skip to content

Commit dff4589

Browse files
committedMay 21, 2014
Improve color parsing, hopefully fixes #7
1 parent d8cfe79 commit dff4589

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed
 

‎TileGenerator.cpp

+19-27
Original file line numberDiff line numberDiff line change
@@ -264,33 +264,26 @@ void TileGenerator::generate(const std::string &input, const std::string &output
264264

265265
void TileGenerator::parseColorsStream(std::istream &in)
266266
{
267+
char line[128], *p;
267268
while (in.good()) {
268-
string name;
269-
ColorEntry color;
270-
in >> name;
271-
if (name[0] == '#') {
272-
in.ignore(65536, '\n');
273-
in >> name;
274-
}
275-
while (name == "\n" && in.good()) {
276-
in >> name;
277-
}
278-
int r, g, b, a, t;
279-
in >> r;
280-
in >> g;
281-
in >> b;
282-
if(in.peek() != '\n') {
283-
in >> a;
284-
if(in.peek() != '\n')
285-
in >> t;
286-
else
287-
t = 0;
288-
} else
289-
a = 0xFF;
290-
if (in.good()) {
291-
color = ColorEntry(r,g,b,a,t);
292-
m_colors[name] = color;
293-
}
269+
in.getline(line, 128);
270+
p = line;
271+
while(*p++ != '\0')
272+
if(*p == '#') {
273+
*p = '\0'; // Cut off at the first #
274+
break;
275+
}
276+
277+
char name[75];
278+
uint8_t r, g, b, a, t;
279+
a = 255;
280+
t = 0;
281+
282+
sscanf(line, "%75s %hhu %hhu %hhu %hhu %hhu", name, &r, &g, &b, &a, &t);
283+
if(strlen(name) == 0)
284+
break;
285+
ColorEntry color = ColorEntry(r, g, b, a, t);
286+
m_colors[name] = color;
294287
}
295288
}
296289

@@ -663,4 +656,3 @@ inline int TileGenerator::getImageY(int val) const
663656
{
664657
return val + m_border;
665658
}
666-

0 commit comments

Comments
 (0)
Please sign in to comment.