BlueGit

projects-timfalken-com meteors

test: 1:1 small drags and spontaneous match rockets

Unit tests cover a 1-tile drag down, a 1-tile drag up, a 2-tile drag
then stop, and a short move that stays in the same cell. Playwright
checks the same with the mouse and with real touch, including mobile
viewports and deviceScaleFactor 3.

New tests require a ground match after a fall, a match after grey
recolor, a flying match after cargo attaches, and a flying match after
two clusters merge, each to become a rocket.

timfa Grok Bot · pushed by timfa

Authored 2026-11-13 · 4 days ago

Hash
f60b6e397667f7613d654e2d32e8ddde17997110
Parent
4589623f
4 files changed +563 −9
test/drag-playwright.py added +346 −0
@@ -0,0 +1,346 @@
1 #!/usr/bin/env python3
2 """1:1 drag tracking (t1104): mouse and real touch, including a high-DPR mobile viewport."""
3 from __future__ import annotations
4
5 import socket
6 import subprocess
7 import sys
8 import time
9 from pathlib import Path
10
11 from playwright.sync_api import sync_playwright
12
13 OUT = Path("/workspace/meteors-shots")
14 OUT.mkdir(parents=True, exist_ok=True)
15 ROOT = Path("/workspace/meteors")
16 CHROME = "/usr/bin/google-chrome"
17 CHROME_ARGS = [
18 "--use-gl=angle",
19 "--use-angle=swiftshader",
20 "--no-sandbox",
21 "--disable-dev-shm-usage",
22 "--disable-gpu-sandbox",
23 ]
24
25 DESKTOP = {
26 "name": "desktop-mouse",
27 "viewport": {"width": 1280, "height": 900},
28 "device_scale_factor": 1,
29 "is_mobile": False,
30 "has_touch": False,
31 "user_agent": None,
32 "input": "mouse",
33 }
34 ANDROID = {
35 "name": "android-touch",
36 "viewport": {"width": 393, "height": 851},
37 "device_scale_factor": 2,
38 "is_mobile": True,
39 "has_touch": True,
40 "user_agent": (
41 "Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 "
42 "(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"
43 ),
44 "input": "touch",
45 }
46 ANDROID_DPR3 = {
47 "name": "android-dpr3",
48 "viewport": {"width": 393, "height": 851},
49 "device_scale_factor": 3,
50 "is_mobile": True,
51 "has_touch": True,
52 "user_agent": (
53 "Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 "
54 "(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"
55 ),
56 "input": "touch",
57 }
58 IOS = {
59 "name": "ios-touch",
60 "viewport": {"width": 390, "height": 844},
61 "device_scale_factor": 2,
62 "is_mobile": True,
63 "has_touch": True,
64 "user_agent": (
65 "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "
66 "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 "
67 "Mobile/15E148 Safari/604.1"
68 ),
69 "input": "touch",
70 }
71
72 FAILURES = []
73 URL = None
74
75
76 def free_port():
77 s = socket.socket()
78 s.bind(("127.0.0.1", 0))
79 port = s.getsockname()[1]
80 s.close()
81 return port
82
83
84 def field_to_client(page, col, field_y):
85 return page.evaluate(
86 """([col, fieldY]) => {
87 const c = app.scene.canvas;
88 const r = c.getBoundingClientRect();
89 const w = Planet.FIELD_WIDTH;
90 const h = Planet.FIELD_HEIGHT;
91 return {
92 x: r.left + ((col + 0.5) / w) * r.width,
93 y: r.top + (1 - fieldY / h) * r.height
94 };
95 }""",
96 [col, field_y],
97 )
98
99
100 def touch_start(cdp, x, y):
101 cdp.send(
102 "Input.dispatchTouchEvent",
103 {"type": "touchStart", "touchPoints": [{"x": x, "y": y, "id": 1}]},
104 )
105
106
107 def touch_move(cdp, x, y):
108 cdp.send(
109 "Input.dispatchTouchEvent",
110 {"type": "touchMove", "touchPoints": [{"x": x, "y": y, "id": 1}]},
111 )
112
113
114 def touch_end(cdp):
115 cdp.send("Input.dispatchTouchEvent", {"type": "touchEnd", "touchPoints": []})
116
117
118 def pointer_down(page, cdp, kind, x, y):
119 if kind == "mouse":
120 page.mouse.move(x, y)
121 page.mouse.down()
122 else:
123 touch_start(cdp, x, y)
124
125
126 def pointer_move(page, cdp, kind, x, y):
127 if kind == "mouse":
128 page.mouse.move(x, y)
129 else:
130 touch_move(cdp, x, y)
131
132
133 def pointer_up(page, cdp, kind):
134 if kind == "mouse":
135 page.mouse.up()
136 else:
137 touch_end(cdp)
138
139
140 def drag_to(page, cdp, kind, x1, y1, x2, y2, steps=12, end=True):
141 pointer_down(page, cdp, kind, x1, y1)
142 for i in range(1, steps + 1):
143 t = i / steps
144 pointer_move(page, cdp, kind, x1 + (x2 - x1) * t, y1 + (y2 - y1) * t)
145 if end:
146 pointer_up(page, cdp, kind)
147
148
149 def reset_board(page, stacks):
150 page.evaluate(
151 """(stacks) => {
152 const g = app.core;
153 g.spawnInterval = 1e9;
154 g.spawnTimer = 0;
155 g.blocks.length = 0;
156 g.clusters = Object.create(null);
157 g.score = 0;
158 g.drag = null;
159 g.state = 'playing';
160 g.nextBlockId = 1;
161 g.nextClusterId = 1;
162 app.selectTween = null;
163 for (const [col, colors] of Object.entries(stacks)) {
164 colors.forEach((color, row) => g.place(+col, row, color));
165 }
166 }""",
167 stacks,
168 )
169 page.wait_for_timeout(80)
170
171
172 def board(page):
173 return page.evaluate(
174 """() => app.core.blocks.map((b) => ({
175 id: b.id, col: b.col, y: b.y, color: b.color, state: b.state
176 }))"""
177 )
178
179
180 def col_ys(page, col):
181 return {b["color"]: b["y"] for b in board(page) if b["col"] == col}
182
183
184 def check(cond, msg, device):
185 if not cond:
186 FAILURES.append(f"[{device}] {msg}")
187 print(f"FAIL [{device}] {msg}")
188 else:
189 print(f"OK [{device}] {msg}")
190 return cond
191
192
193 def shot(page, name):
194 path = OUT / name
195 page.screenshot(path=str(path), full_page=False)
196 print(f"wrote {path} ({path.stat().st_size} bytes)")
197
198
199 def start_play(page, kind):
200 page.goto(URL, wait_until="networkidle", timeout=20000)
201 page.wait_for_timeout(400)
202 btn = page.locator("#btn-play")
203 btn.wait_for(state="visible", timeout=5000)
204 if kind == "touch":
205 box = btn.bounding_box()
206 cdp = page.context.new_cdp_session(page)
207 touch_start(cdp, box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
208 touch_end(cdp)
209 page.wait_for_timeout(400)
210 else:
211 cdp = None
212 btn.click()
213 page.wait_for_timeout(400)
214 if page.evaluate("() => app && app.mode") == "planet-select":
215 go = page.locator("#btn-planet-go")
216 go.wait_for(state="visible", timeout=5000)
217 go.click()
218 page.wait_for_timeout(400)
219 if page.evaluate("() => app.mode") != "playing":
220 if page.locator("#btn-play").is_visible():
221 page.locator("#btn-play").click()
222 page.wait_for_timeout(400)
223 if page.locator("#btn-planet-go").is_visible():
224 page.locator("#btn-planet-go").click()
225 page.wait_for_timeout(400)
226 page.wait_for_function("() => app && app.mode === 'playing' && app.core && app.scene", timeout=8000)
227 page.wait_for_selector("canvas", state="visible", timeout=5000)
228 if cdp is None:
229 cdp = page.context.new_cdp_session(page)
230 return cdp
231
232
233 def nearly(a, b, eps=0.15):
234 return abs(a - b) <= eps
235
236
237 def run_device(browser, device):
238 name = device["name"]
239 kind = device["input"]
240 print(f"\n======== {name} ({kind}, dpr={device['device_scale_factor']}) ========")
241 kw = dict(
242 viewport=device["viewport"],
243 device_scale_factor=device["device_scale_factor"],
244 is_mobile=device["is_mobile"],
245 has_touch=device["has_touch"],
246 )
247 if device["user_agent"]:
248 kw["user_agent"] = device["user_agent"]
249 context = browser.new_context(**kw)
250 page = context.new_page()
251 bag = []
252 page.on("console", lambda m: bag.append(f"{m.type}: {m.text}"))
253 page.on("pageerror", lambda e: bag.append(f"pageerror: {e}"))
254 cdp = start_play(page, kind)
255 check(page.evaluate("() => app.mode") == "playing", "play started", name)
256
257 # --- 1 tile down ---
258 reset_board(page, {"2": [0, 1, 2, 3, 4]})
259 p0 = field_to_client(page, 2, 1.5)
260 p1 = field_to_client(page, 2, 0.5)
261 drag_to(page, cdp, kind, p0["x"], p0["y"], p1["x"], p1["y"], steps=10, end=True)
262 page.wait_for_timeout(60)
263 ys = col_ys(page, 2)
264 check(nearly(ys.get(1, -99), 0), f"1 tile down: grabbed color 1 at y=0, ys={ys}", name)
265 check(nearly(ys.get(0, -99), 1), f"1 tile down: swapped neighbour to y=1, ys={ys}", name)
266 check(nearly(ys.get(2, -99), 2) and nearly(ys.get(3, -99), 3) and nearly(ys.get(4, -99), 4),
267 f"1 tile down: rest of the stack unmoved, ys={ys}", name)
268
269 # --- 1 tile up ---
270 reset_board(page, {"3": [0, 1, 2, 3, 4]})
271 p0 = field_to_client(page, 3, 0.5)
272 p1 = field_to_client(page, 3, 1.5)
273 drag_to(page, cdp, kind, p0["x"], p0["y"], p1["x"], p1["y"], steps=10, end=True)
274 page.wait_for_timeout(60)
275 ys = col_ys(page, 3)
276 check(nearly(ys.get(0, -99), 1), f"1 tile up: grabbed color 0 at y=1, ys={ys}", name)
277 check(nearly(ys.get(1, -99), 0), f"1 tile up: neighbour at y=0, ys={ys}", name)
278 check(nearly(ys.get(2, -99), 2), f"1 tile up: rest unmoved, ys={ys}", name)
279
280 # --- 2 tiles, then stop: pointer held still, nothing else moves ---
281 reset_board(page, {"4": [0, 1, 2, 3, 4]})
282 p0 = field_to_client(page, 4, 0.5)
283 p1 = field_to_client(page, 4, 2.5)
284 drag_to(page, cdp, kind, p0["x"], p0["y"], p1["x"], p1["y"], steps=14, end=False)
285 page.wait_for_timeout(50)
286 mid = col_ys(page, 4)
287 check(nearly(mid.get(0, -99), 2), f"2 tiles: grabbed color 0 at y=2, ys={mid}", name)
288 check(nearly(mid.get(1, -99), 0) and nearly(mid.get(2, -99), 1) and nearly(mid.get(3, -99), 3),
289 f"2 tiles: walked both neighbours, ys={mid}", name)
290 # Pointer stops: more moves at the same point, then a short wait.
291 for _ in range(6):
292 pointer_move(page, cdp, kind, p1["x"], p1["y"])
293 page.wait_for_timeout(30)
294 after = col_ys(page, 4)
295 check(after == mid, f"pointer stopped: stack stays put, mid={mid} after={after}", name)
296 pointer_up(page, cdp, kind)
297 page.wait_for_timeout(80)
298 end = col_ys(page, 4)
299 check(end == mid, f"after release: still at the pointer row, mid={mid} end={end}", name)
300 shot(page, f"t1104-drag-{name}.png")
301
302 if bag:
303 print(f"console [{name}]: {bag[:8]}")
304 context.close()
305
306
307 def main():
308 global URL
309 port = free_port()
310 URL = f"http://127.0.0.1:{port}/"
311 print("serving", URL, "from", ROOT / "build")
312 httpd = subprocess.Popen(
313 ["python3", "-m", "http.server", str(port), "--bind", "127.0.0.1", "--directory", str(ROOT / "build")],
314 stdout=subprocess.DEVNULL,
315 stderr=subprocess.DEVNULL,
316 )
317 try:
318 time.sleep(0.4)
319 with sync_playwright() as p:
320 browser = p.chromium.launch(
321 executable_path=CHROME,
322 args=CHROME_ARGS,
323 headless=True,
324 )
325 for device in (DESKTOP, ANDROID, ANDROID_DPR3, IOS):
326 run_device(browser, device)
327 browser.close()
328 finally:
329 httpd.terminate()
330 try:
331 httpd.wait(timeout=3)
332 except Exception:
333 httpd.kill()
334
335 print("\n======== summary ========")
336 if FAILURES:
337 print(f"{len(FAILURES)} failure(s):")
338 for f in FAILURES:
339 print(" -", f)
340 return 1
341 print("all 1:1 drag tests passed")
342 return 0
343
344
345 if __name__ == "__main__":
346 sys.exit(main())
@@ -0,0 +1,346 @@
1#!/usr/bin/env python3
2"""1:1 drag tracking (t1104): mouse and real touch, including a high-DPR mobile viewport."""
3from __future__ import annotations
4
5import socket
6import subprocess
7import sys
8import time
9from pathlib import Path
10
11from playwright.sync_api import sync_playwright
12
13OUT = Path("/workspace/meteors-shots")
14OUT.mkdir(parents=True, exist_ok=True)
15ROOT = Path("/workspace/meteors")
16CHROME = "/usr/bin/google-chrome"
17CHROME_ARGS = [
18 "--use-gl=angle",
19 "--use-angle=swiftshader",
20 "--no-sandbox",
21 "--disable-dev-shm-usage",
22 "--disable-gpu-sandbox",
23]
24
25DESKTOP = {
26 "name": "desktop-mouse",
27 "viewport": {"width": 1280, "height": 900},
28 "device_scale_factor": 1,
29 "is_mobile": False,
30 "has_touch": False,
31 "user_agent": None,
32 "input": "mouse",
33}
34ANDROID = {
35 "name": "android-touch",
36 "viewport": {"width": 393, "height": 851},
37 "device_scale_factor": 2,
38 "is_mobile": True,
39 "has_touch": True,
40 "user_agent": (
41 "Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 "
42 "(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"
43 ),
44 "input": "touch",
45}
46ANDROID_DPR3 = {
47 "name": "android-dpr3",
48 "viewport": {"width": 393, "height": 851},
49 "device_scale_factor": 3,
50 "is_mobile": True,
51 "has_touch": True,
52 "user_agent": (
53 "Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 "
54 "(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"
55 ),
56 "input": "touch",
57}
58IOS = {
59 "name": "ios-touch",
60 "viewport": {"width": 390, "height": 844},
61 "device_scale_factor": 2,
62 "is_mobile": True,
63 "has_touch": True,
64 "user_agent": (
65 "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "
66 "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 "
67 "Mobile/15E148 Safari/604.1"
68 ),
69 "input": "touch",
70}
71
72FAILURES = []
73URL = None
74
75
76def free_port():
77 s = socket.socket()
78 s.bind(("127.0.0.1", 0))
79 port = s.getsockname()[1]
80 s.close()
81 return port
82
83
84def field_to_client(page, col, field_y):
85 return page.evaluate(
86 """([col, fieldY]) => {
87 const c = app.scene.canvas;
88 const r = c.getBoundingClientRect();
89 const w = Planet.FIELD_WIDTH;
90 const h = Planet.FIELD_HEIGHT;
91 return {
92 x: r.left + ((col + 0.5) / w) * r.width,
93 y: r.top + (1 - fieldY / h) * r.height
94 };
95 }""",
96 [col, field_y],
97 )
98
99
100def touch_start(cdp, x, y):
101 cdp.send(
102 "Input.dispatchTouchEvent",
103 {"type": "touchStart", "touchPoints": [{"x": x, "y": y, "id": 1}]},
104 )
105
106
107def touch_move(cdp, x, y):
108 cdp.send(
109 "Input.dispatchTouchEvent",
110 {"type": "touchMove", "touchPoints": [{"x": x, "y": y, "id": 1}]},
111 )
112
113
114def touch_end(cdp):
115 cdp.send("Input.dispatchTouchEvent", {"type": "touchEnd", "touchPoints": []})
116
117
118def pointer_down(page, cdp, kind, x, y):
119 if kind == "mouse":
120 page.mouse.move(x, y)
121 page.mouse.down()
122 else:
123 touch_start(cdp, x, y)
124
125
126def pointer_move(page, cdp, kind, x, y):
127 if kind == "mouse":
128 page.mouse.move(x, y)
129 else:
130 touch_move(cdp, x, y)
131
132
133def pointer_up(page, cdp, kind):
134 if kind == "mouse":
135 page.mouse.up()
136 else:
137 touch_end(cdp)
138
139
140def drag_to(page, cdp, kind, x1, y1, x2, y2, steps=12, end=True):
141 pointer_down(page, cdp, kind, x1, y1)
142 for i in range(1, steps + 1):
143 t = i / steps
144 pointer_move(page, cdp, kind, x1 + (x2 - x1) * t, y1 + (y2 - y1) * t)
145 if end:
146 pointer_up(page, cdp, kind)
147
148
149def reset_board(page, stacks):
150 page.evaluate(
151 """(stacks) => {
152 const g = app.core;
153 g.spawnInterval = 1e9;
154 g.spawnTimer = 0;
155 g.blocks.length = 0;
156 g.clusters = Object.create(null);
157 g.score = 0;
158 g.drag = null;
159 g.state = 'playing';
160 g.nextBlockId = 1;
161 g.nextClusterId = 1;
162 app.selectTween = null;
163 for (const [col, colors] of Object.entries(stacks)) {
164 colors.forEach((color, row) => g.place(+col, row, color));
165 }
166 }""",
167 stacks,
168 )
169 page.wait_for_timeout(80)
170
171
172def board(page):
173 return page.evaluate(
174 """() => app.core.blocks.map((b) => ({
175 id: b.id, col: b.col, y: b.y, color: b.color, state: b.state
176 }))"""
177 )
178
179
180def col_ys(page, col):
181 return {b["color"]: b["y"] for b in board(page) if b["col"] == col}
182
183
184def check(cond, msg, device):
185 if not cond:
186 FAILURES.append(f"[{device}] {msg}")
187 print(f"FAIL [{device}] {msg}")
188 else:
189 print(f"OK [{device}] {msg}")
190 return cond
191
192
193def shot(page, name):
194 path = OUT / name
195 page.screenshot(path=str(path), full_page=False)
196 print(f"wrote {path} ({path.stat().st_size} bytes)")
197
198
199def start_play(page, kind):
200 page.goto(URL, wait_until="networkidle", timeout=20000)
201 page.wait_for_timeout(400)
202 btn = page.locator("#btn-play")
203 btn.wait_for(state="visible", timeout=5000)
204 if kind == "touch":
205 box = btn.bounding_box()
206 cdp = page.context.new_cdp_session(page)
207 touch_start(cdp, box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
208 touch_end(cdp)
209 page.wait_for_timeout(400)
210 else:
211 cdp = None
212 btn.click()
213 page.wait_for_timeout(400)
214 if page.evaluate("() => app && app.mode") == "planet-select":
215 go = page.locator("#btn-planet-go")
216 go.wait_for(state="visible", timeout=5000)
217 go.click()
218 page.wait_for_timeout(400)
219 if page.evaluate("() => app.mode") != "playing":
220 if page.locator("#btn-play").is_visible():
221 page.locator("#btn-play").click()
222 page.wait_for_timeout(400)
223 if page.locator("#btn-planet-go").is_visible():
224 page.locator("#btn-planet-go").click()
225 page.wait_for_timeout(400)
226 page.wait_for_function("() => app && app.mode === 'playing' && app.core && app.scene", timeout=8000)
227 page.wait_for_selector("canvas", state="visible", timeout=5000)
228 if cdp is None:
229 cdp = page.context.new_cdp_session(page)
230 return cdp
231
232
233def nearly(a, b, eps=0.15):
234 return abs(a - b) <= eps
235
236
237def run_device(browser, device):
238 name = device["name"]
239 kind = device["input"]
240 print(f"\n======== {name} ({kind}, dpr={device['device_scale_factor']}) ========")
241 kw = dict(
242 viewport=device["viewport"],
243 device_scale_factor=device["device_scale_factor"],
244 is_mobile=device["is_mobile"],
245 has_touch=device["has_touch"],
246 )
247 if device["user_agent"]:
248 kw["user_agent"] = device["user_agent"]
249 context = browser.new_context(**kw)
250 page = context.new_page()
251 bag = []
252 page.on("console", lambda m: bag.append(f"{m.type}: {m.text}"))
253 page.on("pageerror", lambda e: bag.append(f"pageerror: {e}"))
254 cdp = start_play(page, kind)
255 check(page.evaluate("() => app.mode") == "playing", "play started", name)
256
257 # --- 1 tile down ---
258 reset_board(page, {"2": [0, 1, 2, 3, 4]})
259 p0 = field_to_client(page, 2, 1.5)
260 p1 = field_to_client(page, 2, 0.5)
261 drag_to(page, cdp, kind, p0["x"], p0["y"], p1["x"], p1["y"], steps=10, end=True)
262 page.wait_for_timeout(60)
263 ys = col_ys(page, 2)
264 check(nearly(ys.get(1, -99), 0), f"1 tile down: grabbed color 1 at y=0, ys={ys}", name)
265 check(nearly(ys.get(0, -99), 1), f"1 tile down: swapped neighbour to y=1, ys={ys}", name)
266 check(nearly(ys.get(2, -99), 2) and nearly(ys.get(3, -99), 3) and nearly(ys.get(4, -99), 4),
267 f"1 tile down: rest of the stack unmoved, ys={ys}", name)
268
269 # --- 1 tile up ---
270 reset_board(page, {"3": [0, 1, 2, 3, 4]})
271 p0 = field_to_client(page, 3, 0.5)
272 p1 = field_to_client(page, 3, 1.5)
273 drag_to(page, cdp, kind, p0["x"], p0["y"], p1["x"], p1["y"], steps=10, end=True)
274 page.wait_for_timeout(60)
275 ys = col_ys(page, 3)
276 check(nearly(ys.get(0, -99), 1), f"1 tile up: grabbed color 0 at y=1, ys={ys}", name)
277 check(nearly(ys.get(1, -99), 0), f"1 tile up: neighbour at y=0, ys={ys}", name)
278 check(nearly(ys.get(2, -99), 2), f"1 tile up: rest unmoved, ys={ys}", name)
279
280 # --- 2 tiles, then stop: pointer held still, nothing else moves ---
281 reset_board(page, {"4": [0, 1, 2, 3, 4]})
282 p0 = field_to_client(page, 4, 0.5)
283 p1 = field_to_client(page, 4, 2.5)
284 drag_to(page, cdp, kind, p0["x"], p0["y"], p1["x"], p1["y"], steps=14, end=False)
285 page.wait_for_timeout(50)
286 mid = col_ys(page, 4)
287 check(nearly(mid.get(0, -99), 2), f"2 tiles: grabbed color 0 at y=2, ys={mid}", name)
288 check(nearly(mid.get(1, -99), 0) and nearly(mid.get(2, -99), 1) and nearly(mid.get(3, -99), 3),
289 f"2 tiles: walked both neighbours, ys={mid}", name)
290 # Pointer stops: more moves at the same point, then a short wait.
291 for _ in range(6):
292 pointer_move(page, cdp, kind, p1["x"], p1["y"])
293 page.wait_for_timeout(30)
294 after = col_ys(page, 4)
295 check(after == mid, f"pointer stopped: stack stays put, mid={mid} after={after}", name)
296 pointer_up(page, cdp, kind)
297 page.wait_for_timeout(80)
298 end = col_ys(page, 4)
299 check(end == mid, f"after release: still at the pointer row, mid={mid} end={end}", name)
300 shot(page, f"t1104-drag-{name}.png")
301
302 if bag:
303 print(f"console [{name}]: {bag[:8]}")
304 context.close()
305
306
307def main():
308 global URL
309 port = free_port()
310 URL = f"http://127.0.0.1:{port}/"
311 print("serving", URL, "from", ROOT / "build")
312 httpd = subprocess.Popen(
313 ["python3", "-m", "http.server", str(port), "--bind", "127.0.0.1", "--directory", str(ROOT / "build")],
314 stdout=subprocess.DEVNULL,
315 stderr=subprocess.DEVNULL,
316 )
317 try:
318 time.sleep(0.4)
319 with sync_playwright() as p:
320 browser = p.chromium.launch(
321 executable_path=CHROME,
322 args=CHROME_ARGS,
323 headless=True,
324 )
325 for device in (DESKTOP, ANDROID, ANDROID_DPR3, IOS):
326 run_device(browser, device)
327 browser.close()
328 finally:
329 httpd.terminate()
330 try:
331 httpd.wait(timeout=3)
332 except Exception:
333 httpd.kill()
334
335 print("\n======== summary ========")
336 if FAILURES:
337 print(f"{len(FAILURES)} failure(s):")
338 for f in FAILURES:
339 print(" -", f)
340 return 1
341 print("all 1:1 drag tests passed")
342 return 0
343
344
345if __name__ == "__main__":
346 sys.exit(main())
test/spontaneous-match.test.js added +149 −0
@@ -0,0 +1,149 @@
1 'use strict';
2
3 const { describe, it } = require('node:test');
4 const assert = require('node:assert/strict');
5 const { makeGame, placeRow, almost, GameCore, Planet } = require('./helpers.js');
6
7 function flyingCluster (game, colsAndY, opts)
8 {
9 opts = opts || {};
10 const cluster = {
11 id: game.nextClusterId++,
12 jumpHeight: opts.jumpHeight != null ? opts.jumpHeight : 3,
13 vy: opts.vy != null ? opts.vy : 4,
14 decel: opts.decel != null ? opts.decel : 2,
15 phase: opts.phase || (opts.vy > 0 ? 'up' : 'down')
16 };
17 game.clusters[cluster.id] = cluster;
18 const members = [];
19 for (const [col, y, color] of colsAndY)
20 {
21 const b = game.createBlock(col, y, color == null ? GameCore.COLOR_GRAY : color, 'flying');
22 b.clusterId = cluster.id;
23 b.vy = cluster.vy;
24 b.flame = color == null || color === GameCore.COLOR_GRAY;
25 members.push(b);
26 }
27 return { cluster, members };
28 }
29
30 describe('Spontaneous matches always become rockets (t1104)', () =>
31 {
32 it('a row that forms on the ground after a block falls launches like a player match', () =>
33 {
34 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
35 g.place(0, 0, 1);
36 g.place(1, 0, 1);
37 const falling = g.createBlock(2, 6, 1, 'falling');
38 falling.vy = -g.planet.fallSpeed;
39 let launched = false;
40 for (let i = 0; i < 800; i++)
41 {
42 g.tick(1 / 120);
43 const cluster = Object.values(g.clusters).find((c) => c.phase === 'up');
44 if (cluster && falling.color === GameCore.COLOR_GRAY)
45 {
46 launched = true;
47 break;
48 }
49 }
50 assert.ok(launched, 'falling block completing a ground row must become a rocket\n' + g.snapshot().picture);
51 assert.equal(g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY).length, 3);
52 const cluster = Object.values(g.clusters).find((c) => c.phase === 'up');
53 assert.ok(cluster.vy > 0);
54 const expectedH = Planet.jumpHeight(g.planet, 3, false);
55 assert.ok(almost(cluster.jumpHeight, expectedH, 1e-9), 'jumpHeight=' + cluster.jumpHeight);
56 });
57
58 it('a row that appears after grey settle and recolor launches', () =>
59 {
60 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 }, seed: 1 });
61 // Non-matching supports so only the recolored greys form a line.
62 g.place(0, 0, 4);
63 g.place(1, 0, 3);
64 g.place(2, 0, 2);
65 const greys = placeRow(g, 1, [0, 1, 2], GameCore.COLOR_GRAY);
66 for (const b of greys)
67 {
68 b.state = 'settling';
69 b.settleTime = 0;
70 b.flame = false;
71 }
72 g.randomColor = () => 0;
73 g.step(g.settleTime + 0.05, 1 / 120);
74 const cluster = Object.values(g.clusters).find((c) => c.phase === 'up');
75 assert.ok(cluster, 'recolored grounded row must launch\n' + g.snapshot().picture
76 + '\nblocks=' + JSON.stringify(g.blocks.map((b) => ({ col: b.col, y: b.y, color: b.color, state: b.state }))));
77 assert.ok(cluster.vy > 0);
78 assert.ok(g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY && b.flame).length >= 3);
79 });
80
81 it('a match after cargo attaches to a flying cluster greys the new line and re-launches the whole cluster', () =>
82 {
83 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
84 // Two color-1 blocks at y=6 with a platform in the gap column, plus a
85 // distant grey so the original cluster is already flying.
86 const { cluster, members } = flyingCluster(g, [
87 [0, 6, 1],
88 [1, 5, 2],
89 [2, 6, 1],
90 [4, 6, GameCore.COLOR_GRAY]
91 ], { vy: 2, decel: 0, jumpHeight: 4, phase: 'up' });
92 const originalHeight = cluster.jumpHeight;
93 const originalVy = cluster.vy;
94 const falling = g.createBlock(1, 10, 1, 'falling');
95 falling.vy = -g.planet.fallSpeed;
96 let relaunched = false;
97 for (let i = 0; i < 800; i++)
98 {
99 g.tick(1 / 120);
100 if (falling.clusterId === cluster.id
101 && falling.color === GameCore.COLOR_GRAY
102 && cluster.phase === 'up'
103 && cluster.vy > originalVy + 0.5)
104 {
105 relaunched = true;
106 break;
107 }
108 }
109 assert.ok(relaunched, 'cargo completing a flying row must re-launch, falling.color='
110 + falling.color + ' state=' + falling.state + ' clusterId=' + falling.clusterId
111 + ' phase=' + cluster.phase + ' vy=' + cluster.vy + '\n' + g.snapshot().picture);
112 assert.equal(members[0].color, GameCore.COLOR_GRAY);
113 assert.equal(members[2].color, GameCore.COLOR_GRAY);
114 assert.equal(falling.color, GameCore.COLOR_GRAY);
115 assert.equal(falling.clusterId, cluster.id);
116 assert.equal(members[3].clusterId, cluster.id, 'existing grey stays linked');
117 assert.equal(cluster.jumpHeight, originalHeight, 'same height as the player-push re-launch');
118 assert.ok(cluster.vy > 0);
119 });
120
121 it('a match that appears when two flying clusters merge greys the line and re-launches', () =>
122 {
123 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
124 const a = flyingCluster(g, [
125 [0, 6, 1],
126 [1, 6, 1],
127 [3, 6, GameCore.COLOR_GRAY]
128 ], { vy: 5, decel: 2, jumpHeight: 4, phase: 'up' });
129 const b = flyingCluster(g, [
130 [3, 6.4, GameCore.COLOR_GRAY],
131 [2, 6.1, 1]
132 ], { vy: 1, decel: 2, jumpHeight: 3, phase: 'up' });
133 assert.ok(a.cluster.id !== b.cluster.id);
134 const keepId = Math.min(a.cluster.id, b.cluster.id);
135
136 g.mergeFlyingClusters();
137
138 const merged = g.clusters[keepId] || Object.values(g.clusters)[0];
139 assert.ok(merged, 'clusters should have merged');
140 const color1 = g.blocks.filter((bl) => bl.col <= 2);
141 assert.ok(color1.every((bl) => bl.color === GameCore.COLOR_GRAY),
142 'the completed row must have turned grey: ' + color1.map((bl) => bl.color).join(','));
143 assert.ok(color1.every((bl) => bl.clusterId === merged.id));
144 assert.equal(merged.phase, 'up');
145 assert.ok(merged.vy > 1, 're-launched from the current position, vy=' + merged.vy);
146 const expectedVy = Planet.launchVelocity(g.planet, merged.jumpHeight);
147 assert.ok(almost(merged.vy, expectedVy, 0.15), 'vy=' + merged.vy + ' expected ' + expectedVy);
148 });
149 });
@@ -0,0 +1,149 @@
1'use strict';
2
3const { describe, it } = require('node:test');
4const assert = require('node:assert/strict');
5const { makeGame, placeRow, almost, GameCore, Planet } = require('./helpers.js');
6
7function flyingCluster (game, colsAndY, opts)
8{
9 opts = opts || {};
10 const cluster = {
11 id: game.nextClusterId++,
12 jumpHeight: opts.jumpHeight != null ? opts.jumpHeight : 3,
13 vy: opts.vy != null ? opts.vy : 4,
14 decel: opts.decel != null ? opts.decel : 2,
15 phase: opts.phase || (opts.vy > 0 ? 'up' : 'down')
16 };
17 game.clusters[cluster.id] = cluster;
18 const members = [];
19 for (const [col, y, color] of colsAndY)
20 {
21 const b = game.createBlock(col, y, color == null ? GameCore.COLOR_GRAY : color, 'flying');
22 b.clusterId = cluster.id;
23 b.vy = cluster.vy;
24 b.flame = color == null || color === GameCore.COLOR_GRAY;
25 members.push(b);
26 }
27 return { cluster, members };
28}
29
30describe('Spontaneous matches always become rockets (t1104)', () =>
31{
32 it('a row that forms on the ground after a block falls launches like a player match', () =>
33 {
34 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
35 g.place(0, 0, 1);
36 g.place(1, 0, 1);
37 const falling = g.createBlock(2, 6, 1, 'falling');
38 falling.vy = -g.planet.fallSpeed;
39 let launched = false;
40 for (let i = 0; i < 800; i++)
41 {
42 g.tick(1 / 120);
43 const cluster = Object.values(g.clusters).find((c) => c.phase === 'up');
44 if (cluster && falling.color === GameCore.COLOR_GRAY)
45 {
46 launched = true;
47 break;
48 }
49 }
50 assert.ok(launched, 'falling block completing a ground row must become a rocket\n' + g.snapshot().picture);
51 assert.equal(g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY).length, 3);
52 const cluster = Object.values(g.clusters).find((c) => c.phase === 'up');
53 assert.ok(cluster.vy > 0);
54 const expectedH = Planet.jumpHeight(g.planet, 3, false);
55 assert.ok(almost(cluster.jumpHeight, expectedH, 1e-9), 'jumpHeight=' + cluster.jumpHeight);
56 });
57
58 it('a row that appears after grey settle and recolor launches', () =>
59 {
60 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 }, seed: 1 });
61 // Non-matching supports so only the recolored greys form a line.
62 g.place(0, 0, 4);
63 g.place(1, 0, 3);
64 g.place(2, 0, 2);
65 const greys = placeRow(g, 1, [0, 1, 2], GameCore.COLOR_GRAY);
66 for (const b of greys)
67 {
68 b.state = 'settling';
69 b.settleTime = 0;
70 b.flame = false;
71 }
72 g.randomColor = () => 0;
73 g.step(g.settleTime + 0.05, 1 / 120);
74 const cluster = Object.values(g.clusters).find((c) => c.phase === 'up');
75 assert.ok(cluster, 'recolored grounded row must launch\n' + g.snapshot().picture
76 + '\nblocks=' + JSON.stringify(g.blocks.map((b) => ({ col: b.col, y: b.y, color: b.color, state: b.state }))));
77 assert.ok(cluster.vy > 0);
78 assert.ok(g.blocks.filter((b) => b.color === GameCore.COLOR_GRAY && b.flame).length >= 3);
79 });
80
81 it('a match after cargo attaches to a flying cluster greys the new line and re-launches the whole cluster', () =>
82 {
83 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
84 // Two color-1 blocks at y=6 with a platform in the gap column, plus a
85 // distant grey so the original cluster is already flying.
86 const { cluster, members } = flyingCluster(g, [
87 [0, 6, 1],
88 [1, 5, 2],
89 [2, 6, 1],
90 [4, 6, GameCore.COLOR_GRAY]
91 ], { vy: 2, decel: 0, jumpHeight: 4, phase: 'up' });
92 const originalHeight = cluster.jumpHeight;
93 const originalVy = cluster.vy;
94 const falling = g.createBlock(1, 10, 1, 'falling');
95 falling.vy = -g.planet.fallSpeed;
96 let relaunched = false;
97 for (let i = 0; i < 800; i++)
98 {
99 g.tick(1 / 120);
100 if (falling.clusterId === cluster.id
101 && falling.color === GameCore.COLOR_GRAY
102 && cluster.phase === 'up'
103 && cluster.vy > originalVy + 0.5)
104 {
105 relaunched = true;
106 break;
107 }
108 }
109 assert.ok(relaunched, 'cargo completing a flying row must re-launch, falling.color='
110 + falling.color + ' state=' + falling.state + ' clusterId=' + falling.clusterId
111 + ' phase=' + cluster.phase + ' vy=' + cluster.vy + '\n' + g.snapshot().picture);
112 assert.equal(members[0].color, GameCore.COLOR_GRAY);
113 assert.equal(members[2].color, GameCore.COLOR_GRAY);
114 assert.equal(falling.color, GameCore.COLOR_GRAY);
115 assert.equal(falling.clusterId, cluster.id);
116 assert.equal(members[3].clusterId, cluster.id, 'existing grey stays linked');
117 assert.equal(cluster.jumpHeight, originalHeight, 'same height as the player-push re-launch');
118 assert.ok(cluster.vy > 0);
119 });
120
121 it('a match that appears when two flying clusters merge greys the line and re-launches', () =>
122 {
123 const g = makeGame({ noSpawn: true, planetOpts: { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 } });
124 const a = flyingCluster(g, [
125 [0, 6, 1],
126 [1, 6, 1],
127 [3, 6, GameCore.COLOR_GRAY]
128 ], { vy: 5, decel: 2, jumpHeight: 4, phase: 'up' });
129 const b = flyingCluster(g, [
130 [3, 6.4, GameCore.COLOR_GRAY],
131 [2, 6.1, 1]
132 ], { vy: 1, decel: 2, jumpHeight: 3, phase: 'up' });
133 assert.ok(a.cluster.id !== b.cluster.id);
134 const keepId = Math.min(a.cluster.id, b.cluster.id);
135
136 g.mergeFlyingClusters();
137
138 const merged = g.clusters[keepId] || Object.values(g.clusters)[0];
139 assert.ok(merged, 'clusters should have merged');
140 const color1 = g.blocks.filter((bl) => bl.col <= 2);
141 assert.ok(color1.every((bl) => bl.color === GameCore.COLOR_GRAY),
142 'the completed row must have turned grey: ' + color1.map((bl) => bl.color).join(','));
143 assert.ok(color1.every((bl) => bl.clusterId === merged.id));
144 assert.equal(merged.phase, 'up');
145 assert.ok(merged.vy > 1, 're-launched from the current position, vy=' + merged.vy);
146 const expectedVy = Planet.launchVelocity(g.planet, merged.jumpHeight);
147 assert.ok(almost(merged.vy, expectedVy, 0.15), 'vy=' + merged.vy + ' expected ' + expectedVy);
148 });
149});
test/swap.test.js +64 −5
@@ -186,7 +186,7 @@ describe('Manual launch of the already-topmost block', () =>
186 186 });
187 187 });
188 188
189 describe('Instant grab, snap and accumulated swaps (t1102/t1103)', () =>
189 describe('Instant grab, snap and 1:1 pointer tracking (t1102/t1103/t1104)', () =>
190 190 {
191 191 it('grabs instantly on beginDrag with no hold delay or elapsed time', () =>
192 192 {
@@ -252,17 +252,76 @@ describe('Instant grab, snap and accumulated swaps (t1102/t1103)', () =>
252 252 assert.equal(g.blockAt(5, 0).color, 3, 'neighbour column is untouched');
253 253 });
254 254
255 it('minimal accumulated travel swaps one step, with no delay before the drag starts', () =>
255 it('a short move that stays inside the same cell does not swap', () =>
256 256 {
257 257 const g = makeGame({ noSpawn: true });
258 258 const a = g.place(0, 0, 0);
259 259 g.place(0, 1, 1);
260 260 g.place(0, 2, 2);
261 261 assert.ok(g.beginDrag(0, 0.5));
262 // Immediately, without ticking, a small upward move of SWAP_DISTANCE swaps once.
262 // Previously SWAP_DISTANCE (0.25) triggered a full-tile jump.
263 263 g.moveDrag(0.5 + GameCore.SWAP_DISTANCE);
264 assert.equal(a.y, 1, 'first swap at the minimal distance, y=' + a.y);
265 assert.ok(g.drag, 'drag is still active');
264 assert.equal(a.y, 0, 'still in the starting cell, y=' + a.y);
265 g.endDrag();
266 });
267
268 it('a 1-tile downward drag swaps exactly one step and stops when the pointer stops', () =>
269 {
270 const g = makeGame({ noSpawn: true });
271 const a = g.place(0, 0, 0);
272 const b = g.place(0, 1, 1);
273 const c = g.place(0, 2, 2);
274 assert.ok(g.beginDrag(0, 1.5));
275 g.moveDrag(0.5);
276 assert.equal(b.y, 0, 'grabbed block followed the pointer one tile down');
277 assert.equal(a.y, 1);
278 assert.equal(c.y, 2);
279 g.moveDrag(0.5);
280 assert.equal(b.y, 0, 'a stopped pointer moves nothing else');
281 assert.equal(a.y, 1);
282 assert.equal(c.y, 2);
283 g.endDrag();
284 });
285
286 it('a 1-tile upward drag swaps exactly one step and stops when the pointer stops', () =>
287 {
288 const g = makeGame({ noSpawn: true });
289 const a = g.place(0, 0, 0);
290 const b = g.place(0, 1, 1);
291 const c = g.place(0, 2, 2);
292 assert.ok(g.beginDrag(0, 0.5));
293 g.moveDrag(1.5);
294 assert.equal(a.y, 1, 'grabbed block followed the pointer one tile up');
295 assert.equal(b.y, 0);
296 assert.equal(c.y, 2);
297 g.moveDrag(1.5);
298 assert.equal(a.y, 1, 'a stopped pointer moves nothing else');
299 assert.equal(b.y, 0);
300 assert.equal(c.y, 2);
301 g.endDrag();
302 });
303
304 it('a 2-tile drag then stop leaves the block on the row under the pointer', () =>
305 {
306 const g = makeGame({ noSpawn: true });
307 const a = g.place(0, 0, 0);
308 const b = g.place(0, 1, 1);
309 const c = g.place(0, 2, 2);
310 const d = g.place(0, 3, 3);
311 assert.ok(g.beginDrag(0, 0.5));
312 g.moveDrag(2.5);
313 assert.equal(a.y, 2);
314 assert.equal(b.y, 0);
315 assert.equal(c.y, 1);
316 assert.equal(d.y, 3);
317 g.moveDrag(2.5);
318 assert.equal(a.y, 2, 'stopped pointer, no further movement');
319 assert.equal(b.y, 0);
320 assert.equal(c.y, 1);
321 assert.equal(d.y, 3);
322 // A twitch that stays in the same cell also leaves the stack alone.
323 g.moveDrag(2.7);
324 assert.equal(a.y, 2);
266 325 g.endDrag();
267 326 });
268 327
@@ -186,7 +186,7 @@ describe('Manual launch of the already-topmost block', () =>
186 });
186 });
187});
187});
188
188
189describe('Instant grab, snap and accumulated swaps (t1102/t1103)', () =>
189describe('Instant grab, snap and 1:1 pointer tracking (t1102/t1103/t1104)', () =>
190{
190{
191 it('grabs instantly on beginDrag with no hold delay or elapsed time', () =>
191 it('grabs instantly on beginDrag with no hold delay or elapsed time', () =>
192 {
192 {
@@ -252,17 +252,76 @@ describe('Instant grab, snap and accumulated swaps (t1102/t1103)', () =>
252 assert.equal(g.blockAt(5, 0).color, 3, 'neighbour column is untouched');
252 assert.equal(g.blockAt(5, 0).color, 3, 'neighbour column is untouched');
253 });
253 });
254
254
255 it('minimal accumulated travel swaps one step, with no delay before the drag starts', () =>
255 it('a short move that stays inside the same cell does not swap', () =>
256 {
256 {
257 const g = makeGame({ noSpawn: true });
257 const g = makeGame({ noSpawn: true });
258 const a = g.place(0, 0, 0);
258 const a = g.place(0, 0, 0);
259 g.place(0, 1, 1);
259 g.place(0, 1, 1);
260 g.place(0, 2, 2);
260 g.place(0, 2, 2);
261 assert.ok(g.beginDrag(0, 0.5));
261 assert.ok(g.beginDrag(0, 0.5));
262 // Immediately, without ticking, a small upward move of SWAP_DISTANCE swaps once.
262 // Previously SWAP_DISTANCE (0.25) triggered a full-tile jump.
263 g.moveDrag(0.5 + GameCore.SWAP_DISTANCE);
263 g.moveDrag(0.5 + GameCore.SWAP_DISTANCE);
264 assert.equal(a.y, 1, 'first swap at the minimal distance, y=' + a.y);
264 assert.equal(a.y, 0, 'still in the starting cell, y=' + a.y);
265 assert.ok(g.drag, 'drag is still active');
265 g.endDrag();
266 });
267
268 it('a 1-tile downward drag swaps exactly one step and stops when the pointer stops', () =>
269 {
270 const g = makeGame({ noSpawn: true });
271 const a = g.place(0, 0, 0);
272 const b = g.place(0, 1, 1);
273 const c = g.place(0, 2, 2);
274 assert.ok(g.beginDrag(0, 1.5));
275 g.moveDrag(0.5);
276 assert.equal(b.y, 0, 'grabbed block followed the pointer one tile down');
277 assert.equal(a.y, 1);
278 assert.equal(c.y, 2);
279 g.moveDrag(0.5);
280 assert.equal(b.y, 0, 'a stopped pointer moves nothing else');
281 assert.equal(a.y, 1);
282 assert.equal(c.y, 2);
283 g.endDrag();
284 });
285
286 it('a 1-tile upward drag swaps exactly one step and stops when the pointer stops', () =>
287 {
288 const g = makeGame({ noSpawn: true });
289 const a = g.place(0, 0, 0);
290 const b = g.place(0, 1, 1);
291 const c = g.place(0, 2, 2);
292 assert.ok(g.beginDrag(0, 0.5));
293 g.moveDrag(1.5);
294 assert.equal(a.y, 1, 'grabbed block followed the pointer one tile up');
295 assert.equal(b.y, 0);
296 assert.equal(c.y, 2);
297 g.moveDrag(1.5);
298 assert.equal(a.y, 1, 'a stopped pointer moves nothing else');
299 assert.equal(b.y, 0);
300 assert.equal(c.y, 2);
301 g.endDrag();
302 });
303
304 it('a 2-tile drag then stop leaves the block on the row under the pointer', () =>
305 {
306 const g = makeGame({ noSpawn: true });
307 const a = g.place(0, 0, 0);
308 const b = g.place(0, 1, 1);
309 const c = g.place(0, 2, 2);
310 const d = g.place(0, 3, 3);
311 assert.ok(g.beginDrag(0, 0.5));
312 g.moveDrag(2.5);
313 assert.equal(a.y, 2);
314 assert.equal(b.y, 0);
315 assert.equal(c.y, 1);
316 assert.equal(d.y, 3);
317 g.moveDrag(2.5);
318 assert.equal(a.y, 2, 'stopped pointer, no further movement');
319 assert.equal(b.y, 0);
320 assert.equal(c.y, 1);
321 assert.equal(d.y, 3);
322 // A twitch that stays in the same cell also leaves the stack alone.
323 g.moveDrag(2.7);
324 assert.equal(a.y, 2);
266 g.endDrag();
325 g.endDrag();
267 });
326 });
268
327
test/touch-playwright.py +4 −4
@@ -64,11 +64,11 @@ def field_to_client(page, col, field_y):
64 64 """([col, fieldY]) => {
65 65 const c = app.scene.canvas;
66 66 const r = c.getBoundingClientRect();
67 const x = (col + 0.5) * app.tile;
68 const y = c.height - fieldY * app.tile;
67 const w = Planet.FIELD_WIDTH;
68 const h = Planet.FIELD_HEIGHT;
69 69 return {
70 x: r.left + x * (r.width / c.width),
71 y: r.top + y * (r.height / c.height)
70 x: r.left + ((col + 0.5) / w) * r.width,
71 y: r.top + (1 - fieldY / h) * r.height
72 72 };
73 73 }""",
74 74 [col, field_y],
@@ -64,11 +64,11 @@ def field_to_client(page, col, field_y):
64 """([col, fieldY]) => {
64 """([col, fieldY]) => {
65 const c = app.scene.canvas;
65 const c = app.scene.canvas;
66 const r = c.getBoundingClientRect();
66 const r = c.getBoundingClientRect();
67 const x = (col + 0.5) * app.tile;
67 const w = Planet.FIELD_WIDTH;
68 const y = c.height - fieldY * app.tile;
68 const h = Planet.FIELD_HEIGHT;
69 return {
69 return {
70 x: r.left + x * (r.width / c.width),
70 x: r.left + ((col + 0.5) / w) * r.width,
71 y: r.top + y * (r.height / c.height)
71 y: r.top + (1 - fieldY / h) * r.height
72 };
72 };
73 }""",
73 }""",
74 [col, field_y],
74 [col, field_y],