mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-08-29 08:52:19 +00:00
Merge pull request #408 from madewokherd/parsecolor
util: Parse token as color, not overall string.
This commit is contained in:
commit
c87e5b600d
10
util.cpp
10
util.cpp
@ -615,17 +615,17 @@ color_t exp_parser::parsecolor(int prio) {
|
|||||||
string token = next_token();
|
string token = next_token();
|
||||||
if(params.count(token)) return (color_t) real(params[token]->get_cld());
|
if(params.count(token)) return (color_t) real(params[token]->get_cld());
|
||||||
|
|
||||||
auto p = find_color_by_name(s);
|
auto p = find_color_by_name(token);
|
||||||
if(p) return (p->second << 8) | 0xFF;
|
if(p) return (p->second << 8) | 0xFF;
|
||||||
|
|
||||||
color_t res;
|
color_t res;
|
||||||
if(s.size() == 6) {
|
if(token.size() == 6) {
|
||||||
int qty = sscanf(s.c_str(), "%x", &res);
|
int qty = sscanf(token.c_str(), "%x", &res);
|
||||||
if(qty == 0) throw hr_parse_exception("color parse error");
|
if(qty == 0) throw hr_parse_exception("color parse error");
|
||||||
return res * 256 + 0xFF;
|
return res * 256 + 0xFF;
|
||||||
}
|
}
|
||||||
else if(s.size() == 8) {
|
else if(token.size() == 8) {
|
||||||
int qty = sscanf(s.c_str(), "%x", &res);
|
int qty = sscanf(token.c_str(), "%x", &res);
|
||||||
if(qty == 0) throw hr_parse_exception("color parse error");
|
if(qty == 0) throw hr_parse_exception("color parse error");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user