Change control scheme

This commit is contained in:
2026-03-11 20:50:08 +01:00
parent 8e66f13c85
commit 4a144ac9f9
3 changed files with 27 additions and 23 deletions
+21 -19
View File
@@ -657,6 +657,12 @@ fn wlKeyboardHandleLeave(data: ?*anyopaque, keyboard: ?*c.wl_keyboard, serial: u
_ = surface;
}
fn handleKey(key: *puzzle.platform.Key, pressed: bool) void {
const already_pressed: bool = key.down;
key.down = pressed;
key.pressing = pressed and already_pressed;
}
fn wlKeyboardHandleKey(data: ?*anyopaque, keyboard: ?*c.wl_keyboard, serial: u32, time: u32, key: u32, state: u32) callconv(.c) void {
_ = keyboard;
_ = serial;
@@ -686,29 +692,25 @@ fn wlKeyboardHandleKey(data: ?*anyopaque, keyboard: ?*c.wl_keyboard, serial: u32
wl_state.running = false;
},
c.XKB_KEY_F1 => {
const already_pressed: bool = wl_state.app_input.key.f1.down;
wl_state.app_input.key.f1.down = pressed;
wl_state.app_input.key.f1.pressing = pressed and already_pressed;
},
c.XKB_KEY_f => {
const already_pressed: bool = wl_state.app_input.key.f.down;
wl_state.app_input.key.f.down = pressed;
wl_state.app_input.key.f.pressing = pressed and already_pressed;
},
c.XKB_KEY_r => {
const already_pressed: bool = wl_state.app_input.key.r.down;
wl_state.app_input.key.r.down = pressed;
wl_state.app_input.key.r.pressing = pressed and already_pressed;
handleKey(&wl_state.app_input.key.f1, pressed);
},
c.XKB_KEY_q => {
const already_pressed: bool = wl_state.app_input.key.q.down;
wl_state.app_input.key.q.down = pressed;
wl_state.app_input.key.q.pressing = pressed and already_pressed;
handleKey(&wl_state.app_input.key.q, pressed);
},
c.XKB_KEY_w => {
handleKey(&wl_state.app_input.key.w, pressed);
},
c.XKB_KEY_e => {
handleKey(&wl_state.app_input.key.e, pressed);
},
c.XKB_KEY_r => {
handleKey(&wl_state.app_input.key.r, pressed);
},
c.XKB_KEY_f => {
handleKey(&wl_state.app_input.key.f, pressed);
},
c.XKB_KEY_space => {
const already_pressed: bool = wl_state.app_input.key.space.down;
wl_state.app_input.key.space.down = pressed;
wl_state.app_input.key.space.pressing = pressed and already_pressed;
handleKey(&wl_state.app_input.key.space, pressed);
},
else => {},
}
+4 -2
View File
@@ -17,9 +17,11 @@ pub const Key = struct {
const Keyboard = struct {
esc: Key,
f1: Key,
f: Key,
r: Key,
q: Key,
w: Key,
e: Key,
r: Key,
f: Key,
space: Key,
};
+2 -2
View File
@@ -648,7 +648,7 @@ pub fn updateAndRender(memory: *platform.AppMemory, buffer: platform.OffscreenBu
const diff = mouse_pos.sub(state.mouse_pos);
brick.pos = brick.pos.add(diff);
if (keyPressed(&input.key.space)) {
if (keyPressed(&input.key.e)) {
brick.rotating = true;
const rotated = brick.rotate();
brick.tiles = rotated;
@@ -659,7 +659,7 @@ pub fn updateAndRender(memory: *platform.AppMemory, buffer: platform.OffscreenBu
}
// Flip
if (keyPressed(&input.key.f)) {
if (keyPressed(&input.key.w)) {
brick.rotating = true;
const flipped = brick.transpose();
brick.tiles = flipped;