mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-01-26 00:47:00 +00:00
parsing expressions allowed for integers too
This commit is contained in:
parent
34921e983e
commit
ad3355f500
26
dialogs.cpp
26
dialogs.cpp
@ -601,20 +601,18 @@ namespace dialog {
|
|||||||
|
|
||||||
void affect(char kind) {
|
void affect(char kind) {
|
||||||
|
|
||||||
if(ne.intval) {
|
if(kind == 's') {
|
||||||
if(kind == 's') sscanf(ne.s.c_str(), "%d", ne.intval), *ne.editwhat = *ne.intval;
|
exp_parser ep;
|
||||||
if(kind == 'v') *ne.intval = ldtoint(*ne.editwhat), ne.s = its(*ne.intval);
|
ep.s = ne.s;
|
||||||
|
ld x = ep.parse();
|
||||||
|
if(!ep.ok()) return;
|
||||||
|
if(ne.sc.positive && x <= 0) return;
|
||||||
|
*ne.editwhat = x;
|
||||||
|
if(ne.intval) *ne.intval = ldtoint(*ne.editwhat);
|
||||||
}
|
}
|
||||||
else {
|
if(kind == 'v') {
|
||||||
if(kind == 's') {
|
if(ne.intval) *ne.intval = ldtoint(*ne.editwhat);
|
||||||
exp_parser ep;
|
ne.s = disp(*ne.editwhat);
|
||||||
ep.s = ne.s;
|
|
||||||
ld x = ep.parse();
|
|
||||||
if(!ep.ok()) return;
|
|
||||||
if(ne.sc.positive && x <= 0) return;
|
|
||||||
*ne.editwhat = x;
|
|
||||||
}
|
|
||||||
if(kind == 'v') ne.s = disp(*ne.editwhat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reaction) reaction();
|
if(reaction) reaction();
|
||||||
@ -732,7 +730,7 @@ namespace dialog {
|
|||||||
|
|
||||||
keyhandler = [] (int sym, int uni) {
|
keyhandler = [] (int sym, int uni) {
|
||||||
handleNavigation(sym, uni);
|
handleNavigation(sym, uni);
|
||||||
if((uni >= '0' && uni <= '9') || (uni == '.' && !ne.intval) || among(uni, '+', '-', '*', '/', '^', '(', ')') || (uni >= 'a' && uni <= 'z')) {
|
if((uni >= '0' && uni <= '9') || among(uni, '.', '+', '-', '*', '/', '^', '(', ')') || (uni >= 'a' && uni <= 'z')) {
|
||||||
ne.s += uni;
|
ne.s += uni;
|
||||||
affect('s');
|
affect('s');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user