| 1 | #!/usr/bin/env python3 |
| 2 | """Layout and flight-arc visuals for t1125 (wide / narrow / mobile).""" |
| 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 | ROOT = Path("/workspace/meteors") |
| 14 | OUT = Path("/workspace/meteors-shots") |
| 15 | OUT.mkdir(parents=True, exist_ok=True) |
| 16 | VIDEO = Path("/workspace/meteors-video") |
| 17 | VIDEO.mkdir(parents=True, exist_ok=True) |
| 18 | CHROME = "/usr/bin/google-chrome" |
| 19 | CHROME_ARGS = [ |
| 20 | "--use-gl=angle", |
| 21 | "--use-angle=swiftshader", |
| 22 | "--no-sandbox", |
| 23 | "--disable-dev-shm-usage", |
| 24 | "--disable-gpu-sandbox", |
| 25 | ] |
| 26 | FAILURES = [] |
| 27 | |
| 28 | |
| 29 | def free_port(): |
| 30 | s = socket.socket() |
| 31 | s.bind(("127.0.0.1", 0)) |
| 32 | port = s.getsockname()[1] |
| 33 | s.close() |
| 34 | return port |
| 35 | |
| 36 | |
| 37 | def check(cond, msg): |
| 38 | if not cond: |
| 39 | FAILURES.append(msg) |
| 40 | print("FAIL", msg) |
| 41 | else: |
| 42 | print("OK ", msg) |
| 43 | return cond |
| 44 | |
| 45 | |
| 46 | def shot(page, name): |
| 47 | path = OUT / name |
| 48 | page.screenshot(path=str(path), full_page=False) |
| 49 | print(f"wrote {path} ({path.stat().st_size} bytes)") |
| 50 | return path |
| 51 | |
| 52 | |
| 53 | def start_http(port): |
| 54 | proc = subprocess.Popen( |
| 55 | ["python3", "-m", "http.server", str(port), "--bind", "127.0.0.1", |
| 56 | "--directory", str(ROOT / "build")], |
| 57 | stdout=subprocess.DEVNULL, |
| 58 | stderr=subprocess.DEVNULL, |
| 59 | ) |
| 60 | time.sleep(0.35) |
| 61 | if proc.poll() is not None: |
| 62 | raise RuntimeError("http.server failed to start") |
| 63 | return proc |
| 64 | |
| 65 | |
| 66 | def open_offline(page, url, round_n=1): |
| 67 | page.goto(url, wait_until="domcontentloaded", timeout=15000) |
| 68 | page.wait_for_timeout(400) |
| 69 | page.locator("#btn-offline").click() |
| 70 | page.wait_for_selector("#planet-select:not([hidden])", timeout=8000) |
| 71 | page.locator("#btn-planet-go").click() |
| 72 | page.wait_for_function( |
| 73 | "() => app && app.mode === 'playing' && app.offline && app.battle && app.core", |
| 74 | timeout=10000, |
| 75 | ) |
| 76 | if round_n != 1: |
| 77 | page.evaluate( |
| 78 | """(round) => { |
| 79 | teardownPlay(); |
| 80 | startPlay({ planet: app.planet, offline: true, round: round }); |
| 81 | }""", |
| 82 | round_n, |
| 83 | ) |
| 84 | page.wait_for_function( |
| 85 | "() => app && app.mode === 'playing' && app.battle && app.miniLayout", |
| 86 | timeout=8000, |
| 87 | ) |
| 88 | page.wait_for_timeout(250) |
| 89 | |
| 90 | |
| 91 | LAYOUT_INFO = """() => { |
| 92 | const plan = app.miniLayout || {}; |
| 93 | const fieldEl = app.scene && app.scene.canvas; |
| 94 | const fr = fieldEl ? fieldEl.getBoundingClientRect() : null; |
| 95 | const minis = [...document.querySelectorAll('#minis .mini')].map((el) => { |
| 96 | const r = el.getBoundingClientRect(); |
| 97 | const c = el.querySelector('canvas'); |
| 98 | const cr = c ? c.getBoundingClientRect() : r; |
| 99 | return { |
| 100 | id: el.getAttribute('data-player'), |
| 101 | left: r.left, right: r.right, top: r.top, bottom: r.bottom, |
| 102 | cx: cr.left + cr.width / 2, |
| 103 | cy: cr.top + cr.height / 2 |
| 104 | }; |
| 105 | }); |
| 106 | return { |
| 107 | mode: plan.mode, |
| 108 | sidesClass: document.getElementById('minis').classList.contains('sides'), |
| 109 | n: plan.n, |
| 110 | field: fr ? { left: fr.left, right: fr.right, top: fr.top, bottom: fr.bottom, |
| 111 | x: app.fieldX, y: app.fieldY, w: app.fieldW, h: app.fieldH } : null, |
| 112 | positions: plan.positions || [], |
| 113 | minis, |
| 114 | tile: app.tile, |
| 115 | vw: window.innerWidth, |
| 116 | vh: window.innerHeight |
| 117 | }; |
| 118 | }""" |
| 119 | |
| 120 | |
| 121 | |
| 122 | INJECT_FLIGHTS = """(age) => { |
| 123 | if (age == null) age = 0.55; |
| 124 | const plan = app.miniLayout; |
| 125 | const field = app.scene.canvas.getBoundingClientRect(); |
| 126 | function miniCell(id, col, y) { |
| 127 | if (Online.miniCellViewport) { |
| 128 | const p = Online.miniCellViewport(id, col, y); |
| 129 | if (p && isFinite(p.x)) return p; |
| 130 | } |
| 131 | const el = document.querySelector('#minis .mini[data-player="' + id + '"] canvas'); |
| 132 | if (!el) return { x: 80, y: 80 }; |
| 133 | return Online.cellViewport(col, y, el.getBoundingClientRect()); |
| 134 | } |
| 135 | const bots = (app.battle.bots || []).map(b => b.id); |
| 136 | const a = bots[0] || 'bot-1'; |
| 137 | const b = bots[1] || bots[0] || 'bot-2'; |
| 138 | const landCol = 3; |
| 139 | // Launch from the real top-row cell, not from above the canvas (t1134). |
| 140 | const pStart = Online.cellViewport(4, 12, field); |
| 141 | const pEnd = Online.fieldEntry ? Online.fieldEntry(landCol) : Online.cellViewport(landCol, 13, field); |
| 142 | if (typeof Online.clearFlights === 'function') Online.clearFlights(); |
| 143 | const flights = [ |
| 144 | { id: 'vis-p2e', client_id: 'vis-p2e', from_id: 'player', target_id: a, miss: false, color: 0, flight_duration: 1.2, age: age, land_col: landCol, col: 4, y: 12 }, |
| 145 | { id: 'vis-e2p', client_id: 'vis-e2p', from_id: a, target_id: 'player', miss: false, color: 1, flight_duration: 1.2, age: age, land_col: landCol, col: 2, y: 12 }, |
| 146 | { id: 'vis-e2e', client_id: 'vis-e2e', from_id: a, target_id: b, miss: false, color: 2, flight_duration: 1.2, age: age, land_col: 7, col: 5, y: 12 }, |
| 147 | { id: 'vis-emiss', client_id: 'vis-emiss', from_id: b, target_id: null, miss: true, color: 3, flight_duration: 1.2, age: Math.min(age, 0.45), col: 1, y: 12 } |
| 148 | ]; |
| 149 | const aOut = miniCell(a, 2, 12); |
| 150 | const bOut = miniCell(b, 1, 12); |
| 151 | const locals = { |
| 152 | 'vis-p2e': { from_id: 'player', color: 0, startX: pStart.x, startY: pStart.y, col: 4, y: 12, land_col: landCol }, |
| 153 | 'vis-e2p': { from_id: a, color: 1, startX: aOut.x, startY: aOut.y, col: 2, y: 12, land_col: landCol }, |
| 154 | 'vis-e2e': { from_id: a, color: 2, startX: aOut.x, startY: aOut.y, col: 5, y: 12, land_col: 7 }, |
| 155 | 'vis-emiss': { from_id: b, color: 3, startX: bOut.x, startY: bOut.y, col: 1, y: 12 } |
| 156 | }; |
| 157 | Online.spawnFlights(flights, locals); |
| 158 | Online.tickFlights(); |
| 159 | const front = [...document.querySelectorAll('#flights .flight')].map(el => ({ |
| 160 | src: el.getAttribute('src') || el.src, |
| 161 | transform: el.style.transform, |
| 162 | parent: 'front' |
| 163 | })); |
| 164 | const back = [...document.querySelectorAll('#flights-back .flight')].map(el => ({ |
| 165 | src: el.getAttribute('src') || el.src, |
| 166 | transform: el.style.transform, |
| 167 | parent: 'back' |
| 168 | })); |
| 169 | const kinds = (Online._flights || []).map(f => { |
| 170 | const raw = Math.min(0.999, Math.max(0, (performance.now() - f.t0) / f.duration)); |
| 171 | const u = f.miss ? Online.easeInOutCubic(raw) : Online.smoothParam(raw, 0.85, 0.85); |
| 172 | const pt = Online.flightPointAt(f, u); |
| 173 | const samples = []; |
| 174 | if (f.kind === 'enemy-to-player' || f.kind === 'player-to-enemy') |
| 175 | { |
| 176 | for (let i = 0; i <= 16; i++) |
| 177 | { |
| 178 | const su = i / 16; |
| 179 | const sp = Online.flightPointAt(f, su); |
| 180 | const inside = !!(f.field && Online.pointInFieldInterior(sp.x, sp.y, f.field)); |
| 181 | const allowed = !f.field || Online.pointAllowedOnArc(sp, f.field, f.start, f.end); |
| 182 | samples.push({ u: su, x: sp.x, y: sp.y, inside: inside, allowed: allowed }); |
| 183 | } |
| 184 | } |
| 185 | const d0 = f.curve ? Online.curveDeriv(f.curve, 0) : null; |
| 186 | const d1 = f.curve ? Online.curveDeriv(f.curve, 1) : null; |
| 187 | return { |
| 188 | kind: f.kind, miss: f.miss, |
| 189 | startScale: f.startScale, endScale: f.endScale, |
| 190 | parent: (f.el && f.el.parentElement && f.el.parentElement.id) || '', |
| 191 | src: (f.el && (f.el.getAttribute('src') || f.el.src)) || '', |
| 192 | color: f.color, |
| 193 | landCol: f.landCol, |
| 194 | start: f.start, |
| 195 | end: f.end, |
| 196 | pos: pt, |
| 197 | samples: samples, |
| 198 | insideNow: f.field ? Online.pointInFieldInterior(pt.x, pt.y, f.field) : false, |
| 199 | hasCurve: !!f.curve, |
| 200 | segments: (f.curve && f.curve.segments) ? f.curve.segments.length : (f.curve ? 1 : 0), |
| 201 | d0: d0, d1: d1 |
| 202 | }; |
| 203 | }); |
| 204 | const expectedEndX = field.left + ((landCol + 0.5) / 10) * field.width; |
| 205 | const expectedEndY = field.top + (1 - (13.5) / 13) * field.height; |
| 206 | const expectedStartY = field.top + (1 - (12.5) / 13) * field.height; |
| 207 | return { |
| 208 | front: front.length, |
| 209 | back: back.length, |
| 210 | kinds, |
| 211 | expectedEndX, |
| 212 | expectedEndY, |
| 213 | expectedStartY, |
| 214 | field: { left: field.left, right: field.right, top: field.top, bottom: field.bottom, |
| 215 | width: field.width, height: field.height }, |
| 216 | pad: field.top, |
| 217 | hudH: app.hudH, |
| 218 | mode: plan.mode, |
| 219 | tile: app.tile |
| 220 | }; |
| 221 | }""" |
| 222 | |
| 223 | |
| 224 | |
| 225 | EDGE = 16 |
| 226 | |
| 227 | |
| 228 | def assert_sides(info, tag, expect_rows=False, expect_one_row=False, n=None): |
| 229 | check(info["mode"] == "sides", f"{tag}: mode is sides (got {info['mode']})") |
| 230 | check(info["sidesClass"], f"{tag}: #minis has .sides") |
| 231 | field = info["field"] |
| 232 | minis = info["minis"] |
| 233 | positions = info.get("positions") or [] |
| 234 | vw = info.get("vw") or 0 |
| 235 | check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})") |
| 236 | if n is not None: |
| 237 | check(len(minis) == n, f"{tag}: expected {n} minis, got {len(minis)}") |
| 238 | if field: |
| 239 | check(field["top"] >= 56 + 70 or field.get("y", 0) >= 56 + 70 |
| 240 | or (info.get("vh") or 900) < 600 and field["top"] >= 56 + 80, |
| 241 | f"{tag}: wide layout has top padding (field.top={field['top']:.1f}, y={field.get('y')})") |
| 242 | if not field or not minis: |
| 243 | return |
| 244 | |
| 245 | # Bottom-aligned with the field (row 0). |
| 246 | row0 = [] |
| 247 | for i, m in enumerate(minis): |
| 248 | pos = positions[i] if i < len(positions) else {} |
| 249 | if pos.get("row", 0) == 0: |
| 250 | row0.append(m) |
| 251 | check(abs(m["bottom"] - field["bottom"]) <= 10, |
| 252 | f"{tag}: mini {i} ({m['id']}) is bottom-aligned " |
| 253 | f"(bottom={m['bottom']:.1f} field.bottom={field['bottom']:.1f})") |
| 254 | check(m["top"] >= 40, |
| 255 | f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})") |
| 256 | # Every mini sits entirely to the left or right of the field. |
| 257 | left_of = m["right"] <= field["left"] + 2 |
| 258 | right_of = m["left"] >= field["right"] - 2 |
| 259 | check(left_of or right_of, |
| 260 | f"{tag}: mini {i} is beside the field, not above it") |
| 261 | |
| 262 | # Alternating sides, outer-edge anchored, filling inward (t1133). |
| 263 | if len(minis) >= 1: |
| 264 | check(minis[0]["left"] <= EDGE + 6, |
| 265 | f"{tag}: bot 1 is at the left outer edge (left={minis[0]['left']:.1f})") |
| 266 | if len(minis) >= 2: |
| 267 | check(minis[1]["right"] >= vw - EDGE - 6, |
| 268 | f"{tag}: bot 2 is at the right outer edge (right={minis[1]['right']:.1f} vw={vw})") |
| 269 | if len(minis) >= 3: |
| 270 | check(minis[2]["left"] > minis[0]["left"] + 20, |
| 271 | f"{tag}: bot 3 is inward of bot 1, toward the field " |
| 272 | f"({minis[0]['left']:.1f} → {minis[2]['left']:.1f})") |
| 273 | # Same row when they fit (3 bots on a wide-enough side). |
| 274 | if positions and positions[0].get("row") == 0 and positions[2].get("row") == 0: |
| 275 | check(abs(minis[2]["bottom"] - minis[0]["bottom"]) <= 6, |
| 276 | f"{tag}: bot 3 shares the bottom row with bot 1") |
| 277 | if len(minis) >= 4: |
| 278 | check(minis[3]["right"] < minis[1]["right"] - 20, |
| 279 | f"{tag}: bot 4 is inward of bot 2, toward the field") |
| 280 | |
| 281 | if expect_one_row: |
| 282 | rows = [p.get("row", 0) for p in positions] if positions else [] |
| 283 | check(rows and all(r == 0 for r in rows), |
| 284 | f"{tag}: all minis sit in a single row (rows={rows})") |
| 285 | if expect_rows: |
| 286 | rows = [p.get("row", 0) for p in positions] if positions else [] |
| 287 | check(any(r >= 1 for r in rows), |
| 288 | f"{tag}: wraps to a second row (rows={rows})") |
| 289 | # Wrapped minis start again at the outer edges and sit above row 0. |
| 290 | lefts = [(i, minis[i], positions[i]) for i in range(len(minis)) |
| 291 | if i < len(positions) and positions[i].get("side") == "left"] |
| 292 | r0 = [t for t in lefts if t[2].get("row") == 0 and t[2].get("fromOuter") == 0] |
| 293 | r1 = [t for t in lefts if t[2].get("row") == 1 and t[2].get("fromOuter") == 0] |
| 294 | if r0 and r1: |
| 295 | check(abs(r1[0][1]["left"] - r0[0][1]["left"]) <= 4, |
| 296 | f"{tag}: wrapped left mini is again at the outer edge") |
| 297 | check(r1[0][1]["bottom"] <= r0[0][1]["top"] + 8, |
| 298 | f"{tag}: wrapped row sits above the first") |
| 299 | |
| 300 | |
| 301 | def assert_top(info, tag): |
| 302 | check(info["mode"] == "top", f"{tag}: mode is top (got {info['mode']})") |
| 303 | check(not info["sidesClass"], f"{tag}: #minis is not .sides") |
| 304 | field = info["field"] |
| 305 | minis = info["minis"] |
| 306 | check(len(minis) >= 1, f"{tag}: at least one mini") |
| 307 | if not field or not minis: |
| 308 | return |
| 309 | for i, m in enumerate(minis): |
| 310 | check(m["bottom"] <= field["top"] + 12, |
| 311 | f"{tag}: mini {i} sits above the field " |
| 312 | f"(bottom={m['bottom']:.1f} field.top={field['top']:.1f})") |
| 313 | |
| 314 | |
| 315 | def assert_flights(info, tag, expect_behind=True, expect_around=True): |
| 316 | check(info["front"] >= 3, f"{tag}: front flights present ({info['front']})") |
| 317 | kinds = {k["kind"]: k for k in info["kinds"]} |
| 318 | check("player-to-enemy" in kinds, f"{tag}: player-to-enemy") |
| 319 | check("enemy-to-player" in kinds, f"{tag}: enemy-to-player") |
| 320 | check("enemy-miss" in kinds, f"{tag}: enemy-miss") |
| 321 | if "player-to-enemy" in kinds: |
| 322 | k = kinds["player-to-enemy"] |
| 323 | check(k["startScale"] > k["endScale"], |
| 324 | f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})") |
| 325 | check("gray" in (k.get("src") or "").lower() or k.get("color") == -1, |
| 326 | f"{tag}: player-to-enemy is grey (src={k.get('src')} color={k.get('color')})") |
| 327 | if k.get("start") and info.get("expectedStartY") is not None: |
| 328 | check(k["start"]["y"] > info["field"]["top"], |
| 329 | f"{tag}: player-to-enemy starts inside the field " |
| 330 | f"(start.y={k['start']['y']:.1f} field.top={info['field']['top']:.1f})") |
| 331 | check(abs(k["start"]["y"] - info["expectedStartY"]) < 8, |
| 332 | f"{tag}: player-to-enemy starts at the top-row cell " |
| 333 | f"(start.y={k['start']['y']:.1f} expected={info['expectedStartY']:.1f})") |
| 334 | if k.get("d0"): |
| 335 | check(k["d0"]["y"] < 0, |
| 336 | f"{tag}: player-to-enemy leaves going up (d0.y={k['d0']['y']:.1f})") |
| 337 | check(k.get("hasCurve"), f"{tag}: player-to-enemy uses a smooth curve") |
| 338 | if expect_around: |
| 339 | forbidden = [s for s in (k.get("samples") or []) if s.get("inside") and not s.get("allowed")] |
| 340 | check(len(forbidden) == 0, |
| 341 | f"{tag}: player-to-enemy stays in launch/land corridors " |
| 342 | f"({len(forbidden)} forbidden {forbidden[:3]})") |
| 343 | if "enemy-to-player" in kinds: |
| 344 | k = kinds["enemy-to-player"] |
| 345 | check(k["endScale"] > k["startScale"], |
| 346 | f"{tag}: enemy-to-player grows ({k['startScale']:.2f}→{k['endScale']:.2f})") |
| 347 | check(k.get("landCol") == 3, |
| 348 | f"{tag}: enemy-to-player landCol is 3 (got {k.get('landCol')})") |
| 349 | if k.get("end") and info.get("expectedEndX"): |
| 350 | check(abs(k["end"]["x"] - info["expectedEndX"]) < 3, |
| 351 | f"{tag}: arc ends at column 3 " |
| 352 | f"(end.x={k['end']['x']:.1f} expected={info['expectedEndX']:.1f})") |
| 353 | if k.get("end") and info.get("expectedEndY") is not None: |
| 354 | check(abs(k["end"]["y"] - info["expectedEndY"]) < 8, |
| 355 | f"{tag}: arc ends at the spawn pose (y=13) " |
| 356 | f"(end.y={k['end']['y']:.1f} expected={info['expectedEndY']:.1f})") |
| 357 | check(k["end"]["y"] < info["field"]["top"] + 2, |
| 358 | f"{tag}: incoming end is at/above the canvas top " |
| 359 | f"(end.y={k['end']['y']:.1f} field.top={info['field']['top']:.1f})") |
| 360 | if k.get("d1"): |
| 361 | check(k["d1"]["y"] > 0, |
| 362 | f"{tag}: enemy-to-player arrives going down (d1.y={k['d1']['y']:.1f})") |
| 363 | check(abs(k.get("endScale", 0) - 1) < 0.05, |
| 364 | f"{tag}: incoming ends at full tile scale ({k.get('endScale')})") |
| 365 | check(k.get("hasCurve"), f"{tag}: enemy-to-player uses a smooth curve") |
| 366 | check("gray" in (k.get("src") or "").lower() or k.get("color") == -1, |
| 367 | f"{tag}: enemy-to-player is grey (src={k.get('src')} color={k.get('color')})") |
| 368 | if expect_around and k.get("samples"): |
| 369 | forbidden = [s for s in k["samples"] if s.get("inside") and not s.get("allowed")] |
| 370 | check(len(forbidden) == 0, |
| 371 | f"{tag}: enemy-to-player stays in launch/land corridors " |
| 372 | f"({len(forbidden)} forbidden {forbidden[:3]})") |
| 373 | if "enemy-to-enemy" in kinds: |
| 374 | k = kinds["enemy-to-enemy"] |
| 375 | check(abs(k["startScale"] - k["endScale"]) < 0.05, |
| 376 | f"{tag}: enemy-to-enemy stays small ({k['startScale']:.2f})") |
| 377 | check(k["parent"] == "flights-back", |
| 378 | f"{tag}: enemy-to-enemy is in #flights-back (got {k['parent']})") |
| 379 | if expect_behind: |
| 380 | check(info["back"] >= 1, f"{tag}: at least one behind-field flight") |
| 381 | check("gray" in (k.get("src") or "").lower() or k.get("color") == -1, |
| 382 | f"{tag}: enemy-to-enemy is grey (src={k.get('src')} color={k.get('color')})") |
| 383 | if "enemy-miss" in kinds: |
| 384 | k = kinds["enemy-miss"] |
| 385 | check(k["startScale"] < 0.7, |
| 386 | f"{tag}: enemy-miss starts small ({k['startScale']:.2f})") |
| 387 | check(k["parent"] == "flights", |
| 388 | f"{tag}: enemy-miss is in #flights (got {k['parent']})") |
| 389 | check(k.get("color") != -1, |
| 390 | f"{tag}: enemy-miss keeps the sender colour (color={k.get('color')})") |
| 391 | |
| 392 | |
| 393 | def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode, |
| 394 | expect_one_row=False, expect_rows=False, n_minis=None): |
| 395 | context = browser.new_context( |
| 396 | viewport={"width": width, "height": height}, |
| 397 | device_scale_factor=1, |
| 398 | is_mobile=is_mobile, |
| 399 | has_touch=is_mobile, |
| 400 | ) |
| 401 | page = context.new_page() |
| 402 | open_offline(page, url, round_n=round_n) |
| 403 | page.wait_for_timeout(300) |
| 404 | info = page.evaluate(LAYOUT_INFO) |
| 405 | field = info.get("field") or {} |
| 406 | print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')}, |
| 407 | "fieldY", field.get("y"), "field.top", field.get("top"), |
| 408 | "positions", info.get("positions")) |
| 409 | if expect_mode == "sides": |
| 410 | assert_sides(info, name, expect_rows=expect_rows, expect_one_row=expect_one_row, |
| 411 | n=n_minis) |
| 412 | else: |
| 413 | assert_top(info, name) |
| 414 | shot(page, f"t1134-{name}-layout.png") |
| 415 | |
| 416 | flights = page.evaluate(INJECT_FLIGHTS, 0.55) |
| 417 | print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'expectedEndY', 'expectedStartY', 'hudH', 'mode') if k in flights}) |
| 418 | for knd in flights["kinds"]: |
| 419 | print(f" {knd['kind']}: color={knd.get('color')} landCol={knd.get('landCol')} " |
| 420 | f"src={knd.get('src')} curve={knd.get('hasCurve')}/{knd.get('segments')} " |
| 421 | f"start={knd.get('start')} end={knd.get('end')} pos={knd.get('pos')}") |
| 422 | assert_flights(flights, name) |
| 423 | shot(page, f"t1134-{name}-midarc.png") |
| 424 | |
| 425 | if name in ("1024x532-3bots", "1920x1080-8bots", "desktop-wide"): |
| 426 | for age, label in ((0.18, "early"), (0.85, "late")): |
| 427 | page.evaluate(INJECT_FLIGHTS, age) |
| 428 | shot(page, f"t1134-{name}-midarc-{label}.png") |
| 429 | context.close() |
| 430 | |
| 431 | |
| 432 | def record_arcs_video(browser, url): |
| 433 | """A short webm of two volleys flying out, over, and into the field (t1134/t1135).""" |
| 434 | VIDEO.mkdir(parents=True, exist_ok=True) |
| 435 | dest = VIDEO / "t1134-arcs-1920x1080.webm" |
| 436 | context = browser.new_context( |
| 437 | viewport={"width": 1920, "height": 1080}, |
| 438 | device_scale_factor=1, |
| 439 | record_video_dir=str(VIDEO / "_raw"), |
| 440 | record_video_size={"width": 1920, "height": 1080}, |
| 441 | ) |
| 442 | page = context.new_page() |
| 443 | open_offline(page, url, round_n=25) |
| 444 | page.wait_for_timeout(400) |
| 445 | # Live volleys at age 0 so tickFlights animates them in the game loop. |
| 446 | page.evaluate(INJECT_FLIGHTS, 0) |
| 447 | page.wait_for_timeout(1300) |
| 448 | page.evaluate(INJECT_FLIGHTS, 0) |
| 449 | page.wait_for_timeout(1400) |
| 450 | page.close() |
| 451 | context.close() |
| 452 | # Playwright writes the webm next to the context; move it into place. |
| 453 | raw = list((VIDEO / "_raw").glob("*.webm")) |
| 454 | if raw: |
| 455 | raw[0].replace(dest) |
| 456 | print(f"wrote {dest} ({dest.stat().st_size} bytes)") |
| 457 | else: |
| 458 | FAILURES.append("video: no webm produced") |
| 459 | print("FAIL video: no webm produced") |
| 460 | return |
| 461 | if dest.stat().st_size < 10000: |
| 462 | FAILURES.append(f"video: suspiciously small ({dest.stat().st_size} bytes)") |
| 463 | |
| 464 | |
| 465 | def main(): |
| 466 | |
| 467 | port = free_port() |
| 468 | http = start_http(port) |
| 469 | url = f"http://127.0.0.1:{port}/" |
| 470 | try: |
| 471 | with sync_playwright() as p: |
| 472 | browser = p.chromium.launch( |
| 473 | executable_path=CHROME, |
| 474 | args=CHROME_ARGS, |
| 475 | headless=True, |
| 476 | ) |
| 477 | # Tim's short wide window, 3 bots (ronde 3) |
| 478 | run_viewport(browser, url, "1024x532-3bots", 1024, 532, False, 3, "sides", |
| 479 | expect_one_row=True, n_minis=3) |
| 480 | # 8 bots: wrap on 1280, one row on 1400 and 1920 |
| 481 | run_viewport(browser, url, "1280x900-8bots", 1280, 900, False, 25, "sides", |
| 482 | expect_rows=True, n_minis=8) |
| 483 | run_viewport(browser, url, "1400x900-8bots", 1400, 900, False, 25, "sides", |
| 484 | expect_one_row=True, n_minis=8) |
| 485 | run_viewport(browser, url, "1920x1080-8bots", 1920, 1080, False, 25, "sides", |
| 486 | expect_one_row=True, n_minis=8) |
| 487 | record_arcs_video(browser, url) |
| 488 | browser.close() |
| 489 | finally: |
| 490 | http.terminate() |
| 491 | try: |
| 492 | http.wait(timeout=3) |
| 493 | except subprocess.TimeoutExpired: |
| 494 | http.kill() |
| 495 | |
| 496 | if FAILURES: |
| 497 | print(f"\n{len(FAILURES)} failure(s):") |
| 498 | for f in FAILURES: |
| 499 | print(" -", f) |
| 500 | return 1 |
| 501 | print("\nall minis/flights checks passed") |
| 502 | return 0 |
| 503 | |
| 504 | |
| 505 | if __name__ == "__main__": |
| 506 | sys.exit(main()) |
projects-timfalken-com meteors