Skip to content

Commit 146eef9

Browse files
committed
fix(core/touch): deck double tap issue
1 parent 95a4af6 commit 146eef9

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

core/touch.lua

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ local mouse = require "core.mouse"
22

33
local TOUCH_LONG_PRESS_FRAMES <const> = 18
44
local TOUCH_MOVE_THRESHOLD2 <const> = 12 * 12
5-
local TOUCH_REPEAT_DIST2 <const> = 160 * 160
6-
75
-- Regions that require a confirmation tap.
86
local DOUBLE_TAP_REGIONS <const> = {
97
hand = true,
@@ -13,12 +11,16 @@ local DOUBLE_TAP_REGIONS <const> = {
1311
discard = true,
1412
deck = true,
1513
card = true,
16-
map = true,
14+
}
15+
16+
local REGION_CONFIRM_DOUBLE <const> = {
17+
deck = true,
1718
}
1819

1920
local touch = {}
2021

2122
local current_frame = 0
23+
local pending_clear_focus
2224

2325
local function dist2(x1, y1, x2, y2)
2426
local dx = x1 - x2
@@ -55,6 +57,26 @@ local function clear_last_tap()
5557
last_tap.y = 0
5658
end
5759

60+
local function store_last_tap(focus_object, region, x, y)
61+
if focus_object then
62+
last_tap.require_double = true
63+
last_tap.object = focus_object
64+
last_tap.region = region
65+
last_tap.x = x
66+
last_tap.y = y
67+
return true
68+
end
69+
if region and REGION_CONFIRM_DOUBLE[region] then
70+
last_tap.require_double = true
71+
last_tap.object = nil
72+
last_tap.region = region
73+
last_tap.x = x
74+
last_tap.y = y
75+
return true
76+
end
77+
clear_last_tap()
78+
end
79+
5880
local function reset_state()
5981
state.active = false
6082
state.pressing = false
@@ -97,9 +119,8 @@ function touch.begin(x, y)
97119
if last_tap.require_double then
98120
local focus_object = mouse.focus_object()
99121
local same_object = focus_object and focus_object == last_tap.object
100-
local same_region = region ~= nil and region == last_tap.region
101-
local same_spot = dist2(x, y, last_tap.x, last_tap.y) <= TOUCH_REPEAT_DIST2
102-
if same_object or same_region or same_spot then
122+
local same_region = (focus_object == nil and last_tap.object == nil and region ~= nil and REGION_CONFIRM_DOUBLE[region] and region == last_tap.region)
123+
if same_object or same_region then
103124
state.double_candidate = true
104125
else
105126
clear_last_tap()
@@ -138,13 +159,13 @@ function touch.ended(x, y)
138159
mouse.mouse_button("left", true)
139160
mouse.mouse_button("left", false)
140161
clear_last_tap()
162+
pending_clear_focus = true
141163
else
142164
local focus_object = mouse.focus_object()
143-
last_tap.require_double = true
144-
last_tap.object = focus_object
145-
last_tap.region = region
146-
last_tap.x = state.x
147-
last_tap.y = state.y
165+
if not store_last_tap(focus_object, region, state.x, state.y) then
166+
reset_state()
167+
return
168+
end
148169
end
149170
else
150171
mouse.mouse_button("left", true)
@@ -160,6 +181,10 @@ end
160181

161182
function touch.update(frame)
162183
current_frame = frame
184+
if pending_clear_focus then
185+
mouse.set_focus(nil, nil)
186+
pending_clear_focus = nil
187+
end
163188
if not state.active then
164189
return
165190
end
@@ -172,9 +197,7 @@ function touch.update(frame)
172197
local focus_object = mouse.focus_object()
173198
if focus_object and focus_object == last_tap.object then
174199
candidate = true
175-
elseif last_tap.region and region == last_tap.region then
176-
candidate = true
177-
elseif dist2(state.x, state.y, last_tap.x, last_tap.y) <= TOUCH_REPEAT_DIST2 then
200+
elseif focus_object == nil and last_tap.object == nil and REGION_CONFIRM_DOUBLE[region] and region == last_tap.region then
178201
candidate = true
179202
end
180203
end

0 commit comments

Comments
 (0)