cleanups of input
This commit is contained in:
parent
5375c44d4f
commit
de7d54ddc1
|
@ -2135,7 +2135,7 @@ static int is_key(struct inp_event *ev, const char *name)
|
|||
return strcmp(ev->sym, name);
|
||||
}
|
||||
|
||||
static int game_input(int down, const char *key, int x, int y)
|
||||
static int game_input(int down, const char *key, int x, int y, int mb)
|
||||
{
|
||||
char *p;
|
||||
char buf[1024];
|
||||
|
@ -2145,8 +2145,8 @@ static int game_input(int down, const char *key, int x, int y)
|
|||
if (!p)
|
||||
return -1;
|
||||
|
||||
if (x == -1)
|
||||
snprintf(buf, sizeof(buf), "return stead.input(%s, \"%s\")",
|
||||
if (mb == -1)
|
||||
snprintf(buf, sizeof(buf), "return stead.input(\"kbd\", %s, \"%s\")",
|
||||
((down)?"true":"false"), p);
|
||||
else {
|
||||
float v = game_theme.scale;
|
||||
|
@ -2154,8 +2154,8 @@ static int game_input(int down, const char *key, int x, int y)
|
|||
x = (int)((float)x / v);
|
||||
y = (int)((float)y / v);
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "return stead.input(%s, \"%s\", %d, %d)",
|
||||
((down)?"true":"false"), p, x, y);
|
||||
snprintf(buf, sizeof(buf), "return stead.input(\"mouse\", %s, %d, %d, %d)",
|
||||
((down)?"true":"false"), x, y, mb);
|
||||
}
|
||||
free(p);
|
||||
if (instead_eval(buf)) {
|
||||
|
@ -2186,10 +2186,10 @@ int game_loop(void)
|
|||
if (rc == -1) {/* close */
|
||||
break;
|
||||
} else if (curgame_dir && (ev.type == KEY_DOWN || ev.type == KEY_UP)
|
||||
&& !game_input((ev.type == KEY_DOWN), ev.sym, -1, -1)) {
|
||||
&& !game_input((ev.type == KEY_DOWN), ev.sym, -1, -1, -1)) {
|
||||
; /* all is done in game_input */
|
||||
} else if (curgame_dir && (ev.type == MOUSE_DOWN || ev.type == MOUSE_UP)
|
||||
&& !game_input((ev.type == MOUSE_DOWN), "mouse", ev.x, ev.y)) {
|
||||
&& !game_input((ev.type == MOUSE_DOWN), "mouse", ev.x, ev.y, ev.code)) {
|
||||
; /* all is done in game_input */
|
||||
} else if (((ev.type == KEY_DOWN) || (ev.type == KEY_UP)) &&
|
||||
(!is_key(&ev, "left alt") || !is_key(&ev, "right alt"))) {
|
||||
|
|
|
@ -12,16 +12,17 @@ stead = {
|
|||
end
|
||||
return
|
||||
end,
|
||||
input = function(pressed, event, x, y)
|
||||
if type(input) == 'table' then
|
||||
if event == 'mouse' then
|
||||
if type(input.click) == 'function' then
|
||||
return input:click(pressed, x, y);
|
||||
end
|
||||
else
|
||||
if type(input.key) == 'function' then
|
||||
return input:key(pressed, event);
|
||||
end
|
||||
input = function(event, ...)
|
||||
if type(input) ~= 'table' then
|
||||
return
|
||||
end
|
||||
if event == 'kbd' then
|
||||
if type(input.key) == 'function' then
|
||||
return input:key(unpack(arg)); -- pressed, event
|
||||
end
|
||||
elseif event == 'mouse' then
|
||||
if type(input.click) == 'function' then
|
||||
return input:click(unpack(arg)); -- pressed, x, y, mb
|
||||
end
|
||||
end
|
||||
return
|
||||
|
@ -1868,7 +1869,7 @@ input = obj { -- input object
|
|||
--[[ key = function(s, down, key)
|
||||
return
|
||||
end, ]]
|
||||
--[[ click = function(s, down, x, y)
|
||||
--[[ click = function(s, down, x, y, mb)
|
||||
return
|
||||
end ]]
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue