BlueGit

projects-timfalken-com meteors

test: outer-edge horizontal mini layout (t1127, t1131, t1133)

Unit tests cover 1024×532 with 3 bots, a single row for 8 bots at
1400 and 1920, and wrapping at 1280. Playwright shots match Tim's
drawing and include mid-arc frames.

timfa Grok Bot · pushed by timfa

Authored 2026-11-13 · 4 days ago

Hash
6ce67f271ae8ffa46e299e574e8ce79505f6ab17
Parent
a8032a29
2 files changed +185 −84
test/mini-layout.test.js +94 −39
@@ -5,67 +5,124 @@ const assert = require('node:assert/strict');
5 5 const MiniLayout = require('../src/miniLayout.js');
6 6 const Online = require('../src/online.js');
7 7
8 describe('MiniLayout (t1125)', () =>
8 function hudOf (vh)
9 9 {
10 it('uses sides on a wide desktop and top on a narrow one', () =>
10 return Math.max(56, Math.round(vh * 0.09));
11 }
12 function marginOf (vw, vh)
13 {
14 return Math.max(6, Math.round(Math.min(vw, vh) * 0.015));
15 }
16 function plan (vw, vh, n)
17 {
18 return MiniLayout.plan(vw, vh, n, hudOf(vh), marginOf(vw, vh));
19 }
20
21 describe('MiniLayout (t1125 / t1127 / t1131 / t1133)', () =>
22 {
23 it('uses sides on a wide desktop and top on a narrow or portrait one', () =>
11 24 {
12 const wide = MiniLayout.plan(1280, 900, 2, 70, 8);
25 const wide = plan(1280, 900, 2);
13 26 assert.equal(wide.mode, 'sides', '1280×900 with 2 opponents is sides');
14 27 assert.ok(wide.tile >= MiniLayout.MIN_TILE_FOR_SIDES, 'tiles stay large enough');
15 28 assert.equal(wide.miniH, 0, 'sides mode does not reserve a top band');
16 29 assert.equal(wide.positions.length, 2);
17 30
18 const justUnder = MiniLayout.plan(MiniLayout.MIN_VIEWPORT_FOR_SIDES - 1, 900, 2, 70, 8);
19 assert.equal(justUnder.mode, 'top', 'just under 960 px stays on top');
20 const narrow = MiniLayout.plan(720, 800, 2, 70, 8);
21 assert.equal(narrow.mode, 'top', '720-wide keeps the top row');
31 const shortWide = plan(1024, 532, 3);
32 assert.equal(shortWide.mode, 'sides', '1024×532 (Tim\'s window) is sides, not a top row');
33 assert.equal(shortWide.positions.length, 3);
34
35 const narrow = plan(720, 800, 2);
36 assert.equal(narrow.mode, 'top', '720-tall-ish keeps the top row');
22 37 assert.ok(narrow.miniH > 0, 'top mode reserves height above the field');
23 38 assert.equal(narrow.positions.length, 0);
24 39
25 const mobile = MiniLayout.plan(393, 851, 1, 60, 6);
40 const mobile = plan(393, 851, 1);
26 41 assert.equal(mobile.mode, 'top', 'phone stays on the top layout');
27 42 });
28 43
29 it('alternates first left, second right, third left, and stacks upward', () =>
44 it('anchors minis to the outer edges and fills inward, bottom-aligned (t1133)', () =>
30 45 {
31 const plan = MiniLayout.plan(1400, 900, 6, 70, 8);
32 assert.equal(plan.mode, 'sides');
33 assert.equal(plan.positions.length, 6);
34 const sides = plan.positions.map(p => p.side);
35 assert.deepEqual(sides, ['left', 'right', 'left', 'right', 'left', 'right']);
36 const rows = plan.positions.map(p => p.row);
37 assert.deepEqual(rows, [0, 0, 1, 1, 2, 2]);
38
39 // Lowest row aligns with (or near) the field bottom; higher rows go up.
40 const lefts = plan.positions.filter(p => p.side === 'left');
41 assert.ok(lefts[0].y + lefts[0].h <= plan.fieldY + plan.fieldH + 2,
42 'first row sits at the field bottom');
43 assert.ok(lefts[1].y < lefts[0].y, 'second row is above the first');
44 assert.ok(lefts[2].y < lefts[1].y, 'third row is above the second');
45 // Same x for a column
46 assert.equal(lefts[0].x, lefts[1].x);
47 assert.ok(lefts[0].x + lefts[0].w <= plan.fieldX - MiniLayout.GAP + 0.5);
48 const rights = plan.positions.filter(p => p.side === 'right');
49 assert.ok(rights[0].x >= plan.fieldX + plan.fieldW + MiniLayout.GAP - 0.5);
46 const p = plan(1024, 532, 3);
47 assert.equal(p.mode, 'sides');
48 assert.equal(p.positions.length, 3);
49 assert.deepEqual(p.positions.map(x => x.side), ['left', 'right', 'left']);
50 assert.deepEqual(p.positions.map(x => x.row), [0, 0, 0], '3 bots fit in one row');
51 assert.deepEqual(p.positions.map(x => x.fromOuter), [0, 0, 1]);
52
53 const [a, b, c] = p.positions;
54 assert.ok(Math.abs(a.x - MiniLayout.EDGE) <= 1, 'bot 1 sits at the left screen edge, x=' + a.x);
55 assert.ok(Math.abs((b.x + b.w) - (1024 - MiniLayout.EDGE)) <= 1,
56 'bot 2 sits at the right screen edge');
57 assert.ok(c.x > a.x, 'bot 3 is inward of bot 1, toward the field');
58 assert.ok(c.x + c.w + MiniLayout.GAP <= p.fieldX + 0.5,
59 'bot 3 does not overlap the field');
60 const bottom = p.fieldY + p.fieldH;
61 for (const m of p.positions)
62 {
63 assert.ok(Math.abs((m.y + m.h) - bottom) <= 2,
64 'mini ' + m.index + ' is bottom-aligned with the field');
65 }
66 });
67
68 it('fits 8 bots in a single row at 1400 and 1920, and wraps on a narrower wide screen (t1127)', () =>
69 {
70 const wide = plan(1400, 900, 8);
71 assert.equal(wide.mode, 'sides');
72 assert.equal(wide.positions.length, 8);
73 assert.ok(wide.positions.every(x => x.row === 0), '1400×900: all 8 in one row');
74 assert.ok(wide.colsPerSide >= 4, 'at least 4 columns per side, got ' + wide.colsPerSide);
75 const lefts = wide.positions.filter(x => x.side === 'left');
76 const rights = wide.positions.filter(x => x.side === 'right');
77 assert.equal(lefts.length, 4);
78 assert.equal(rights.length, 4);
79 // Outer to inward: x increases on the left, decreases on the right.
80 for (let i = 1; i < lefts.length; i++)
81 { assert.ok(lefts[i].x > lefts[i - 1].x, 'left fills inward'); }
82 for (let i = 1; i < rights.length; i++)
83 { assert.ok(rights[i].x < rights[i - 1].x, 'right fills inward'); }
84 assert.ok(Math.abs(lefts[0].x - MiniLayout.EDGE) <= 1, 'first left is at the outer edge');
85 assert.ok(Math.abs((rights[0].x + rights[0].w) - (1400 - MiniLayout.EDGE)) <= 1,
86 'first right is at the outer edge');
87
88 const fullhd = plan(1920, 1080, 8);
89 assert.equal(fullhd.mode, 'sides');
90 assert.ok(fullhd.positions.every(x => x.row === 0), '1920×1080: all 8 in one row');
91 assert.ok(fullhd.colsPerSide >= 4);
92
93 const narrower = plan(1280, 900, 8);
94 assert.equal(narrower.mode, 'sides');
95 const rowsUsed = Math.max(...narrower.positions.map(x => x.row));
96 assert.ok(rowsUsed >= 1, '1280×900 wraps to a second row for 8 bots');
97 const row0 = narrower.positions.filter(x => x.row === 0);
98 const row1 = narrower.positions.filter(x => x.row === 1);
99 assert.ok(row0.length >= 2 && row1.length >= 2);
100 // New row starts again at the outer edges.
101 const r1L = row1.find(x => x.side === 'left');
102 const r0L = row0.find(x => x.side === 'left' && x.fromOuter === 0);
103 assert.ok(r1L && r0L);
104 assert.equal(r1L.x, r0L.x, 'wrapped left mini is again at the outer edge');
105 assert.ok(r1L.y < r0L.y, 'wrapped row sits above the first');
106 assert.ok(r1L.y >= hudOf(900) + 3, 'wrapped row stays under the HUD');
50 107 });
51 108
52 109 it('shrinks minis so stacked rows stay under the HUD', () =>
53 110 {
54 const plan = MiniLayout.plan(1400, 800, 12, 70, 8);
55 assert.equal(plan.mode, 'sides');
56 for (const p of plan.positions)
111 const p = plan(1100, 700, 16);
112 assert.equal(p.mode, 'sides');
113 for (const m of p.positions)
57 114 {
58 assert.ok(p.y >= 70 + 3, 'mini top stays below the HUD, y=' + p.y);
59 assert.ok(p.canvasH >= 40, 'minis do not shrink below a readable size');
115 assert.ok(m.y >= hudOf(700) + 3, 'mini top stays below the HUD, y=' + m.y);
116 assert.ok(m.canvasH >= 40, 'minis do not shrink below a readable size');
60 117 }
61 118 });
62 119
63 120 it('solo (n=0) never reserves minis', () =>
64 121 {
65 const plan = MiniLayout.plan(1280, 900, 0, 70, 8);
66 assert.equal(plan.mode, 'top');
67 assert.equal(plan.miniH, 0);
68 assert.equal(plan.positions.length, 0);
122 const p = plan(1280, 900, 0);
123 assert.equal(p.mode, 'top');
124 assert.equal(p.miniH, 0);
125 assert.equal(p.positions.length, 0);
69 126 });
70 127 });
71 128
@@ -95,13 +152,11 @@ describe('Online flight visuals (t1125)', () =>
95 152 const h = 80;
96 153 const mid = Online.arcPoint(start, end, 0.5, h);
97 154 assert.equal(mid.x, 50);
98 // 4*h*t*(1-t) at t=0.5 is h, so y = 200 - 80
99 155 assert.equal(mid.y, 120);
100 156 const a = Online.arcPoint(start, end, 0, h);
101 157 const b = Online.arcPoint(start, end, 1, h);
102 158 assert.deepEqual(a, start);
103 159 assert.deepEqual(b, end);
104 // Symmetric and always above (smaller y) the chord
105 160 const q1 = Online.arcPoint(start, end, 0.25, h);
106 161 const q3 = Online.arcPoint(start, end, 0.75, h);
107 162 assert.equal(q1.y, q3.y);
@@ -5,67 +5,124 @@ const assert = require('node:assert/strict');
5const MiniLayout = require('../src/miniLayout.js');
5const MiniLayout = require('../src/miniLayout.js');
6const Online = require('../src/online.js');
6const Online = require('../src/online.js');
7
7
8describe('MiniLayout (t1125)', () =>
8function hudOf (vh)
9{
9{
10 it('uses sides on a wide desktop and top on a narrow one', () =>
10 return Math.max(56, Math.round(vh * 0.09));
11}
12function marginOf (vw, vh)
13{
14 return Math.max(6, Math.round(Math.min(vw, vh) * 0.015));
15}
16function plan (vw, vh, n)
17{
18 return MiniLayout.plan(vw, vh, n, hudOf(vh), marginOf(vw, vh));
19}
20
21describe('MiniLayout (t1125 / t1127 / t1131 / t1133)', () =>
22{
23 it('uses sides on a wide desktop and top on a narrow or portrait one', () =>
11 {
24 {
12 const wide = MiniLayout.plan(1280, 900, 2, 70, 8);
25 const wide = plan(1280, 900, 2);
13 assert.equal(wide.mode, 'sides', '1280×900 with 2 opponents is sides');
26 assert.equal(wide.mode, 'sides', '1280×900 with 2 opponents is sides');
14 assert.ok(wide.tile >= MiniLayout.MIN_TILE_FOR_SIDES, 'tiles stay large enough');
27 assert.ok(wide.tile >= MiniLayout.MIN_TILE_FOR_SIDES, 'tiles stay large enough');
15 assert.equal(wide.miniH, 0, 'sides mode does not reserve a top band');
28 assert.equal(wide.miniH, 0, 'sides mode does not reserve a top band');
16 assert.equal(wide.positions.length, 2);
29 assert.equal(wide.positions.length, 2);
17
30
18 const justUnder = MiniLayout.plan(MiniLayout.MIN_VIEWPORT_FOR_SIDES - 1, 900, 2, 70, 8);
31 const shortWide = plan(1024, 532, 3);
19 assert.equal(justUnder.mode, 'top', 'just under 960 px stays on top');
32 assert.equal(shortWide.mode, 'sides', '1024×532 (Tim\'s window) is sides, not a top row');
20 const narrow = MiniLayout.plan(720, 800, 2, 70, 8);
33 assert.equal(shortWide.positions.length, 3);
21 assert.equal(narrow.mode, 'top', '720-wide keeps the top row');
34
35 const narrow = plan(720, 800, 2);
36 assert.equal(narrow.mode, 'top', '720-tall-ish keeps the top row');
22 assert.ok(narrow.miniH > 0, 'top mode reserves height above the field');
37 assert.ok(narrow.miniH > 0, 'top mode reserves height above the field');
23 assert.equal(narrow.positions.length, 0);
38 assert.equal(narrow.positions.length, 0);
24
39
25 const mobile = MiniLayout.plan(393, 851, 1, 60, 6);
40 const mobile = plan(393, 851, 1);
26 assert.equal(mobile.mode, 'top', 'phone stays on the top layout');
41 assert.equal(mobile.mode, 'top', 'phone stays on the top layout');
27 });
42 });
28
43
29 it('alternates first left, second right, third left, and stacks upward', () =>
44 it('anchors minis to the outer edges and fills inward, bottom-aligned (t1133)', () =>
30 {
45 {
31 const plan = MiniLayout.plan(1400, 900, 6, 70, 8);
46 const p = plan(1024, 532, 3);
32 assert.equal(plan.mode, 'sides');
47 assert.equal(p.mode, 'sides');
33 assert.equal(plan.positions.length, 6);
48 assert.equal(p.positions.length, 3);
34 const sides = plan.positions.map(p => p.side);
49 assert.deepEqual(p.positions.map(x => x.side), ['left', 'right', 'left']);
35 assert.deepEqual(sides, ['left', 'right', 'left', 'right', 'left', 'right']);
50 assert.deepEqual(p.positions.map(x => x.row), [0, 0, 0], '3 bots fit in one row');
36 const rows = plan.positions.map(p => p.row);
51 assert.deepEqual(p.positions.map(x => x.fromOuter), [0, 0, 1]);
37 assert.deepEqual(rows, [0, 0, 1, 1, 2, 2]);
52
38
53 const [a, b, c] = p.positions;
39 // Lowest row aligns with (or near) the field bottom; higher rows go up.
54 assert.ok(Math.abs(a.x - MiniLayout.EDGE) <= 1, 'bot 1 sits at the left screen edge, x=' + a.x);
40 const lefts = plan.positions.filter(p => p.side === 'left');
55 assert.ok(Math.abs((b.x + b.w) - (1024 - MiniLayout.EDGE)) <= 1,
41 assert.ok(lefts[0].y + lefts[0].h <= plan.fieldY + plan.fieldH + 2,
56 'bot 2 sits at the right screen edge');
42 'first row sits at the field bottom');
57 assert.ok(c.x > a.x, 'bot 3 is inward of bot 1, toward the field');
43 assert.ok(lefts[1].y < lefts[0].y, 'second row is above the first');
58 assert.ok(c.x + c.w + MiniLayout.GAP <= p.fieldX + 0.5,
44 assert.ok(lefts[2].y < lefts[1].y, 'third row is above the second');
59 'bot 3 does not overlap the field');
45 // Same x for a column
60 const bottom = p.fieldY + p.fieldH;
46 assert.equal(lefts[0].x, lefts[1].x);
61 for (const m of p.positions)
47 assert.ok(lefts[0].x + lefts[0].w <= plan.fieldX - MiniLayout.GAP + 0.5);
62 {
48 const rights = plan.positions.filter(p => p.side === 'right');
63 assert.ok(Math.abs((m.y + m.h) - bottom) <= 2,
49 assert.ok(rights[0].x >= plan.fieldX + plan.fieldW + MiniLayout.GAP - 0.5);
64 'mini ' + m.index + ' is bottom-aligned with the field');
65 }
66 });
67
68 it('fits 8 bots in a single row at 1400 and 1920, and wraps on a narrower wide screen (t1127)', () =>
69 {
70 const wide = plan(1400, 900, 8);
71 assert.equal(wide.mode, 'sides');
72 assert.equal(wide.positions.length, 8);
73 assert.ok(wide.positions.every(x => x.row === 0), '1400×900: all 8 in one row');
74 assert.ok(wide.colsPerSide >= 4, 'at least 4 columns per side, got ' + wide.colsPerSide);
75 const lefts = wide.positions.filter(x => x.side === 'left');
76 const rights = wide.positions.filter(x => x.side === 'right');
77 assert.equal(lefts.length, 4);
78 assert.equal(rights.length, 4);
79 // Outer to inward: x increases on the left, decreases on the right.
80 for (let i = 1; i < lefts.length; i++)
81 { assert.ok(lefts[i].x > lefts[i - 1].x, 'left fills inward'); }
82 for (let i = 1; i < rights.length; i++)
83 { assert.ok(rights[i].x < rights[i - 1].x, 'right fills inward'); }
84 assert.ok(Math.abs(lefts[0].x - MiniLayout.EDGE) <= 1, 'first left is at the outer edge');
85 assert.ok(Math.abs((rights[0].x + rights[0].w) - (1400 - MiniLayout.EDGE)) <= 1,
86 'first right is at the outer edge');
87
88 const fullhd = plan(1920, 1080, 8);
89 assert.equal(fullhd.mode, 'sides');
90 assert.ok(fullhd.positions.every(x => x.row === 0), '1920×1080: all 8 in one row');
91 assert.ok(fullhd.colsPerSide >= 4);
92
93 const narrower = plan(1280, 900, 8);
94 assert.equal(narrower.mode, 'sides');
95 const rowsUsed = Math.max(...narrower.positions.map(x => x.row));
96 assert.ok(rowsUsed >= 1, '1280×900 wraps to a second row for 8 bots');
97 const row0 = narrower.positions.filter(x => x.row === 0);
98 const row1 = narrower.positions.filter(x => x.row === 1);
99 assert.ok(row0.length >= 2 && row1.length >= 2);
100 // New row starts again at the outer edges.
101 const r1L = row1.find(x => x.side === 'left');
102 const r0L = row0.find(x => x.side === 'left' && x.fromOuter === 0);
103 assert.ok(r1L && r0L);
104 assert.equal(r1L.x, r0L.x, 'wrapped left mini is again at the outer edge');
105 assert.ok(r1L.y < r0L.y, 'wrapped row sits above the first');
106 assert.ok(r1L.y >= hudOf(900) + 3, 'wrapped row stays under the HUD');
50 });
107 });
51
108
52 it('shrinks minis so stacked rows stay under the HUD', () =>
109 it('shrinks minis so stacked rows stay under the HUD', () =>
53 {
110 {
54 const plan = MiniLayout.plan(1400, 800, 12, 70, 8);
111 const p = plan(1100, 700, 16);
55 assert.equal(plan.mode, 'sides');
112 assert.equal(p.mode, 'sides');
56 for (const p of plan.positions)
113 for (const m of p.positions)
57 {
114 {
58 assert.ok(p.y >= 70 + 3, 'mini top stays below the HUD, y=' + p.y);
115 assert.ok(m.y >= hudOf(700) + 3, 'mini top stays below the HUD, y=' + m.y);
59 assert.ok(p.canvasH >= 40, 'minis do not shrink below a readable size');
116 assert.ok(m.canvasH >= 40, 'minis do not shrink below a readable size');
60 }
117 }
61 });
118 });
62
119
63 it('solo (n=0) never reserves minis', () =>
120 it('solo (n=0) never reserves minis', () =>
64 {
121 {
65 const plan = MiniLayout.plan(1280, 900, 0, 70, 8);
122 const p = plan(1280, 900, 0);
66 assert.equal(plan.mode, 'top');
123 assert.equal(p.mode, 'top');
67 assert.equal(plan.miniH, 0);
124 assert.equal(p.miniH, 0);
68 assert.equal(plan.positions.length, 0);
125 assert.equal(p.positions.length, 0);
69 });
126 });
70});
127});
71
128
@@ -95,13 +152,11 @@ describe('Online flight visuals (t1125)', () =>
95 const h = 80;
152 const h = 80;
96 const mid = Online.arcPoint(start, end, 0.5, h);
153 const mid = Online.arcPoint(start, end, 0.5, h);
97 assert.equal(mid.x, 50);
154 assert.equal(mid.x, 50);
98 // 4*h*t*(1-t) at t=0.5 is h, so y = 200 - 80
99 assert.equal(mid.y, 120);
155 assert.equal(mid.y, 120);
100 const a = Online.arcPoint(start, end, 0, h);
156 const a = Online.arcPoint(start, end, 0, h);
101 const b = Online.arcPoint(start, end, 1, h);
157 const b = Online.arcPoint(start, end, 1, h);
102 assert.deepEqual(a, start);
158 assert.deepEqual(a, start);
103 assert.deepEqual(b, end);
159 assert.deepEqual(b, end);
104 // Symmetric and always above (smaller y) the chord
105 const q1 = Online.arcPoint(start, end, 0.25, h);
160 const q1 = Online.arcPoint(start, end, 0.25, h);
106 const q3 = Online.arcPoint(start, end, 0.75, h);
161 const q3 = Online.arcPoint(start, end, 0.75, h);
107 assert.equal(q1.y, q3.y);
162 assert.equal(q1.y, q3.y);
test/minis-flights-playwright.py +91 −45
@@ -126,10 +126,7 @@ INJECT_FLIGHTS = """(age) => {
126 126 if (!el) return { x: 80, y: 80 };
127 127 const r = el.getBoundingClientRect();
128 128 if (plan && plan.mode === 'sides') {
129 const mid = field.left + field.width / 2;
130 const left = (r.left + r.width / 2) < mid;
131 if (inner) return { x: left ? r.right : r.left, y: r.top + r.height / 2 };
132 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
129 return { x: r.left + r.width / 2, y: r.top + 4 };
133 130 }
134 131 return { x: r.left + r.width / 2, y: inner ? r.bottom : r.top };
135 132 }
@@ -222,37 +219,81 @@ INJECT_FLIGHTS = """(age) => {
222 219 }"""
223 220
224 221
225 def assert_sides(info, tag, expect_rows=False):
222
223 EDGE = 16
224
225
226 def assert_sides(info, tag, expect_rows=False, expect_one_row=False, n=None):
226 227 check(info["mode"] == "sides", f"{tag}: mode is sides (got {info['mode']})")
227 228 check(info["sidesClass"], f"{tag}: #minis has .sides")
228 229 field = info["field"]
229 230 minis = info["minis"]
231 positions = info.get("positions") or []
232 vw = info.get("vw") or 0
230 233 check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})")
234 if n is not None:
235 check(len(minis) == n, f"{tag}: expected {n} minis, got {len(minis)}")
231 236 if field:
232 # t1129: room above the field for around-the-top arcs
233 gap = field["top"] - 50 # HUD is ~56–80; require a clear pad
234 check(field["top"] >= (info.get("hud") or 70) + 80
235 or field["y"] >= 70 + 80,
237 check(field["top"] >= 56 + 70 or field.get("y", 0) >= 56 + 70
238 or (info.get("vh") or 900) < 600 and field["top"] >= 56 + 80,
236 239 f"{tag}: wide layout has top padding (field.top={field['top']:.1f}, y={field.get('y')})")
237 240 if not field or not minis:
238 241 return
242
243 # Bottom-aligned with the field (row 0).
244 row0 = []
239 245 for i, m in enumerate(minis):
240 if i % 2 == 0:
241 check(m["right"] <= field["left"] + 2,
242 f"{tag}: mini {i} ({m['id']}) is on the left of the field "
243 f"(right={m['right']:.1f} field.left={field['left']:.1f})")
244 else:
245 check(m["left"] >= field["right"] - 2,
246 f"{tag}: mini {i} ({m['id']}) is on the right of the field "
247 f"(left={m['left']:.1f} field.right={field['right']:.1f})")
248 check(m["bottom"] <= field["bottom"] + 8,
249 f"{tag}: mini {i} does not hang below the field")
250 check(m["top"] >= 50,
246 pos = positions[i] if i < len(positions) else {}
247 if pos.get("row", 0) == 0:
248 row0.append(m)
249 check(abs(m["bottom"] - field["bottom"]) <= 10,
250 f"{tag}: mini {i} ({m['id']}) is bottom-aligned "
251 f"(bottom={m['bottom']:.1f} field.bottom={field['bottom']:.1f})")
252 check(m["top"] >= 40,
251 253 f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})")
252 if expect_rows and len(minis) >= 3:
253 check(minis[2]["bottom"] <= minis[0]["top"] + 4,
254 f"{tag}: third mini is stacked above the first "
255 f"(b={minis[2]['bottom']:.1f} vs top={minis[0]['top']:.1f})")
254 # Every mini sits entirely to the left or right of the field.
255 left_of = m["right"] <= field["left"] + 2
256 right_of = m["left"] >= field["right"] - 2
257 check(left_of or right_of,
258 f"{tag}: mini {i} is beside the field, not above it")
259
260 # Alternating sides, outer-edge anchored, filling inward (t1133).
261 if len(minis) >= 1:
262 check(minis[0]["left"] <= EDGE + 6,
263 f"{tag}: bot 1 is at the left outer edge (left={minis[0]['left']:.1f})")
264 if len(minis) >= 2:
265 check(minis[1]["right"] >= vw - EDGE - 6,
266 f"{tag}: bot 2 is at the right outer edge (right={minis[1]['right']:.1f} vw={vw})")
267 if len(minis) >= 3:
268 check(minis[2]["left"] > minis[0]["left"] + 20,
269 f"{tag}: bot 3 is inward of bot 1, toward the field "
270 f"({minis[0]['left']:.1f} → {minis[2]['left']:.1f})")
271 # Same row when they fit (3 bots on a wide-enough side).
272 if positions and positions[0].get("row") == 0 and positions[2].get("row") == 0:
273 check(abs(minis[2]["bottom"] - minis[0]["bottom"]) <= 6,
274 f"{tag}: bot 3 shares the bottom row with bot 1")
275 if len(minis) >= 4:
276 check(minis[3]["right"] < minis[1]["right"] - 20,
277 f"{tag}: bot 4 is inward of bot 2, toward the field")
278
279 if expect_one_row:
280 rows = [p.get("row", 0) for p in positions] if positions else []
281 check(rows and all(r == 0 for r in rows),
282 f"{tag}: all minis sit in a single row (rows={rows})")
283 if expect_rows:
284 rows = [p.get("row", 0) for p in positions] if positions else []
285 check(any(r >= 1 for r in rows),
286 f"{tag}: wraps to a second row (rows={rows})")
287 # Wrapped minis start again at the outer edges and sit above row 0.
288 lefts = [(i, minis[i], positions[i]) for i in range(len(minis))
289 if i < len(positions) and positions[i].get("side") == "left"]
290 r0 = [t for t in lefts if t[2].get("row") == 0 and t[2].get("fromOuter") == 0]
291 r1 = [t for t in lefts if t[2].get("row") == 1 and t[2].get("fromOuter") == 0]
292 if r0 and r1:
293 check(abs(r1[0][1]["left"] - r0[0][1]["left"]) <= 4,
294 f"{tag}: wrapped left mini is again at the outer edge")
295 check(r1[0][1]["bottom"] <= r0[0][1]["top"] + 8,
296 f"{tag}: wrapped row sits above the first")
256 297
257 298
258 299 def assert_top(info, tag):
@@ -281,6 +322,11 @@ def assert_flights(info, tag, expect_behind=True, expect_around=True):
281 322 f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})")
282 323 check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,
283 324 f"{tag}: player-to-enemy is grey (src={k.get('src')} color={k.get('color')})")
325 if expect_around:
326 inside = [s for s in (k.get("samples") or []) if s.get("inside")]
327 check(len(inside) == 0,
328 f"{tag}: player-to-enemy path stays outside the field "
329 f"({len(inside)} interior samples {inside[:3]})")
284 330 if "enemy-to-player" in kinds:
285 331 k = kinds["enemy-to-player"]
286 332 check(k["endScale"] > k["startScale"],
@@ -300,12 +346,6 @@ def assert_flights(info, tag, expect_behind=True, expect_around=True):
300 346 f"({len(inside)} interior samples {inside[:3]})")
301 347 check(not k.get("insideNow"),
302 348 f"{tag}: enemy-to-player mid-arc is not over the field interior")
303 if "player-to-enemy" in kinds and expect_around:
304 k = kinds["player-to-enemy"]
305 inside = [s for s in (k.get("samples") or []) if s.get("inside")]
306 check(len(inside) == 0,
307 f"{tag}: player-to-enemy path stays outside the field "
308 f"({len(inside)} interior samples {inside[:3]})")
309 349 if "enemy-to-enemy" in kinds:
310 350 k = kinds["enemy-to-enemy"]
311 351 check(abs(k["startScale"] - k["endScale"]) < 0.05,
@@ -322,12 +362,12 @@ def assert_flights(info, tag, expect_behind=True, expect_around=True):
322 362 f"{tag}: enemy-miss starts small ({k['startScale']:.2f})")
323 363 check(k["parent"] == "flights",
324 364 f"{tag}: enemy-miss is in #flights (got {k['parent']})")
325 # Misses keep the sender colour (not forced grey).
326 365 check(k.get("color") != -1,
327 366 f"{tag}: enemy-miss keeps the sender colour (color={k.get('color')})")
328 367
329 368
330 def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode):
369 def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode,
370 expect_one_row=False, expect_rows=False, n_minis=None):
331 371 context = browser.new_context(
332 372 viewport={"width": width, "height": height},
333 373 device_scale_factor=1,
@@ -338,16 +378,17 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
338 378 open_offline(page, url, round_n=round_n)
339 379 page.wait_for_timeout(300)
340 380 info = page.evaluate(LAYOUT_INFO)
381 field = info.get("field") or {}
341 382 print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')},
342 "fieldY", info.get("field") and info["field"].get("y"),
343 "field.top", info.get("field") and info["field"].get("top"))
383 "fieldY", field.get("y"), "field.top", field.get("top"),
384 "positions", info.get("positions"))
344 385 if expect_mode == "sides":
345 assert_sides(info, name, expect_rows=(round_n >= 12))
386 assert_sides(info, name, expect_rows=expect_rows, expect_one_row=expect_one_row,
387 n=n_minis)
346 388 else:
347 389 assert_top(info, name)
348 shot(page, f"t1126-{name}-layout.png")
390 shot(page, f"t1127-{name}-layout.png")
349 391
350 # Mid-arc (age 0.55 of 1.2 s) — main verification frame
351 392 flights = page.evaluate(INJECT_FLIGHTS, 0.55)
352 393 print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'hudH', 'mode') if k in flights})
353 394 for knd in flights["kinds"]:
@@ -355,13 +396,12 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
355 396 f"src={knd.get('src')} insideNow={knd.get('insideNow')} "
356 397 f"end={knd.get('end')} pos={knd.get('pos')}")
357 398 assert_flights(flights, name)
358 shot(page, f"t1126-{name}-midarc.png")
399 shot(page, f"t1127-{name}-midarc.png")
359 400
360 # Extra mid-path frames on the wide 2-bot view so the around-route is visible
361 if name == "desktop-wide":
401 if name in ("1024x532-3bots", "1920x1080-8bots", "desktop-wide"):
362 402 for age, label in ((0.25, "early"), (0.85, "late")):
363 403 page.evaluate(INJECT_FLIGHTS, age)
364 shot(page, f"t1126-{name}-midarc-{label}.png")
404 shot(page, f"t1127-{name}-midarc-{label}.png")
365 405 context.close()
366 406
367 407
@@ -376,10 +416,16 @@ def main():
376 416 args=CHROME_ARGS,
377 417 headless=True,
378 418 )
379 run_viewport(browser, url, "desktop-wide", 1280, 900, False, 2, "sides")
380 run_viewport(browser, url, "desktop-wide-many", 1400, 900, False, 25, "sides")
381 run_viewport(browser, url, "desktop-narrow", 720, 800, False, 2, "top")
382 run_viewport(browser, url, "mobile", 393, 851, True, 2, "top")
419 # Tim's short wide window, 3 bots (ronde 3)
420 run_viewport(browser, url, "1024x532-3bots", 1024, 532, False, 3, "sides",
421 expect_one_row=True, n_minis=3)
422 # 8 bots: wrap on 1280, one row on 1400 and 1920
423 run_viewport(browser, url, "1280x900-8bots", 1280, 900, False, 25, "sides",
424 expect_rows=True, n_minis=8)
425 run_viewport(browser, url, "1400x900-8bots", 1400, 900, False, 25, "sides",
426 expect_one_row=True, n_minis=8)
427 run_viewport(browser, url, "1920x1080-8bots", 1920, 1080, False, 25, "sides",
428 expect_one_row=True, n_minis=8)
383 429 browser.close()
384 430 finally:
385 431 http.terminate()
@@ -126,10 +126,7 @@ INJECT_FLIGHTS = """(age) => {
126 if (!el) return { x: 80, y: 80 };
126 if (!el) return { x: 80, y: 80 };
127 const r = el.getBoundingClientRect();
127 const r = el.getBoundingClientRect();
128 if (plan && plan.mode === 'sides') {
128 if (plan && plan.mode === 'sides') {
129 const mid = field.left + field.width / 2;
129 return { x: r.left + r.width / 2, y: r.top + 4 };
130 const left = (r.left + r.width / 2) < mid;
131 if (inner) return { x: left ? r.right : r.left, y: r.top + r.height / 2 };
132 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
133 }
130 }
134 return { x: r.left + r.width / 2, y: inner ? r.bottom : r.top };
131 return { x: r.left + r.width / 2, y: inner ? r.bottom : r.top };
135 }
132 }
@@ -222,37 +219,81 @@ INJECT_FLIGHTS = """(age) => {
222}"""
219}"""
223
220
224
221
225def assert_sides(info, tag, expect_rows=False):
222
223EDGE = 16
224
225
226def assert_sides(info, tag, expect_rows=False, expect_one_row=False, n=None):
226 check(info["mode"] == "sides", f"{tag}: mode is sides (got {info['mode']})")
227 check(info["mode"] == "sides", f"{tag}: mode is sides (got {info['mode']})")
227 check(info["sidesClass"], f"{tag}: #minis has .sides")
228 check(info["sidesClass"], f"{tag}: #minis has .sides")
228 field = info["field"]
229 field = info["field"]
229 minis = info["minis"]
230 minis = info["minis"]
231 positions = info.get("positions") or []
232 vw = info.get("vw") or 0
230 check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})")
233 check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})")
234 if n is not None:
235 check(len(minis) == n, f"{tag}: expected {n} minis, got {len(minis)}")
231 if field:
236 if field:
232 # t1129: room above the field for around-the-top arcs
237 check(field["top"] >= 56 + 70 or field.get("y", 0) >= 56 + 70
233 gap = field["top"] - 50 # HUD is ~56–80; require a clear pad
238 or (info.get("vh") or 900) < 600 and field["top"] >= 56 + 80,
234 check(field["top"] >= (info.get("hud") or 70) + 80
235 or field["y"] >= 70 + 80,
236 f"{tag}: wide layout has top padding (field.top={field['top']:.1f}, y={field.get('y')})")
239 f"{tag}: wide layout has top padding (field.top={field['top']:.1f}, y={field.get('y')})")
237 if not field or not minis:
240 if not field or not minis:
238 return
241 return
242
243 # Bottom-aligned with the field (row 0).
244 row0 = []
239 for i, m in enumerate(minis):
245 for i, m in enumerate(minis):
240 if i % 2 == 0:
246 pos = positions[i] if i < len(positions) else {}
241 check(m["right"] <= field["left"] + 2,
247 if pos.get("row", 0) == 0:
242 f"{tag}: mini {i} ({m['id']}) is on the left of the field "
248 row0.append(m)
243 f"(right={m['right']:.1f} field.left={field['left']:.1f})")
249 check(abs(m["bottom"] - field["bottom"]) <= 10,
244 else:
250 f"{tag}: mini {i} ({m['id']}) is bottom-aligned "
245 check(m["left"] >= field["right"] - 2,
251 f"(bottom={m['bottom']:.1f} field.bottom={field['bottom']:.1f})")
246 f"{tag}: mini {i} ({m['id']}) is on the right of the field "
252 check(m["top"] >= 40,
247 f"(left={m['left']:.1f} field.right={field['right']:.1f})")
248 check(m["bottom"] <= field["bottom"] + 8,
249 f"{tag}: mini {i} does not hang below the field")
250 check(m["top"] >= 50,
251 f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})")
253 f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})")
252 if expect_rows and len(minis) >= 3:
254 # Every mini sits entirely to the left or right of the field.
253 check(minis[2]["bottom"] <= minis[0]["top"] + 4,
255 left_of = m["right"] <= field["left"] + 2
254 f"{tag}: third mini is stacked above the first "
256 right_of = m["left"] >= field["right"] - 2
255 f"(b={minis[2]['bottom']:.1f} vs top={minis[0]['top']:.1f})")
257 check(left_of or right_of,
258 f"{tag}: mini {i} is beside the field, not above it")
259
260 # Alternating sides, outer-edge anchored, filling inward (t1133).
261 if len(minis) >= 1:
262 check(minis[0]["left"] <= EDGE + 6,
263 f"{tag}: bot 1 is at the left outer edge (left={minis[0]['left']:.1f})")
264 if len(minis) >= 2:
265 check(minis[1]["right"] >= vw - EDGE - 6,
266 f"{tag}: bot 2 is at the right outer edge (right={minis[1]['right']:.1f} vw={vw})")
267 if len(minis) >= 3:
268 check(minis[2]["left"] > minis[0]["left"] + 20,
269 f"{tag}: bot 3 is inward of bot 1, toward the field "
270 f"({minis[0]['left']:.1f} → {minis[2]['left']:.1f})")
271 # Same row when they fit (3 bots on a wide-enough side).
272 if positions and positions[0].get("row") == 0 and positions[2].get("row") == 0:
273 check(abs(minis[2]["bottom"] - minis[0]["bottom"]) <= 6,
274 f"{tag}: bot 3 shares the bottom row with bot 1")
275 if len(minis) >= 4:
276 check(minis[3]["right"] < minis[1]["right"] - 20,
277 f"{tag}: bot 4 is inward of bot 2, toward the field")
278
279 if expect_one_row:
280 rows = [p.get("row", 0) for p in positions] if positions else []
281 check(rows and all(r == 0 for r in rows),
282 f"{tag}: all minis sit in a single row (rows={rows})")
283 if expect_rows:
284 rows = [p.get("row", 0) for p in positions] if positions else []
285 check(any(r >= 1 for r in rows),
286 f"{tag}: wraps to a second row (rows={rows})")
287 # Wrapped minis start again at the outer edges and sit above row 0.
288 lefts = [(i, minis[i], positions[i]) for i in range(len(minis))
289 if i < len(positions) and positions[i].get("side") == "left"]
290 r0 = [t for t in lefts if t[2].get("row") == 0 and t[2].get("fromOuter") == 0]
291 r1 = [t for t in lefts if t[2].get("row") == 1 and t[2].get("fromOuter") == 0]
292 if r0 and r1:
293 check(abs(r1[0][1]["left"] - r0[0][1]["left"]) <= 4,
294 f"{tag}: wrapped left mini is again at the outer edge")
295 check(r1[0][1]["bottom"] <= r0[0][1]["top"] + 8,
296 f"{tag}: wrapped row sits above the first")
256
297
257
298
258def assert_top(info, tag):
299def assert_top(info, tag):
@@ -281,6 +322,11 @@ def assert_flights(info, tag, expect_behind=True, expect_around=True):
281 f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})")
322 f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})")
282 check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,
323 check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,
283 f"{tag}: player-to-enemy is grey (src={k.get('src')} color={k.get('color')})")
324 f"{tag}: player-to-enemy is grey (src={k.get('src')} color={k.get('color')})")
325 if expect_around:
326 inside = [s for s in (k.get("samples") or []) if s.get("inside")]
327 check(len(inside) == 0,
328 f"{tag}: player-to-enemy path stays outside the field "
329 f"({len(inside)} interior samples {inside[:3]})")
284 if "enemy-to-player" in kinds:
330 if "enemy-to-player" in kinds:
285 k = kinds["enemy-to-player"]
331 k = kinds["enemy-to-player"]
286 check(k["endScale"] > k["startScale"],
332 check(k["endScale"] > k["startScale"],
@@ -300,12 +346,6 @@ def assert_flights(info, tag, expect_behind=True, expect_around=True):
300 f"({len(inside)} interior samples {inside[:3]})")
346 f"({len(inside)} interior samples {inside[:3]})")
301 check(not k.get("insideNow"),
347 check(not k.get("insideNow"),
302 f"{tag}: enemy-to-player mid-arc is not over the field interior")
348 f"{tag}: enemy-to-player mid-arc is not over the field interior")
303 if "player-to-enemy" in kinds and expect_around:
304 k = kinds["player-to-enemy"]
305 inside = [s for s in (k.get("samples") or []) if s.get("inside")]
306 check(len(inside) == 0,
307 f"{tag}: player-to-enemy path stays outside the field "
308 f"({len(inside)} interior samples {inside[:3]})")
309 if "enemy-to-enemy" in kinds:
349 if "enemy-to-enemy" in kinds:
310 k = kinds["enemy-to-enemy"]
350 k = kinds["enemy-to-enemy"]
311 check(abs(k["startScale"] - k["endScale"]) < 0.05,
351 check(abs(k["startScale"] - k["endScale"]) < 0.05,
@@ -322,12 +362,12 @@ def assert_flights(info, tag, expect_behind=True, expect_around=True):
322 f"{tag}: enemy-miss starts small ({k['startScale']:.2f})")
362 f"{tag}: enemy-miss starts small ({k['startScale']:.2f})")
323 check(k["parent"] == "flights",
363 check(k["parent"] == "flights",
324 f"{tag}: enemy-miss is in #flights (got {k['parent']})")
364 f"{tag}: enemy-miss is in #flights (got {k['parent']})")
325 # Misses keep the sender colour (not forced grey).
326 check(k.get("color") != -1,
365 check(k.get("color") != -1,
327 f"{tag}: enemy-miss keeps the sender colour (color={k.get('color')})")
366 f"{tag}: enemy-miss keeps the sender colour (color={k.get('color')})")
328
367
329
368
330def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode):
369def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode,
370 expect_one_row=False, expect_rows=False, n_minis=None):
331 context = browser.new_context(
371 context = browser.new_context(
332 viewport={"width": width, "height": height},
372 viewport={"width": width, "height": height},
333 device_scale_factor=1,
373 device_scale_factor=1,
@@ -338,16 +378,17 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
338 open_offline(page, url, round_n=round_n)
378 open_offline(page, url, round_n=round_n)
339 page.wait_for_timeout(300)
379 page.wait_for_timeout(300)
340 info = page.evaluate(LAYOUT_INFO)
380 info = page.evaluate(LAYOUT_INFO)
381 field = info.get("field") or {}
341 print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')},
382 print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')},
342 "fieldY", info.get("field") and info["field"].get("y"),
383 "fieldY", field.get("y"), "field.top", field.get("top"),
343 "field.top", info.get("field") and info["field"].get("top"))
384 "positions", info.get("positions"))
344 if expect_mode == "sides":
385 if expect_mode == "sides":
345 assert_sides(info, name, expect_rows=(round_n >= 12))
386 assert_sides(info, name, expect_rows=expect_rows, expect_one_row=expect_one_row,
387 n=n_minis)
346 else:
388 else:
347 assert_top(info, name)
389 assert_top(info, name)
348 shot(page, f"t1126-{name}-layout.png")
390 shot(page, f"t1127-{name}-layout.png")
349
391
350 # Mid-arc (age 0.55 of 1.2 s) — main verification frame
351 flights = page.evaluate(INJECT_FLIGHTS, 0.55)
392 flights = page.evaluate(INJECT_FLIGHTS, 0.55)
352 print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'hudH', 'mode') if k in flights})
393 print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'hudH', 'mode') if k in flights})
353 for knd in flights["kinds"]:
394 for knd in flights["kinds"]:
@@ -355,13 +396,12 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
355 f"src={knd.get('src')} insideNow={knd.get('insideNow')} "
396 f"src={knd.get('src')} insideNow={knd.get('insideNow')} "
356 f"end={knd.get('end')} pos={knd.get('pos')}")
397 f"end={knd.get('end')} pos={knd.get('pos')}")
357 assert_flights(flights, name)
398 assert_flights(flights, name)
358 shot(page, f"t1126-{name}-midarc.png")
399 shot(page, f"t1127-{name}-midarc.png")
359
400
360 # Extra mid-path frames on the wide 2-bot view so the around-route is visible
401 if name in ("1024x532-3bots", "1920x1080-8bots", "desktop-wide"):
361 if name == "desktop-wide":
362 for age, label in ((0.25, "early"), (0.85, "late")):
402 for age, label in ((0.25, "early"), (0.85, "late")):
363 page.evaluate(INJECT_FLIGHTS, age)
403 page.evaluate(INJECT_FLIGHTS, age)
364 shot(page, f"t1126-{name}-midarc-{label}.png")
404 shot(page, f"t1127-{name}-midarc-{label}.png")
365 context.close()
405 context.close()
366
406
367
407
@@ -376,10 +416,16 @@ def main():
376 args=CHROME_ARGS,
416 args=CHROME_ARGS,
377 headless=True,
417 headless=True,
378 )
418 )
379 run_viewport(browser, url, "desktop-wide", 1280, 900, False, 2, "sides")
419 # Tim's short wide window, 3 bots (ronde 3)
380 run_viewport(browser, url, "desktop-wide-many", 1400, 900, False, 25, "sides")
420 run_viewport(browser, url, "1024x532-3bots", 1024, 532, False, 3, "sides",
381 run_viewport(browser, url, "desktop-narrow", 720, 800, False, 2, "top")
421 expect_one_row=True, n_minis=3)
382 run_viewport(browser, url, "mobile", 393, 851, True, 2, "top")
422 # 8 bots: wrap on 1280, one row on 1400 and 1920
423 run_viewport(browser, url, "1280x900-8bots", 1280, 900, False, 25, "sides",
424 expect_rows=True, n_minis=8)
425 run_viewport(browser, url, "1400x900-8bots", 1400, 900, False, 25, "sides",
426 expect_one_row=True, n_minis=8)
427 run_viewport(browser, url, "1920x1080-8bots", 1920, 1080, False, 25, "sides",
428 expect_one_row=True, n_minis=8)
383 browser.close()
429 browser.close()
384 finally:
430 finally:
385 http.terminate()
431 http.terminate()