1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-10 02:33:00 +00:00

fixed hex color parsing

This commit is contained in:
Zeno Rogue
2024-05-27 12:29:37 +02:00
parent 83575d9d7d
commit f823a53f84
3 changed files with 12 additions and 3 deletions

View File

@@ -578,8 +578,16 @@ color_t exp_parser::parsecolor(int prio) {
if(token == "black") return 0x000000FF;
if(token == "white") return 0xFFFFFFFF;
color_t res;
int qty = sscanf(s.c_str(), "%x", &res);
if(qty == 0) throw hr_parse_exception("color parse error");
if(s.size() == 6) {
int qty = sscanf(s.c_str(), "%x", &res);
if(qty == 0) throw hr_parse_exception("color parse error");
return res * 256 + 0xFF;
}
else if(s.size() == 8) {
int qty = sscanf(s.c_str(), "%x", &res);
if(qty == 0) throw hr_parse_exception("color parse error");
return res;
}
return res;
}