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:
1 parent
bed81a2e05
commit
af4951baf8
8 files changed
+343
-10
No files matched your search
+52
-2
@@ -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,6 +438,9 @@ func _gui_input(event: InputEvent) -> void:
|
||||
hold_fired = false
|
||||
queue_redraw()
|
||||
if not fired and was_cell.x >= 0 and cell == was_cell:
|
||||
if double_tap_place:
|
||||
_handle_tap(was_cell)
|
||||
else:
|
||||
_tap(was_cell)
|
||||
accept_event()
|
||||
|
||||
@@ -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:
|
||||
|
||||
+92
-3
@@ -2,9 +2,17 @@ extends Control
|
||||
|
||||
signal back_pressed
|
||||
|
||||
## A tap is only trusted when it is short and stationary. Anything that
|
||||
## drifts or moves the scroll container is treated as a scroll gesture.
|
||||
const TAP_MAX_MOVE := 12.0
|
||||
const TAP_MAX_MS := 500
|
||||
const DRAG_SUPPRESS_MS := 180
|
||||
const DETAIL_CLOSE_GUARD_MS := 250
|
||||
|
||||
var grid: GridContainer
|
||||
var progress_label: Label
|
||||
var status_label: Label
|
||||
var scroll: ScrollContainer
|
||||
var detail_layer: ColorRect
|
||||
var detail_portrait: TextureRect
|
||||
var detail_name: Label
|
||||
@@ -14,6 +22,14 @@ var detail_bio: Label
|
||||
var detail_snack: Label
|
||||
var detail_status: Label
|
||||
|
||||
var _press_active := false
|
||||
var _press_at := 0
|
||||
var _press_pos := Vector2.ZERO
|
||||
var _press_scroll := 0
|
||||
var _dragged := false
|
||||
var _suppress_until := 0
|
||||
var _detail_opened_at := 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var margin := MarginContainer.new()
|
||||
@@ -53,10 +69,12 @@ func _ready() -> void:
|
||||
status_label.custom_minimum_size = Vector2(0, 20)
|
||||
column.add_child(status_label)
|
||||
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll = ScrollContainer.new()
|
||||
scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
scroll.scroll_started.connect(_on_scroll_started)
|
||||
scroll.scroll_ended.connect(_on_scroll_ended)
|
||||
column.add_child(scroll)
|
||||
|
||||
grid = GridContainer.new()
|
||||
@@ -173,9 +191,62 @@ func _make_card(guest: Dictionary) -> PanelContainer:
|
||||
return panel
|
||||
|
||||
|
||||
func _on_scroll_started() -> void:
|
||||
_dragged = true
|
||||
|
||||
|
||||
func _on_scroll_ended() -> void:
|
||||
_dragged = true
|
||||
_suppress_until = max(_suppress_until, Time.get_ticks_msec() + DRAG_SUPPRESS_MS)
|
||||
|
||||
|
||||
func _on_card_input(event: InputEvent, guest: Dictionary, locked: bool) -> void:
|
||||
if not (event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT):
|
||||
if event is InputEventMouseMotion and _press_active:
|
||||
var motion := event as InputEventMouseMotion
|
||||
if motion.global_position.distance_to(_press_pos) > TAP_MAX_MOVE:
|
||||
_dragged = true
|
||||
return
|
||||
|
||||
if not (event is InputEventMouseButton):
|
||||
return
|
||||
var button := event as InputEventMouseButton
|
||||
if button.button_index != MOUSE_BUTTON_LEFT:
|
||||
return
|
||||
|
||||
if button.pressed:
|
||||
# Remember where and when the finger landed, and how far the list
|
||||
# was scrolled, so a release can be checked against it.
|
||||
_press_active = true
|
||||
_press_at = Time.get_ticks_msec()
|
||||
_press_pos = button.global_position
|
||||
_press_scroll = scroll.scroll_vertical if scroll != null else 0
|
||||
_dragged = false
|
||||
return
|
||||
|
||||
if not _press_active:
|
||||
return
|
||||
_press_active = false
|
||||
|
||||
var now := Time.get_ticks_msec()
|
||||
var moved: float = button.global_position.distance_to(_press_pos)
|
||||
var scroll_now := scroll.scroll_vertical if scroll != null else 0
|
||||
var scrolled := _dragged or absi(scroll_now - _press_scroll) > 1
|
||||
var is_tap: bool = (
|
||||
not scrolled
|
||||
and moved <= TAP_MAX_MOVE
|
||||
and now - _press_at <= TAP_MAX_MS
|
||||
and now >= _suppress_until
|
||||
)
|
||||
|
||||
if scrolled:
|
||||
_suppress_until = now + DRAG_SUPPRESS_MS
|
||||
|
||||
# Consume the release either way: a scroll must not fall through to a
|
||||
# card, and a tap must not reach the detail sheet that is about to open.
|
||||
accept_event()
|
||||
if not is_tap:
|
||||
return
|
||||
|
||||
if locked:
|
||||
var room := int(guest.get("unlock_room", 0))
|
||||
status_label.text = "Check in a guest from Room %d to meet them." % room
|
||||
@@ -192,14 +263,17 @@ func _build_detail() -> void:
|
||||
detail_layer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
detail_layer.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
detail_layer.visible = false
|
||||
detail_layer.gui_input.connect(_on_detail_input)
|
||||
add_child(detail_layer)
|
||||
|
||||
var center := CenterContainer.new()
|
||||
center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
detail_layer.add_child(center)
|
||||
|
||||
var panel := UI.panel(Palette.CREAM, 24, 16)
|
||||
panel.custom_minimum_size = Vector2(320, 0)
|
||||
panel.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
center.add_child(panel)
|
||||
|
||||
var box := VBoxContainer.new()
|
||||
@@ -230,7 +304,7 @@ func _build_detail() -> void:
|
||||
|
||||
var close := UI.button("Close", false, 44)
|
||||
close.add_theme_font_size_override("font_size", 16)
|
||||
close.pressed.connect(func() -> void: detail_layer.visible = false)
|
||||
close.pressed.connect(_try_close_detail)
|
||||
box.add_child(close)
|
||||
|
||||
|
||||
@@ -247,4 +321,19 @@ func _show_detail(guest: Dictionary) -> void:
|
||||
detail_status.text = "Checked in · Room %d" % int(guest.get("unlock_room", 0))
|
||||
if int(guest.get("unlock_room", 0)) == 0:
|
||||
detail_status.text = "Resident · always in"
|
||||
_detail_opened_at = Time.get_ticks_msec()
|
||||
detail_layer.visible = true
|
||||
detail_layer.move_to_front()
|
||||
|
||||
|
||||
func _on_detail_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
||||
_try_close_detail()
|
||||
|
||||
|
||||
func _try_close_detail() -> void:
|
||||
# The opening tap can land where the sheet appears. Ignore close input
|
||||
# for a moment so one deliberate tap opens and a second one closes.
|
||||
if Time.get_ticks_msec() - _detail_opened_at < DETAIL_CLOSE_GUARD_MS:
|
||||
return
|
||||
detail_layer.visible = false
|
||||
+5
-1
@@ -7,6 +7,7 @@ signal rules_pressed
|
||||
|
||||
var progress_pill: Button
|
||||
var primary: Button
|
||||
var hint_label: Label
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -79,7 +80,8 @@ func _ready() -> void:
|
||||
|
||||
column.add_child(UI.label("Crumb, innkeeper", 12, Palette.MUTED))
|
||||
column.add_child(UI.label("Every guest gets a room of their own.", 15))
|
||||
column.add_child(UI.label("Tap = X · Hold or right-click = check in", 11, Palette.MUTED))
|
||||
hint_label = UI.label(UI.place_hint(), 11, Palette.MUTED)
|
||||
column.add_child(hint_label)
|
||||
|
||||
var bottom_space := Control.new()
|
||||
bottom_space.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
@@ -113,10 +115,12 @@ func _ready() -> void:
|
||||
column.add_child(UI.label(Version.BUILD_LABEL, 9, Palette.MUTED))
|
||||
|
||||
SaveGame.progress_changed.connect(refresh)
|
||||
SaveGame.settings_changed.connect(refresh)
|
||||
refresh()
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
hint_label.text = UI.place_hint()
|
||||
var guests := Guests.all()
|
||||
var unlocked := SaveGame.unlocked_count(guests)
|
||||
progress_pill.text = "%d / %d guests" % [unlocked, guests.size()]
|
||||
|
||||
+23
-3
@@ -6,6 +6,7 @@ const BoardScene = preload("res://scenes/Board.tscn")
|
||||
|
||||
var tutorial_board: Board
|
||||
var tutorial_status: Label
|
||||
var checkin_body: Label
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -54,7 +55,8 @@ func _ready() -> void:
|
||||
content.add_child(_rule_row("No shared walls or corners", "Rats cannot touch, not even diagonally.", "touch"))
|
||||
|
||||
content.add_child(_heading("Checking in", 18))
|
||||
content.add_child(_body("Tap or left-click to mark X. Tap an X or a guest to clear it. Hold or right-click to check a guest in. Gold-ringed guests are already in."))
|
||||
checkin_body = _body(_checkin_text())
|
||||
content.add_child(checkin_body)
|
||||
content.add_child(_body("Undo is unlimited. Hints are free and explain the next sensible move."))
|
||||
|
||||
content.add_child(_heading("Try a tiny room", 18))
|
||||
@@ -84,8 +86,9 @@ func _ready() -> void:
|
||||
hint.pressed.connect(_on_tutorial_hint)
|
||||
controls.add_child(hint)
|
||||
|
||||
tutorial_status = UI.label("Tap = X · Hold or right-click = check in", 10, Palette.MUTED)
|
||||
tutorial_status = UI.label(UI.place_hint(), 10, Palette.MUTED)
|
||||
content.add_child(tutorial_status)
|
||||
SaveGame.settings_changed.connect(_refresh_hints)
|
||||
|
||||
content.add_child(_heading("Housekeeping tips", 18))
|
||||
content.add_child(_body("Start with the smallest room. If a room's open cells all sit in one row, that row's guest belongs to that room. Every room has one solution and never requires guessing."))
|
||||
@@ -152,9 +155,26 @@ func _load_tutorial() -> Dictionary:
|
||||
return {}
|
||||
|
||||
|
||||
func _checkin_text() -> String:
|
||||
var place := "Double-tap or right-click to check a guest in."
|
||||
if not bool(SaveGame.get_setting("double_tap_place")):
|
||||
place = "Hold or right-click to check a guest in."
|
||||
return "Tap or left-click to mark X. Tap an X or a guest to clear it. %s Gold-ringed guests are already in." % place
|
||||
|
||||
|
||||
func _refresh_hints() -> void:
|
||||
if checkin_body != null:
|
||||
checkin_body.text = _checkin_text()
|
||||
if tutorial_status != null and (
|
||||
tutorial_status.text == "Tap = X · Hold or right-click = check in"
|
||||
or tutorial_status.text == "Tap = X · Double-tap or right-click = check in"
|
||||
):
|
||||
tutorial_status.text = UI.place_hint()
|
||||
|
||||
|
||||
func _on_tutorial_reset() -> void:
|
||||
tutorial_board.restart()
|
||||
tutorial_status.text = "Tap = X · Hold or right-click = check in"
|
||||
tutorial_status.text = UI.place_hint()
|
||||
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ const DEFAULTS := {
|
||||
"show_timer": true,
|
||||
"reduce_motion": false,
|
||||
"hold_seconds": 0.35,
|
||||
"double_tap_place": false,
|
||||
}
|
||||
|
||||
var data := {}
|
||||
|
||||
@@ -9,6 +9,7 @@ var game_mode := false
|
||||
var toggles := {}
|
||||
var hold_slider: HSlider
|
||||
var hold_value: Label
|
||||
var hold_panel: PanelContainer
|
||||
var game_actions: HBoxContainer
|
||||
var reset_row: Control
|
||||
var resume_button: Button
|
||||
@@ -84,6 +85,7 @@ func _ready() -> void:
|
||||
_add_pattern_row(list)
|
||||
_add_toggle(list, "Show timer", "Keep the clock visible while you solve.", "show_timer")
|
||||
_add_toggle(list, "Reduce motion", "Stop the bob and placement pop.", "reduce_motion")
|
||||
_add_toggle(list, "Double-tap to place", "Tap = mark · double-tap = check in.", "double_tap_place")
|
||||
_add_hold_row(list)
|
||||
|
||||
list.add_child(UI.spacer(2))
|
||||
@@ -152,6 +154,7 @@ func refresh() -> void:
|
||||
if hold_slider != null:
|
||||
hold_slider.set_value_no_signal(float(SaveGame.get_setting("hold_seconds")))
|
||||
hold_value.text = "%.2f s" % hold_slider.value
|
||||
_update_hold_availability()
|
||||
|
||||
|
||||
func _add_pattern_row(parent: VBoxContainer) -> void:
|
||||
@@ -197,7 +200,10 @@ func _add_toggle(parent: VBoxContainer, title: String, detail: String, key: Stri
|
||||
|
||||
var check := CheckButton.new()
|
||||
check.button_pressed = bool(SaveGame.get_setting(key))
|
||||
check.toggled.connect(func(on: bool) -> void: SaveGame.set_setting(key, on))
|
||||
check.toggled.connect(func(on: bool) -> void:
|
||||
SaveGame.set_setting(key, on)
|
||||
_update_hold_availability()
|
||||
)
|
||||
row.add_child(check)
|
||||
toggles[key] = check
|
||||
parent.add_child(panel)
|
||||
@@ -205,6 +211,7 @@ func _add_toggle(parent: VBoxContainer, title: String, detail: String, key: Stri
|
||||
|
||||
func _add_hold_row(parent: VBoxContainer) -> void:
|
||||
var panel := UI.panel(Palette.PAPER, 14, 8)
|
||||
hold_panel = panel
|
||||
var column := VBoxContainer.new()
|
||||
column.add_theme_constant_override("separation", 2)
|
||||
panel.add_child(column)
|
||||
@@ -271,6 +278,15 @@ func _on_hold_changed(value: float) -> void:
|
||||
SaveGame.set_setting("hold_seconds", snapped)
|
||||
|
||||
|
||||
func _update_hold_availability() -> void:
|
||||
if hold_slider == null or hold_panel == null:
|
||||
return
|
||||
var enabled := not bool(SaveGame.get_setting("double_tap_place"))
|
||||
hold_slider.editable = enabled
|
||||
hold_slider.mouse_filter = Control.MOUSE_FILTER_STOP if enabled else Control.MOUSE_FILTER_IGNORE
|
||||
hold_panel.modulate = Color(1, 1, 1, 1.0 if enabled else 0.45)
|
||||
|
||||
|
||||
func _on_scrim_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_close()
|
||||
|
||||
@@ -142,6 +142,13 @@ static func safe_bottom() -> int:
|
||||
return 24 if OS.has_feature("mobile") else 14
|
||||
|
||||
|
||||
## Short control hint that follows the saved placement mode.
|
||||
static func place_hint() -> String:
|
||||
if bool(SaveGame.get_setting("double_tap_place")):
|
||||
return "Tap = X · Double-tap or right-click = check in"
|
||||
return "Tap = X · Hold or right-click = check in"
|
||||
|
||||
|
||||
static func _button_style(color: Color) -> StyleBoxFlat:
|
||||
var s := StyleBoxFlat.new()
|
||||
s.bg_color = color
|
||||
|
||||
@@ -53,6 +53,8 @@ func _run() -> void:
|
||||
_check(abs(main.game.board.hold_seconds - 0.50) < 0.001, "hold_seconds did not reach Board")
|
||||
save.set_setting("hold_seconds", 0.35)
|
||||
|
||||
_test_placement_modes(save, main.game.board)
|
||||
|
||||
var unlocked: String = save.complete_room("room-01", 1)
|
||||
_check(unlocked == "pepper", "room 1 should unlock Pepper")
|
||||
_check(save.is_guest_unlocked("pepper"), "Pepper should be unlocked")
|
||||
@@ -64,6 +66,7 @@ func _run() -> void:
|
||||
_check(main.guest_book != null, "Guest Book missing")
|
||||
if main.guest_book != null and main.guest_book.progress_label != null:
|
||||
_check(main.guest_book.progress_label.text.find("6/25") >= 0, "Guest Book progress should be 6/25")
|
||||
_test_guest_book_input(main.guest_book)
|
||||
|
||||
main.show_screen("rules")
|
||||
await process_frame
|
||||
@@ -80,6 +83,149 @@ func _run() -> void:
|
||||
save.set_setting("show_timer", true)
|
||||
save.set_setting("reduce_motion", false)
|
||||
save.set_setting("hold_seconds", 0.35)
|
||||
save.set_setting("double_tap_place", false)
|
||||
|
||||
print("UI TEST: ", "PASS" if failures == 0 else "FAIL (%d)" % failures)
|
||||
quit(0 if failures == 0 else 1)
|
||||
|
||||
|
||||
func _find_empty(board: Board) -> Vector2i:
|
||||
for r in board.n:
|
||||
for c in board.n:
|
||||
if (
|
||||
int(board.cells[r][c]) == Board.EMPTY
|
||||
and not board.fixed.has(Vector2i(r, c))
|
||||
and not board.auto_x[r][c]
|
||||
):
|
||||
return Vector2i(r, c)
|
||||
return Vector2i(-1, -1)
|
||||
|
||||
|
||||
func _test_placement_modes(save, board: Board) -> void:
|
||||
board.restart()
|
||||
save.set_setting("double_tap_place", true)
|
||||
_check(board.double_tap_place, "double_tap_place did not reach Board")
|
||||
|
||||
# A first tap waits; a second tap on the same cell checks a guest in.
|
||||
var cell := _find_empty(board)
|
||||
board._handle_tap(cell)
|
||||
_check(int(board.cells[cell.x][cell.y]) == Board.EMPTY, "first tap should wait in double-tap mode")
|
||||
board._handle_tap(cell)
|
||||
_check(int(board.cells[cell.x][cell.y]) == Board.RAT, "double tap should check a guest in")
|
||||
board._handle_tap(cell)
|
||||
board._handle_tap(cell)
|
||||
_check(int(board.cells[cell.x][cell.y]) == Board.EMPTY, "double tap on a guest should check them out")
|
||||
|
||||
# A lone tap still marks an X once the double-tap window passes.
|
||||
var cell2 := _find_empty(board)
|
||||
board._handle_tap(cell2)
|
||||
board.pending_tap_at -= Board.DOUBLE_TAP_MS + 1
|
||||
board._process(0.0)
|
||||
_check(int(board.cells[cell2.x][cell2.y]) == Board.X, "single tap should mark X after the window")
|
||||
|
||||
# Holding must not place a guest while double-tap mode is on.
|
||||
board.press_cell = cell2
|
||||
board.press_elapsed = 0.0
|
||||
board.hold_fired = false
|
||||
board._process(1.0)
|
||||
_check(int(board.cells[cell2.x][cell2.y]) == Board.X, "hold should not place in double-tap mode")
|
||||
board.press_cell = Vector2i(-1, -1)
|
||||
board.hold_fired = false
|
||||
|
||||
# Right-click still checks a guest in and out in double-tap mode.
|
||||
board.size = Vector2(320, 320)
|
||||
board._update_layout()
|
||||
var cell3 := _find_empty(board)
|
||||
_right_click(board, cell3)
|
||||
_check(int(board.cells[cell3.x][cell3.y]) == Board.RAT, "right-click should check in during double-tap mode")
|
||||
_right_click(board, cell3)
|
||||
_check(int(board.cells[cell3.x][cell3.y]) == Board.EMPTY, "right-click should check out during double-tap mode")
|
||||
|
||||
# Hold mode still works when the setting is off.
|
||||
save.set_setting("double_tap_place", false)
|
||||
_check(not board.double_tap_place, "double_tap_place did not turn off")
|
||||
board.restart()
|
||||
var cell4 := _find_empty(board)
|
||||
board.press_cell = cell4
|
||||
board.press_elapsed = 0.0
|
||||
board.hold_fired = false
|
||||
board._process(0.60)
|
||||
_check(int(board.cells[cell4.x][cell4.y]) == Board.RAT, "hold should place in hold mode")
|
||||
board.press_cell = Vector2i(-1, -1)
|
||||
board.hold_fired = false
|
||||
|
||||
# Single tap marks X in hold mode.
|
||||
var cell5 := _find_empty(board)
|
||||
board.size = Vector2(320, 320)
|
||||
board._update_layout()
|
||||
_left_tap(board, cell5)
|
||||
_check(int(board.cells[cell5.x][cell5.y]) == Board.X, "single tap should mark X in hold mode")
|
||||
|
||||
# The setting survives a save/load round trip.
|
||||
save.set_setting("double_tap_place", true)
|
||||
save.load_game()
|
||||
_check(bool(save.get_setting("double_tap_place")), "double_tap_place should persist")
|
||||
save.set_setting("double_tap_place", false)
|
||||
board.restart()
|
||||
|
||||
|
||||
func _left_tap(board: Board, cell: Vector2i) -> void:
|
||||
var pos := board._cell_rect(cell.x, cell.y).get_center()
|
||||
var down := InputEventMouseButton.new()
|
||||
down.button_index = MOUSE_BUTTON_LEFT
|
||||
down.pressed = true
|
||||
down.position = pos
|
||||
board._gui_input(down)
|
||||
var up := InputEventMouseButton.new()
|
||||
up.button_index = MOUSE_BUTTON_LEFT
|
||||
up.pressed = false
|
||||
up.position = pos
|
||||
board._gui_input(up)
|
||||
|
||||
|
||||
func _right_click(board: Board, cell: Vector2i) -> void:
|
||||
var event := InputEventMouseButton.new()
|
||||
event.button_index = MOUSE_BUTTON_RIGHT
|
||||
event.pressed = true
|
||||
event.position = board._cell_rect(cell.x, cell.y).get_center()
|
||||
board._gui_input(event)
|
||||
|
||||
|
||||
func _test_guest_book_input(book) -> void:
|
||||
var guest: Dictionary = Guests.all()[0]
|
||||
book.detail_layer.visible = false
|
||||
|
||||
# Dragging across a card is a scroll, not a tap.
|
||||
_mouse(book, guest, Vector2(100, 300), true)
|
||||
var motion := InputEventMouseMotion.new()
|
||||
motion.global_position = Vector2(170, 300)
|
||||
book._on_card_input(motion, guest, false)
|
||||
_mouse(book, guest, Vector2(170, 300), false)
|
||||
_check(not book.detail_layer.visible, "dragging should not open a guest card")
|
||||
|
||||
# A fling settling must not turn into a tap either.
|
||||
book._suppress_until = Time.get_ticks_msec() + 1000
|
||||
_mouse(book, guest, Vector2(100, 300), true)
|
||||
_mouse(book, guest, Vector2(100, 300), false)
|
||||
_check(not book.detail_layer.visible, "post-scroll tap should be ignored")
|
||||
|
||||
# A short, stationary tap opens the card.
|
||||
book._suppress_until = 0
|
||||
_mouse(book, guest, Vector2(100, 300), true)
|
||||
_mouse(book, guest, Vector2(100, 300), false)
|
||||
_check(book.detail_layer.visible, "a clean tap should open a guest card")
|
||||
|
||||
# The opening tap must not immediately close the sheet.
|
||||
book._try_close_detail()
|
||||
_check(book.detail_layer.visible, "close should be guarded right after opening")
|
||||
book._detail_opened_at -= 300
|
||||
book._try_close_detail()
|
||||
_check(not book.detail_layer.visible, "close should work after the guard")
|
||||
|
||||
|
||||
func _mouse(book, guest: Dictionary, pos: Vector2, pressed: bool) -> void:
|
||||
var event := InputEventMouseButton.new()
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.pressed = pressed
|
||||
event.global_position = pos
|
||||
book._on_card_input(event, guest, false)
|
||||
Reference in new issue
Block a user