Add support for setting flags for nodes in the colors.txt file.
These will allow special treatement for such nodes. See subsequent commits
This commit is contained in:
parent
99b3134810
commit
5660f71175
8
Color.h
8
Color.h
@ -21,14 +21,18 @@ struct Color {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ColorEntry {
|
struct ColorEntry {
|
||||||
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
|
enum flags {
|
||||||
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t): r(r), g(g), b(b), a(a), t(t) {};
|
FlagNone = 0x00,
|
||||||
|
};
|
||||||
|
ColorEntry(): r(0), g(0), b(0), a(0), t(0), f(0) {};
|
||||||
|
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t, uint8_t f): r(r), g(g), b(b), a(a), t(t), f(f) {};
|
||||||
inline Color to_color() const { return Color(r, g, b, a); }
|
inline Color to_color() const { return Color(r, g, b, a); }
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
uint8_t g;
|
uint8_t g;
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
uint8_t a;
|
uint8_t a;
|
||||||
uint8_t t;
|
uint8_t t;
|
||||||
|
uint8_t f;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Color &Color::operator=(const Color &c)
|
inline Color &Color::operator=(const Color &c)
|
||||||
|
@ -606,17 +606,19 @@ void TileGenerator::parseDataStream(std::istream &in, const std::string &filenam
|
|||||||
|
|
||||||
void TileGenerator::parseNodeColorsLine(const std::string &line, std::string name, istringstream &iline, int linenr, const std::string &filename)
|
void TileGenerator::parseNodeColorsLine(const std::string &line, std::string name, istringstream &iline, int linenr, const std::string &filename)
|
||||||
{
|
{
|
||||||
|
iline >> std::ws >> std::skipws;
|
||||||
if (iline.good() && iline.peek() == '-') {
|
if (iline.good() && iline.peek() == '-') {
|
||||||
char c;
|
char c;
|
||||||
iline >> c >> std::ws;
|
iline >> c >> std::ws;
|
||||||
if (iline.bad() || !iline.eof()) {
|
if (iline.fail() || !iline.eof()) {
|
||||||
std::cerr << filename << ":" << linenr << ": bad line in colors file (" << line << ")" << std::endl;
|
std::cerr << filename << ":" << linenr << ": bad line in colors file (" << line << ")" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_nodeColors.erase(name);
|
m_nodeColors.erase(name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int r, g, b, a, t;
|
int r, g, b, a, t, f;
|
||||||
|
std::string flags;
|
||||||
ColorEntry color;
|
ColorEntry color;
|
||||||
iline >> r;
|
iline >> r;
|
||||||
iline >> g;
|
iline >> g;
|
||||||
@ -626,10 +628,28 @@ void TileGenerator::parseNodeColorsLine(const std::string &line, std::string nam
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
a = 0xff;
|
a = 0xff;
|
||||||
iline >> a;
|
iline >> std::ws;
|
||||||
|
if (iline.good() && isdigit(iline.peek()))
|
||||||
|
iline >> a >> std::ws;
|
||||||
t = 0;
|
t = 0;
|
||||||
iline >> t;
|
if (iline.good() && isdigit(iline.peek()))
|
||||||
color = ColorEntry(r,g,b,a,t);
|
iline >> t >> std::ws;
|
||||||
|
if (iline.good() && !isdigit(iline.peek()))
|
||||||
|
iline >> flags >> std::ws;
|
||||||
|
f = 0;
|
||||||
|
if (!iline.fail() && flags != "") {
|
||||||
|
for(size_t i = 0; i < flags.length(); i++) {
|
||||||
|
if (flags[i] == ',')
|
||||||
|
flags[i]= ' ';
|
||||||
|
}
|
||||||
|
istringstream iflags(flags);
|
||||||
|
std::string flag;
|
||||||
|
iflags >> flag;
|
||||||
|
while (!iflags.fail()) {
|
||||||
|
iflags >> flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
color = ColorEntry(r,g,b,a,t,f);
|
||||||
if ((m_drawAlpha && a == 0xff) || (!m_drawAlpha && a != 0xff)) {
|
if ((m_drawAlpha && a == 0xff) || (!m_drawAlpha && a != 0xff)) {
|
||||||
// If drawing alpha, and the colors file contains both
|
// If drawing alpha, and the colors file contains both
|
||||||
// an opaque entry and a non-opaque entry for a name, prefer
|
// an opaque entry and a non-opaque entry for a name, prefer
|
||||||
@ -717,7 +737,7 @@ void TileGenerator::parseHeightMapNodesLine(const std::string &line, std::string
|
|||||||
m_nodeColors.erase(name);
|
m_nodeColors.erase(name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_nodeColors[name] = ColorEntry(0,0,0,255,1); // Dummy entry - but must not be transparent
|
m_nodeColors[name] = ColorEntry(0,0,0,255,1,0); // Dummy entry - but must not be transparent
|
||||||
}
|
}
|
||||||
// Don't care if not at eof (== really eol). We might be reading a colors.txt file...
|
// Don't care if not at eof (== really eol). We might be reading a colors.txt file...
|
||||||
if (iline.bad()) {
|
if (iline.bad()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user