feat(input): guard Guest Book taps and add double-tap placement

Guest Book: only open a card on a short stationary tap, ignore drags and flings, and guard the detail Close button after opening. Board: add a persisted double-tap placement mode with deferred single taps, while hold stays the default and right-click works in both modes.
This commit is contained in:
Ratdoku Builder committed 2026-12-02 20:10:44 -06:00
1 parent bed81a2e05
commit af4951baf8
8 files changed
+344 -11

No files matched your search

+53 -3
View File
@@ -11,6 +11,7 @@ signal mistake
const EMPTY := 0
const X := 1
const RAT := 2
const DOUBLE_TAP_MS := 220
var n := 8
var regions: Array = []
@@ -33,6 +34,9 @@ var hold_fired := false
var hold_seconds := 0.35
var show_patterns := true
var reduce_motion := false
var double_tap_place := false
var pending_tap_cell := Vector2i(-1, -1)
var pending_tap_at := 0
var region_rats: Array = []
var region_textures := {}
@@ -76,6 +80,7 @@ func _ready() -> void:
show_patterns = bool(save.get_setting("patterns"))
reduce_motion = bool(save.get_setting("reduce_motion"))
hold_seconds = float(save.get_setting("hold_seconds"))
double_tap_place = bool(save.get_setting("double_tap_place"))
save.settings_changed.connect(_on_settings_changed)
@@ -86,6 +91,15 @@ func _on_settings_changed() -> void:
show_patterns = bool(save.get_setting("patterns"))
reduce_motion = bool(save.get_setting("reduce_motion"))
hold_seconds = float(save.get_setting("hold_seconds"))
double_tap_place = bool(save.get_setting("double_tap_place"))
if not double_tap_place and pending_tap_cell.x >= 0:
var pending := pending_tap_cell
pending_tap_cell = Vector2i(-1, -1)
_tap(pending)
elif double_tap_place:
# Leave hold mode cleanly if it was mid-press.
press_cell = Vector2i(-1, -1)
hold_fired = false
queue_redraw()
@@ -94,7 +108,13 @@ func _process(delta: float) -> void:
pop_time = max(0.0, pop_time - delta)
queue_redraw()
if press_cell.x >= 0 and not hold_fired:
if pending_tap_cell.x >= 0 and Time.get_ticks_msec() - pending_tap_at >= DOUBLE_TAP_MS:
var pending := pending_tap_cell
pending_tap_cell = Vector2i(-1, -1)
_tap(pending)
queue_redraw()
if not double_tap_place and press_cell.x >= 0 and not hold_fired:
press_elapsed += delta
if press_elapsed >= hold_seconds:
hold_fired = true
@@ -137,6 +157,7 @@ func set_level(level: Dictionary) -> void:
fixed[Vector2i(r, c)] = true
history.clear()
pending_tap_cell = Vector2i(-1, -1)
conflict_cells.clear()
last_placed = Vector2i(-1, -1)
pop_time = 0.0
@@ -183,7 +204,7 @@ func _draw() -> void:
draw_arc(center, cell_size * 0.42, 0.0, TAU, 32, Palette.RED, 3.0, true)
# Hold progress: fills a gold ring before checking a guest in.
if press_cell.x >= 0 and not hold_fired:
if press_cell.x >= 0 and not hold_fired and not double_tap_place:
var center := _cell_rect(press_cell.x, press_cell.y).get_center()
var t: float = clamp(press_elapsed / hold_seconds, 0.0, 1.0)
draw_arc(center, cell_size * 0.40, -PI * 0.5, -PI * 0.5 + TAU * t, 32, Palette.GOLD, 3.0, true)
@@ -417,7 +438,10 @@ func _gui_input(event: InputEvent) -> void:
hold_fired = false
queue_redraw()
if not fired and was_cell.x >= 0 and cell == was_cell:
_tap(was_cell)
if double_tap_place:
_handle_tap(was_cell)
else:
_tap(was_cell)
accept_event()
elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
@@ -452,10 +476,33 @@ func _tap(cell: Vector2i) -> void:
_set_cell(cell, X)
## Double-tap mode: defer the single-tap action briefly so a second tap
## on the same cell can check a guest in instead.
func _handle_tap(cell: Vector2i) -> void:
if fixed.has(cell):
return
var now := Time.get_ticks_msec()
if pending_tap_cell == cell and now - pending_tap_at <= DOUBLE_TAP_MS:
pending_tap_cell = Vector2i(-1, -1)
_toggle_rat(cell)
return
if pending_tap_cell.x >= 0:
var old := pending_tap_cell
pending_tap_cell = Vector2i(-1, -1)
_tap(old)
pending_tap_cell = cell
pending_tap_at = now
## Hold (mobile/PC) or right-click (PC): check a guest in or out.
func _toggle_rat(cell: Vector2i) -> void:
if fixed.has(cell):
return
# A right-click or hold overrides any tap still waiting for a partner.
if pending_tap_cell == cell:
pending_tap_cell = Vector2i(-1, -1)
if int(cells[cell.x][cell.y]) == RAT:
_set_cell(cell, EMPTY)
else:
@@ -504,11 +551,13 @@ func _copy_cells() -> Array:
func undo() -> void:
if history.is_empty():
return
pending_tap_cell = Vector2i(-1, -1)
cells = history.pop_back()
_after_change()
func restart() -> void:
pending_tap_cell = Vector2i(-1, -1)
_push_history()
for r in n:
for c in n:
@@ -520,6 +569,7 @@ func restart() -> void:
func hint() -> bool:
if solution.size() != n:
return false
pending_tap_cell = Vector2i(-1, -1)
for r in n:
var c := int(solution[r])
if int(cells[r][c]) == RAT: