BlueGit

projects-timfalken-com meteors

chore: rebuild game.js with side minis and flight arcs (t1125)

timfa Grok Bot · pushed by timfa

Authored 2026-11-13 · 4 days ago

Hash
b924b78ab564455cde6638a564e28fc5f734f3ab
Parent
76566b32
1 file changed +604 −62
build/game.js +604 −62
@@ -3749,6 +3749,187 @@ else if (typeof globalThis !== 'undefined')
3749 3749 * /workspace/meteors/src/gameCore.js
3750 3750 */
3751 3751
3752 /*
3753 * Start File:
3754 * /workspace/meteors/src/miniLayout.js
3755 */
3756 'use strict';
3757
3758 /**
3759 * Opponent miniature layout for online and Offline Strijd (t1125).
3760 * Wide screens: alternating left/right of the player's field, extra
3761 * rows stacked upward. Narrow screens: a row (wrapping) above the field.
3762 */
3763
3764 var MiniLayout = (function ()
3765 {
3766
3767 var GAP = 12;
3768 var VGAP = 8;
3769 var EDGE = 16;
3770 var MIN_TILE_FOR_SIDES = 18;
3771 var MIN_VIEWPORT_FOR_SIDES = 960;
3772 var LABEL_H = 32;
3773
3774 function canvasSize (n, mode, availH)
3775 {
3776 n = n || 0;
3777 if (mode === 'sides' && availH && n > 0)
3778 {
3779 var rows = Math.ceil(n / 2);
3780 var maxOuter = Math.floor((availH - (rows - 1) * VGAP) / Math.max(1, rows));
3781 var ch = Math.max(40, Math.min(104, maxOuter - LABEL_H));
3782 var cw = Math.max(32, Math.round(ch * 10 / 13));
3783 return {
3784 w: cw,
3785 h: ch,
3786 outerW: Math.max(cw + 8, 64),
3787 outerH: ch + LABEL_H
3788 };
3789 }
3790 if (n >= 10)
3791 { return { w: 40, h: 52, outerW: 56, outerH: 52 + LABEL_H }; }
3792 if (n >= 6)
3793 { return { w: 56, h: 73, outerW: 68, outerH: 73 + LABEL_H }; }
3794 return { w: 80, h: 104, outerW: 90, outerH: 104 + LABEL_H };
3795 }
3796
3797 function sidePositions (n, fieldX, fieldY, fieldW, fieldH, mini, hudH)
3798 {
3799 var positions = [];
3800 if (n <= 0)
3801 { return positions; }
3802 var rows = Math.ceil(n / 2);
3803 var stackH = rows * mini.outerH + Math.max(0, rows - 1) * VGAP;
3804 var bottom = fieldY + fieldH;
3805 var top = bottom - stackH;
3806 if (top < hudH + 4)
3807 {
3808 top = hudH + 4;
3809 bottom = top + stackH;
3810 }
3811 for (var i = 0; i < n; i++)
3812 {
3813 var col = i % 2;
3814 var row = Math.floor(i / 2);
3815 var x = col === 0
3816 ? fieldX - GAP - mini.outerW
3817 : fieldX + fieldW + GAP;
3818 var y = bottom - (row + 1) * mini.outerH - row * VGAP;
3819 positions.push({
3820 index: i,
3821 side: col === 0 ? 'left' : 'right',
3822 row: row,
3823 x: x,
3824 y: y,
3825 w: mini.outerW,
3826 h: mini.outerH,
3827 canvasW: mini.w,
3828 canvasH: mini.h
3829 });
3830 }
3831 return positions;
3832 }
3833
3834 /**
3835 * Compute the field and mini plan for a viewport.
3836 * `n` is the number of opponents (0 = solo, no minis).
3837 */
3838 function plan (vw, vh, n, hudH, margin)
3839 {
3840 vw = vw || 320;
3841 vh = vh || 480;
3842 n = n || 0;
3843 hudH = hudH == null ? 56 : hudH;
3844 margin = margin == null ? Math.max(6, Math.round(Math.min(vw, vh) * 0.015)) : margin;
3845
3846 function finish (mode, tile, fieldX, fieldY, miniH, mini, positions)
3847 {
3848 return {
3849 mode: mode,
3850 tile: tile,
3851 fieldW: tile * 10,
3852 fieldH: tile * 13,
3853 fieldX: fieldX,
3854 fieldY: fieldY,
3855 miniH: miniH,
3856 mini: mini,
3857 positions: positions || [],
3858 n: n
3859 };
3860 }
3861
3862 if (n > 0)
3863 {
3864 var availHSide = Math.max(80, vh - hudH - margin);
3865 var probe = canvasSize(n, 'sides', availHSide);
3866 var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));
3867 var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHSide / 13)));
3868 var fieldWSide = tileSide * 10;
3869 var fieldHSide = tileSide * 13;
3870 var leftover = (vw - fieldWSide) / 2;
3871 var need = probe.outerW + GAP + EDGE;
3872 if (vw >= MIN_VIEWPORT_FOR_SIDES && leftover >= need
3873 && tileSide >= MIN_TILE_FOR_SIDES)
3874 {
3875 var fieldX = Math.floor((vw - fieldWSide) / 2);
3876 var fieldY = hudH + Math.floor((availHSide - fieldHSide) / 2);
3877 if (fieldY < hudH)
3878 { fieldY = hudH; }
3879 return finish('sides', tileSide, fieldX, fieldY, 0, probe,
3880 sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));
3881 }
3882 }
3883
3884 var miniTop = canvasSize(n, 'top', 0);
3885 var miniH = 0;
3886 if (n > 0)
3887 {
3888 var share = n > 6 ? 0.26 : 0.20;
3889 miniH = Math.min(n > 6 ? 180 : 150, Math.max(86, Math.round(vh * share)));
3890 }
3891 var availW = Math.max(80, vw - margin * 2);
3892 var availH = Math.max(80, vh - hudH - miniH - margin);
3893 var tile = Math.max(14, Math.floor(Math.min(availW / 10, availH / 13)));
3894 var fieldW = tile * 10;
3895 var fieldH = tile * 13;
3896 var fieldX = Math.floor((vw - fieldW) / 2);
3897 var topBand = hudH + miniH;
3898 var fieldY = topBand + Math.floor((vh - topBand - fieldH - margin / 2) / 2);
3899 if (fieldY < topBand)
3900 { fieldY = topBand; }
3901 return finish('top', tile, fieldX, fieldY, miniH, miniTop, []);
3902 }
3903
3904 var api = {
3905 GAP: GAP,
3906 VGAP: VGAP,
3907 EDGE: EDGE,
3908 MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,
3909 MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,
3910 LABEL_H: LABEL_H,
3911 canvasSize: canvasSize,
3912 sidePositions: sidePositions,
3913 plan: plan
3914 };
3915
3916 if (typeof module !== 'undefined' && module.exports)
3917 { module.exports = api; }
3918 else if (typeof globalThis !== 'undefined')
3919 { globalThis.MiniLayout = api; }
3920
3921 return api;
3922
3923 })();
3924
3925 if (typeof module !== 'undefined' && module.exports && typeof MiniLayout !== 'undefined')
3926 { module.exports = MiniLayout; }
3927
3928 /*
3929 * End File:
3930 * /workspace/meteors/src/miniLayout.js
3931 */
3932
3752 3933 /*
3753 3934 * Start File:
3754 3935 * /workspace/meteors/src/online.js
@@ -3958,8 +4139,15 @@ Online._handleTransitions = function (prevStatus, data)
3958 4139 { this.onGameStart(lobby); }
3959 4140 if (data && data.incoming && data.incoming.length && this.onIncoming)
3960 4141 { this.onIncoming(data.incoming); }
4142 // Own outgoing results (immediate) and lobby-wide recent flights
4143 // (so every client can draw opponent and enemy-to-enemy arcs, t1125).
4144 var flights = [];
3961 4145 if (data && data.shot_results && data.shot_results.length)
3962 { this.spawnFlights(data.shot_results, this._lastQueuedMeta); }
4146 { flights = flights.concat(data.shot_results); }
4147 if (data && data.shot_flights && data.shot_flights.length)
4148 { flights = flights.concat(data.shot_flights); }
4149 if (flights.length)
4150 { this.spawnFlights(flights, this._flightLocals); }
3963 4151 if (status === 'finished' && prevStatus !== 'finished' && this.onFinished)
3964 4152 { this.onFinished(lobby); }
3965 4153 if (status === 'waiting' && prevStatus === 'finished' && this.onLobbyReturn)
@@ -4050,6 +4238,20 @@ Online.renderMinis = function (container)
4050 4238 + '<div class="mini-meta"></div>';
4051 4239 container.appendChild(el);
4052 4240 }
4241 var mz = (typeof app !== 'undefined' && app.miniLayout && app.miniLayout.mini)
4242 ? app.miniLayout.mini
4243 : { w: 80, h: 104 };
4244 var canvas = el.querySelector('canvas');
4245 if (canvas && (canvas.width !== mz.w || canvas.height !== mz.h))
4246 {
4247 canvas.width = mz.w;
4248 canvas.height = mz.h;
4249 }
4250 if (canvas)
4251 {
4252 canvas.style.width = mz.w + 'px';
4253 canvas.style.height = mz.h + 'px';
4254 }
4053 4255 el.classList.toggle('eliminated', !!p.eliminated);
4054 4256 el.querySelector('.mini-name').textContent = p.name + (p.is_host ? ' (host)' : '');
4055 4257 el.querySelector('.mini-meta').textContent = p.eliminated
@@ -4062,6 +4264,8 @@ Online.renderMinis = function (container)
4062 4264 if (!seen[id])
4063 4265 { existing[id].remove(); }
4064 4266 }
4267 if (typeof applyMinisLayout === 'function')
4268 { applyMinisLayout(); }
4065 4269 };
4066 4270
4067 4271 var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];
@@ -4156,40 +4360,221 @@ function colorSpriteUrl (color, planetId)
4156 4360 * startX, startY} in viewport pixels, filled by the view just after
4157 4361 * consumeOutgoingShots.
4158 4362 */
4363 Online.playerId = function ()
4364 {
4365 if (typeof app !== 'undefined' && app.offline)
4366 { return 'player'; }
4367 if (this.lobby && this.lobby.players)
4368 {
4369 for (var i = 0; i < this.lobby.players.length; i++)
4370 {
4371 if (this.lobby.players[i].is_me)
4372 { return this.lobby.players[i].id; }
4373 }
4374 }
4375 return 'player';
4376 };
4377
4378 /**
4379 * Classify a shot for visual treatment (t1125).
4380 * player-to-enemy, enemy-to-player, enemy-to-enemy,
4381 * player-miss, enemy-miss.
4382 */
4383 Online.flightKind = function (fromId, targetId, miss)
4384 {
4385 var me = this.playerId();
4386 var fromMe = !fromId || fromId === me || fromId === 'player';
4387 if (miss)
4388 { return fromMe ? 'player-miss' : 'enemy-miss'; }
4389 if (fromMe)
4390 { return 'player-to-enemy'; }
4391 if (targetId === me || targetId === 'player')
4392 { return 'enemy-to-player'; }
4393 return 'enemy-to-enemy';
4394 };
4395
4396 /**
4397 * Parabolic arc: linear in x, a rise of `height` pixels above the
4398 * chord at mid-flight (screen y grows downward, so we subtract).
4399 */
4400 Online.arcPoint = function (start, end, u, height)
4401 {
4402 var t = u < 0 ? 0 : (u > 1 ? 1 : u);
4403 var x = start.x + (end.x - start.x) * t;
4404 var y = start.y + (end.y - start.y) * t - 4 * height * t * (1 - t);
4405 return { x: x, y: y };
4406 };
4407
4408 Online.arcHeight = function (start, end)
4409 {
4410 var dx = end.x - start.x;
4411 var dy = end.y - start.y;
4412 var dist = Math.sqrt(dx * dx + dy * dy);
4413 return Math.max(48, Math.min(220, dist * 0.28));
4414 };
4415
4416 Online.easeInOutCubic = function (t)
4417 {
4418 if (t < 0.5)
4419 { return 4 * t * t * t; }
4420 var u = -2 * t + 2;
4421 return 1 - (u * u * u) / 2;
4422 };
4423
4424 Online._miniCellSize = function (playerId)
4425 {
4426 var el = this.miniElement(playerId);
4427 var canvas = el && el.querySelector('canvas');
4428 if (canvas)
4429 {
4430 var r = canvas.getBoundingClientRect();
4431 return Math.max(6, r.width / 10);
4432 }
4433 return 10;
4434 };
4435
4436 Online._fullTileSize = function ()
4437 {
4438 if (typeof app !== 'undefined' && app.tile)
4439 { return app.tile; }
4440 return 40;
4441 };
4442
4443 Online._miniAnchor = function (playerId, dir)
4444 {
4445 var el = this.miniElement(playerId);
4446 var canvas = el && (el.querySelector ? el.querySelector('canvas') : null);
4447 var box = canvas || el;
4448 if (!box)
4449 { return { x: window.innerWidth / 2, y: 48 }; }
4450 var r = box.getBoundingClientRect();
4451 if (dir === 'out')
4452 { return { x: r.left + r.width / 2, y: r.top + 4 }; }
4453 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
4454 };
4455
4456 Online._fieldTop = function (col)
4457 {
4458 return this._flightStart(col);
4459 };
4460
4461 /**
4462 * Animate shot results. `locals` is a map of client_id → {col, y, color,
4463 * startX, startY, from_id} in viewport pixels.
4464 *
4465 * Visual-only (t1125): a parabolic arc whose scale goes from mini-cell
4466 * to full tile (or the reverse). Enemy-to-enemy arcs stay small and
4467 * are drawn behind the player's field. Delivery timing is unchanged;
4468 * a late-seen flight starts mid-arc via `age`.
4469 */
4159 4470 Online.spawnFlights = function (results, locals)
4160 4471 {
4161 4472 locals = locals || this._flightLocals || {};
4162 var layer = document.getElementById('flights');
4163 if (!layer)
4473 var front = document.getElementById('flights');
4474 var back = document.getElementById('flights-back') || front;
4475 if (!front)
4164 4476 { return; }
4477 if (!this._flightSeen)
4478 { this._flightSeen = Object.create(null); }
4479 var now = performance.now();
4480 var full = this._fullTileSize();
4165 4481 for (var i = 0; i < results.length; i++)
4166 4482 {
4167 4483 var r = results[i];
4168 var meta = locals[r.client_id] || {};
4169 var start = this._flightStart(meta.col);
4170 var end;
4484 var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));
4485 if (this._flightSeen[sid])
4486 { continue; }
4487 this._flightSeen[sid] = now;
4488
4489 var meta = locals[r.client_id] || locals[sid] || {};
4490 var fromId = r.from_id || r.from_user || meta.from_id || null;
4491 var targetId = r.target_id != null ? r.target_id : r.to_user;
4171 4492 var miss = !!r.miss;
4493 var kind = this.flightKind(fromId, targetId, miss);
4494 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
4495 if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)
4496 { continue; }
4497
4498 var start;
4499 if (meta.startX != null && isFinite(meta.startX))
4500 { start = { x: meta.startX, y: meta.startY }; }
4501 else if (kind === 'player-to-enemy' || kind === 'player-miss')
4502 { start = this._flightStart(meta.col != null ? meta.col : r.col); }
4503 else
4504 { start = this._miniAnchor(fromId, 'out'); }
4505
4506 var end;
4172 4507 if (miss)
4173 { end = this._missEnd(start); }
4508 { end = this._missEnd(start, kind === 'enemy-miss'); }
4509 else if (kind === 'enemy-to-player')
4510 { end = this._fieldTop(null); }
4174 4511 else
4175 { end = this._targetEnd(r.target_id, start); }
4512 { end = this._targetEnd(targetId, start); }
4513
4514 var startScale;
4515 var endScale;
4516 var mini = this._miniCellSize(fromId || targetId) / full;
4517 if (mini < 0.12)
4518 { mini = 0.2; }
4519 if (kind === 'player-to-enemy')
4520 {
4521 startScale = 1;
4522 endScale = mini;
4523 }
4524 else if (kind === 'enemy-to-player')
4525 {
4526 startScale = mini;
4527 endScale = 1;
4528 }
4529 else if (kind === 'enemy-to-enemy')
4530 {
4531 startScale = mini;
4532 endScale = mini;
4533 }
4534 else if (kind === 'enemy-miss')
4535 {
4536 startScale = mini;
4537 endScale = 0;
4538 }
4539 else
4540 {
4541 startScale = 1;
4542 endScale = 0;
4543 }
4544
4545 var layer = (kind === 'enemy-to-enemy' && back) ? back : front;
4176 4546 var el = document.createElement('img');
4177 4547 el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);
4178 4548 el.alt = '';
4179 el.className = 'flight';
4549 el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');
4550 el.style.width = full + 'px';
4551 el.style.height = full + 'px';
4180 4552 layer.appendChild(el);
4181 var spin = (Math.random() * 2 - 1) * 720;
4182 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
4553
4554 var t0 = now;
4555 if (r.age != null && isFinite(r.age) && r.age > 0)
4556 {
4557 var u0 = Math.min(0.95, (r.age * 1000) / duration);
4558 t0 = now - u0 * duration;
4559 }
4560 var height = miss
4561 ? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
4562 : this.arcHeight(start, end);
4183 4563 this._flights.push({
4184 4564 el: el,
4185 4565 start: start,
4186 4566 end: end,
4187 ctrl: miss ? this._missCtrl(start, end) : this._hitCtrl(start, end),
4188 t0: performance.now(),
4567 ctrl: miss ? this._missCtrl(start, end) : null,
4568 height: height,
4569 t0: t0,
4189 4570 duration: duration,
4190 spin: spin,
4571 spin: (Math.random() * 2 - 1) * 720,
4191 4572 miss: miss,
4192 angle: Math.random() * 360
4573 kind: kind,
4574 startScale: startScale,
4575 endScale: endScale,
4576 angle: Math.random() * 360,
4577 id: sid
4193 4578 });
4194 4579 }
4195 4580 this._flightLocals = {};
@@ -4204,13 +4589,13 @@ Online.rememberFlightLocal = function (shot, startX, startY)
4204 4589 y: shot.y,
4205 4590 color: shot.color,
4206 4591 startX: startX,
4207 startY: startY
4592 startY: startY,
4593 from_id: shot.from_id
4208 4594 };
4209 4595 };
4210 4596
4211 4597 Online._flightStart = function (col)
4212 4598 {
4213 var field = document.querySelector('canvas');
4214 4599 var appRef = typeof app !== 'undefined' ? app : null;
4215 4600 if (appRef && appRef.scene && appRef.scene.canvas)
4216 4601 {
@@ -4222,6 +4607,7 @@ Online._flightStart = function (col)
4222 4607 y: rect.top + 4
4223 4608 };
4224 4609 }
4610 var field = document.querySelector('canvas');
4225 4611 if (field)
4226 4612 {
4227 4613 var rect = field.getBoundingClientRect();
@@ -4235,19 +4621,25 @@ Online._targetEnd = function (targetId, start)
4235 4621 var el = targetId && this.miniElement(targetId);
4236 4622 if (el)
4237 4623 {
4238 var r = el.getBoundingClientRect();
4624 var canvas = el.querySelector('canvas') || el;
4625 var r = canvas.getBoundingClientRect();
4239 4626 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
4240 4627 }
4241 4628 return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };
4242 4629 };
4243 4630
4244 Online._missEnd = function (start)
4631 Online._missEnd = function (start, fromMini)
4245 4632 {
4246 var dx = (Math.random() * 2 - 1) * window.innerWidth * 0.35;
4247 return {
4248 x: start.x + dx,
4249 y: start.y - (120 + Math.random() * 220)
4250 };
4633 var w = window.innerWidth || 800;
4634 var outward;
4635 if (start.x < w * 0.4)
4636 { outward = -(80 + Math.random() * w * 0.25); }
4637 else if (start.x > w * 0.6)
4638 { outward = (80 + Math.random() * w * 0.25); }
4639 else
4640 { outward = (Math.random() * 2 - 1) * w * 0.35; }
4641 var lift = fromMini ? (80 + Math.random() * 160) : (120 + Math.random() * 220);
4642 return { x: start.x + outward, y: start.y - lift };
4251 4643 };
4252 4644
4253 4645 Online._missCtrl = function (start, end)
@@ -4273,26 +4665,53 @@ Online.tickFlights = function (now)
4273 4665 for (var i = 0; i < this._flights.length; i++)
4274 4666 {
4275 4667 var f = this._flights[i];
4276 var u = (now - f.t0) / f.duration;
4277 if (u >= 1)
4668 var raw = (now - f.t0) / f.duration;
4669 if (raw >= 1)
4278 4670 {
4279 4671 if (f.el && f.el.parentNode)
4280 4672 { f.el.parentNode.removeChild(f.el); }
4281 4673 continue;
4282 4674 }
4283 // Quadratic bezier, ease-in so they feel like they recede.
4284 var e = u * u;
4285 var mt = 1 - e;
4286 var x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
4287 var y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
4288 var scale = f.miss ? (1 - e) : (1 - 0.85 * e);
4289 var angle = f.angle + f.spin * u;
4675 if (raw < 0)
4676 { raw = 0; }
4677 var u = this.easeInOutCubic(raw);
4678 var x, y;
4679 if (f.miss && f.ctrl)
4680 {
4681 var e = raw * raw;
4682 var mt = 1 - e;
4683 x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
4684 y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
4685 }
4686 else
4687 {
4688 var pt = this.arcPoint(f.start, f.end, u, f.height || 80);
4689 x = pt.x;
4690 y = pt.y;
4691 }
4692 var scale = f.startScale + (f.endScale - f.startScale) * u;
4693 if (f.miss)
4694 {
4695 var fadeU = raw * raw;
4696 scale = f.startScale * (1 - fadeU);
4697 }
4698 var angle = f.angle + f.spin * raw;
4290 4699 f.el.style.transform = 'translate(' + x + 'px,' + y + 'px) translate(-50%,-50%) rotate('
4291 4700 + angle + 'deg) scale(' + scale + ')';
4292 f.el.style.opacity = f.miss ? String(1 - e) : '1';
4701 f.el.style.opacity = f.miss ? String(Math.max(0, 1 - raw * raw)) : '1';
4293 4702 leftover.push(f);
4294 4703 }
4295 4704 this._flights = leftover;
4705 if (this._flightSeen)
4706 {
4707 var cutoff = now - 8000;
4708 var ids = Object.keys(this._flightSeen);
4709 for (var k = 0; k < ids.length; k++)
4710 {
4711 if (this._flightSeen[ids[k]] < cutoff)
4712 { delete this._flightSeen[ids[k]]; }
4713 }
4714 }
4296 4715 };
4297 4716
4298 4717 Online.clearFlights = function ()
@@ -4305,6 +4724,7 @@ Online.clearFlights = function ()
4305 4724 }
4306 4725 this._flights = [];
4307 4726 this._flightLocals = {};
4727 this._flightSeen = Object.create(null);
4308 4728 };
4309 4729
4310 4730 if (typeof globalThis !== 'undefined')
@@ -5215,13 +5635,122 @@ function placeTile (obj, col, y)
5215 5635 obj.transform.size = { x: t, y: t };
5216 5636 }
5217 5637
5638 function opponentCount ()
5639 {
5640 if (app.offline && app.battle && app.battle.bots)
5641 { return app.battle.bots.length; }
5642 if (app.online && typeof Online !== 'undefined' && Online.opponents)
5643 { return Online.opponents().length; }
5644 return 0;
5645 }
5646
5647 function currentMiniSize ()
5648 {
5649 if (app.miniLayout && app.miniLayout.mini)
5650 { return { w: app.miniLayout.mini.w, h: app.miniLayout.mini.h }; }
5651 var n = opponentCount();
5652 var mode = (app.miniLayout && app.miniLayout.mode) || 'top';
5653 if (typeof MiniLayout !== 'undefined' && MiniLayout.canvasSize)
5654 { return MiniLayout.canvasSize(n, mode, 0); }
5655 if (n >= 10)
5656 { return { w: 40, h: 52 }; }
5657 if (n >= 6)
5658 { return { w: 56, h: 73 }; }
5659 return { w: 80, h: 104 };
5660 }
5661
5662 function applyMinisContainer (plan)
5663 {
5664 var minis = document.getElementById('minis');
5665 if (!minis)
5666 { return; }
5667 var n = plan ? plan.n : 0;
5668 minis.classList.toggle('crowded', n > 5);
5669 if (!plan || n === 0 || plan.mode !== 'sides')
5670 {
5671 minis.classList.remove('sides');
5672 minis.style.top = (app.hudH || 56) + 'px';
5673 minis.style.maxHeight = (plan && plan.miniH ? plan.miniH : 0) + 'px';
5674 minis.style.bottom = '';
5675 minis.style.left = '';
5676 minis.style.right = '';
5677 var kids = minis.querySelectorAll('.mini');
5678 for (var i = 0; i < kids.length; i++)
5679 {
5680 kids[i].style.left = '';
5681 kids[i].style.top = '';
5682 kids[i].style.width = '';
5683 kids[i].style.position = '';
5684 }
5685 return;
5686 }
5687 minis.classList.add('sides');
5688 minis.style.top = '0';
5689 minis.style.bottom = '0';
5690 minis.style.left = '0';
5691 minis.style.right = '0';
5692 minis.style.maxHeight = 'none';
5693 }
5694
5695 function applyMinisLayout ()
5696 {
5697 var plan = app.miniLayout;
5698 var minis = document.getElementById('minis');
5699 if (!minis)
5700 { return; }
5701 applyMinisContainer(plan);
5702 if (!plan || plan.mode !== 'sides')
5703 { return; }
5704 var positions = plan.positions || [];
5705 var kids = minis.querySelectorAll('.mini');
5706 for (var i = 0; i < positions.length && i < kids.length; i++)
5707 {
5708 var p = positions[i];
5709 var el = kids[i];
5710 el.style.position = 'absolute';
5711 el.style.left = p.x + 'px';
5712 el.style.top = p.y + 'px';
5713 el.style.width = p.w + 'px';
5714 var canvas = el.querySelector('canvas');
5715 if (canvas)
5716 {
5717 canvas.style.width = p.canvasW + 'px';
5718 canvas.style.height = p.canvasH + 'px';
5719 }
5720 }
5721 }
5722
5723 function applyFlightsBackClip ()
5724 {
5725 var back = document.getElementById('flights-back');
5726 if (!back)
5727 { return; }
5728 var x = app.fieldX || 0;
5729 var y = app.fieldY || 0;
5730 var w = app.fieldW || 0;
5731 var h = app.fieldH || 0;
5732 if (!w || !h)
5733 {
5734 back.style.clipPath = '';
5735 return;
5736 }
5737 // Even-odd polygon: full viewport with a hole over the player's field,
5738 // so enemy-to-enemy arcs travel behind the field (t1125).
5739 back.style.clipPath = 'polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0, '
5740 + x + 'px ' + y + 'px, ' + (x + w) + 'px ' + y + 'px, '
5741 + (x + w) + 'px ' + (y + h) + 'px, ' + x + 'px ' + (y + h) + 'px, '
5742 + x + 'px ' + y + 'px)';
5743 }
5744
5218 5745 function layoutIfNeeded ()
5219 5746 {
5220 5747 if (app.core && app.core.drag)
5221 5748 { return; }
5222 5749 var vw = window.innerWidth || 320;
5223 5750 var vh = window.innerHeight || 480;
5224 if (app._layoutVw === vw && app._layoutVh === vh && app.scene && app.tile)
5751 var n = (app.online || app.offline) ? opponentCount() : 0;
5752 if (app._layoutVw === vw && app._layoutVh === vh && app._layoutN === n
5753 && app.scene && app.tile)
5225 5754 { return; }
5226 5755 layout();
5227 5756 }
@@ -5232,8 +5761,10 @@ function layout ()
5232 5761 { return; }
5233 5762 var vw = window.innerWidth || 320;
5234 5763 var vh = window.innerHeight || 480;
5764 var n = (app.online || app.offline) ? opponentCount() : 0;
5235 5765 app._layoutVw = vw;
5236 5766 app._layoutVh = vh;
5767 app._layoutN = n;
5237 5768 var safeTop = 0;
5238 5769 try
5239 5770 {
@@ -5242,30 +5773,34 @@ function layout ()
5242 5773 }
5243 5774 catch (e) { /* ignore */ }
5244 5775 app.hudH = Math.max(56, Math.round(vh * 0.09) + safeTop);
5245 app.miniH = 0;
5246 if (app.online || app.offline)
5247 {
5248 var nBots = (app.battle && app.battle.bots) ? app.battle.bots.length : 2;
5249 var share = nBots > 6 ? 0.26 : 0.20;
5250 app.miniH = Math.min(nBots > 6 ? 180 : 150, Math.max(86, Math.round(vh * share)));
5251 }
5252 5776 var margin = Math.max(6, Math.round(Math.min(vw, vh) * 0.015));
5253 var availW = Math.max(80, vw - margin * 2);
5254 var availH = Math.max(80, vh - app.hudH - app.miniH - margin);
5255 app.tile = Math.max(14, Math.floor(Math.min(availW / 10, availH / 13)));
5256 app.fieldW = app.tile * 10;
5257 app.fieldH = app.tile * 13;
5258 app.fieldX = Math.floor((vw - app.fieldW) / 2);
5259 var topBand = app.hudH + app.miniH;
5260 app.fieldY = topBand + Math.floor((vh - topBand - app.fieldH - margin / 2) / 2);
5261 if (app.fieldY < topBand)
5262 { app.fieldY = topBand; }
5263 var minis = document.getElementById('minis');
5264 if (minis)
5777 var plan;
5778 if (typeof MiniLayout !== 'undefined' && MiniLayout.plan)
5779 { plan = MiniLayout.plan(vw, vh, n, app.hudH, margin); }
5780 else
5265 5781 {
5266 minis.style.top = app.hudH + 'px';
5267 minis.style.maxHeight = app.miniH + 'px';
5782 plan = {
5783 mode: 'top',
5784 tile: 14,
5785 fieldW: 140,
5786 fieldH: 182,
5787 fieldX: Math.floor((vw - 140) / 2),
5788 fieldY: app.hudH,
5789 miniH: n > 0 ? 100 : 0,
5790 mini: { w: 80, h: 104 },
5791 positions: [],
5792 n: n
5793 };
5268 5794 }
5795 app.miniLayout = plan;
5796 app.miniH = plan.miniH;
5797 app.tile = plan.tile;
5798 app.fieldW = plan.fieldW;
5799 app.fieldH = plan.fieldH;
5800 app.fieldX = plan.fieldX;
5801 app.fieldY = plan.fieldY;
5802 applyMinisLayout();
5803 applyFlightsBackClip();
5269 5804
5270 5805 if (app.scene)
5271 5806 {
@@ -6101,6 +6636,7 @@ function tickOnline (dt)
6101 6636 }
6102 6637 Online.tickFlights();
6103 6638 Online.renderMinis(document.getElementById('minis'));
6639 applyMinisLayout();
6104 6640 }
6105 6641
6106 6642
@@ -6179,7 +6715,8 @@ function tickOffline (dt)
6179 6715 y: s.y,
6180 6716 color: s.color,
6181 6717 startX: start.x,
6182 startY: start.y
6718 startY: start.y,
6719 from_id: s.from_id
6183 6720 };
6184 6721 }
6185 6722 Online.spawnFlights(result.flights, locals);
@@ -6293,16 +6830,20 @@ function miniViewportCenter (botId)
6293 6830 if (!el)
6294 6831 { return { x: window.innerWidth / 2, y: 40 }; }
6295 6832 var rect = el.getBoundingClientRect();
6833 var plan = app.miniLayout;
6834 if (plan && plan.mode === 'sides')
6835 {
6836 var mid = plan.fieldX + plan.fieldW / 2;
6837 if (rect.left + rect.width / 2 < mid)
6838 { return { x: rect.right, y: rect.top + rect.height / 2 }; }
6839 return { x: rect.left, y: rect.top + rect.height / 2 };
6840 }
6296 6841 return { x: rect.left + rect.width / 2, y: rect.bottom };
6297 6842 }
6298 6843
6299 6844 function offlineMiniSize (n)
6300 6845 {
6301 if (n >= 10)
6302 { return { w: 40, h: 52 }; }
6303 if (n >= 6)
6304 { return { w: 56, h: 73 }; }
6305 return { w: 80, h: 104 };
6846 return currentMiniSize();
6306 6847 }
6307 6848
6308 6849 function updateOfflineMinis (dt, force)
@@ -6365,6 +6906,7 @@ function renderOfflineMinis ()
6365 6906 if (!seen[id])
6366 6907 { existing[id].remove(); }
6367 6908 }
6909 applyMinisLayout();
6368 6910 }
6369 6911
6370 6912 function buildColumnWarn ()
@@ -3749,6 +3749,187 @@ else if (typeof globalThis !== 'undefined')
3749 * /workspace/meteors/src/gameCore.js
3749 * /workspace/meteors/src/gameCore.js
3750 */
3750 */
3751
3751
3752/*
3753 * Start File:
3754 * /workspace/meteors/src/miniLayout.js
3755 */
3756'use strict';
3757
3758/**
3759 * Opponent miniature layout for online and Offline Strijd (t1125).
3760 * Wide screens: alternating left/right of the player's field, extra
3761 * rows stacked upward. Narrow screens: a row (wrapping) above the field.
3762 */
3763
3764var MiniLayout = (function ()
3765{
3766
3767var GAP = 12;
3768var VGAP = 8;
3769var EDGE = 16;
3770var MIN_TILE_FOR_SIDES = 18;
3771var MIN_VIEWPORT_FOR_SIDES = 960;
3772var LABEL_H = 32;
3773
3774function canvasSize (n, mode, availH)
3775{
3776 n = n || 0;
3777 if (mode === 'sides' && availH && n > 0)
3778 {
3779 var rows = Math.ceil(n / 2);
3780 var maxOuter = Math.floor((availH - (rows - 1) * VGAP) / Math.max(1, rows));
3781 var ch = Math.max(40, Math.min(104, maxOuter - LABEL_H));
3782 var cw = Math.max(32, Math.round(ch * 10 / 13));
3783 return {
3784 w: cw,
3785 h: ch,
3786 outerW: Math.max(cw + 8, 64),
3787 outerH: ch + LABEL_H
3788 };
3789 }
3790 if (n >= 10)
3791 { return { w: 40, h: 52, outerW: 56, outerH: 52 + LABEL_H }; }
3792 if (n >= 6)
3793 { return { w: 56, h: 73, outerW: 68, outerH: 73 + LABEL_H }; }
3794 return { w: 80, h: 104, outerW: 90, outerH: 104 + LABEL_H };
3795}
3796
3797function sidePositions (n, fieldX, fieldY, fieldW, fieldH, mini, hudH)
3798{
3799 var positions = [];
3800 if (n <= 0)
3801 { return positions; }
3802 var rows = Math.ceil(n / 2);
3803 var stackH = rows * mini.outerH + Math.max(0, rows - 1) * VGAP;
3804 var bottom = fieldY + fieldH;
3805 var top = bottom - stackH;
3806 if (top < hudH + 4)
3807 {
3808 top = hudH + 4;
3809 bottom = top + stackH;
3810 }
3811 for (var i = 0; i < n; i++)
3812 {
3813 var col = i % 2;
3814 var row = Math.floor(i / 2);
3815 var x = col === 0
3816 ? fieldX - GAP - mini.outerW
3817 : fieldX + fieldW + GAP;
3818 var y = bottom - (row + 1) * mini.outerH - row * VGAP;
3819 positions.push({
3820 index: i,
3821 side: col === 0 ? 'left' : 'right',
3822 row: row,
3823 x: x,
3824 y: y,
3825 w: mini.outerW,
3826 h: mini.outerH,
3827 canvasW: mini.w,
3828 canvasH: mini.h
3829 });
3830 }
3831 return positions;
3832}
3833
3834/**
3835 * Compute the field and mini plan for a viewport.
3836 * `n` is the number of opponents (0 = solo, no minis).
3837 */
3838function plan (vw, vh, n, hudH, margin)
3839{
3840 vw = vw || 320;
3841 vh = vh || 480;
3842 n = n || 0;
3843 hudH = hudH == null ? 56 : hudH;
3844 margin = margin == null ? Math.max(6, Math.round(Math.min(vw, vh) * 0.015)) : margin;
3845
3846 function finish (mode, tile, fieldX, fieldY, miniH, mini, positions)
3847 {
3848 return {
3849 mode: mode,
3850 tile: tile,
3851 fieldW: tile * 10,
3852 fieldH: tile * 13,
3853 fieldX: fieldX,
3854 fieldY: fieldY,
3855 miniH: miniH,
3856 mini: mini,
3857 positions: positions || [],
3858 n: n
3859 };
3860 }
3861
3862 if (n > 0)
3863 {
3864 var availHSide = Math.max(80, vh - hudH - margin);
3865 var probe = canvasSize(n, 'sides', availHSide);
3866 var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));
3867 var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHSide / 13)));
3868 var fieldWSide = tileSide * 10;
3869 var fieldHSide = tileSide * 13;
3870 var leftover = (vw - fieldWSide) / 2;
3871 var need = probe.outerW + GAP + EDGE;
3872 if (vw >= MIN_VIEWPORT_FOR_SIDES && leftover >= need
3873 && tileSide >= MIN_TILE_FOR_SIDES)
3874 {
3875 var fieldX = Math.floor((vw - fieldWSide) / 2);
3876 var fieldY = hudH + Math.floor((availHSide - fieldHSide) / 2);
3877 if (fieldY < hudH)
3878 { fieldY = hudH; }
3879 return finish('sides', tileSide, fieldX, fieldY, 0, probe,
3880 sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));
3881 }
3882 }
3883
3884 var miniTop = canvasSize(n, 'top', 0);
3885 var miniH = 0;
3886 if (n > 0)
3887 {
3888 var share = n > 6 ? 0.26 : 0.20;
3889 miniH = Math.min(n > 6 ? 180 : 150, Math.max(86, Math.round(vh * share)));
3890 }
3891 var availW = Math.max(80, vw - margin * 2);
3892 var availH = Math.max(80, vh - hudH - miniH - margin);
3893 var tile = Math.max(14, Math.floor(Math.min(availW / 10, availH / 13)));
3894 var fieldW = tile * 10;
3895 var fieldH = tile * 13;
3896 var fieldX = Math.floor((vw - fieldW) / 2);
3897 var topBand = hudH + miniH;
3898 var fieldY = topBand + Math.floor((vh - topBand - fieldH - margin / 2) / 2);
3899 if (fieldY < topBand)
3900 { fieldY = topBand; }
3901 return finish('top', tile, fieldX, fieldY, miniH, miniTop, []);
3902}
3903
3904var api = {
3905 GAP: GAP,
3906 VGAP: VGAP,
3907 EDGE: EDGE,
3908 MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,
3909 MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,
3910 LABEL_H: LABEL_H,
3911 canvasSize: canvasSize,
3912 sidePositions: sidePositions,
3913 plan: plan
3914};
3915
3916if (typeof module !== 'undefined' && module.exports)
3917{ module.exports = api; }
3918else if (typeof globalThis !== 'undefined')
3919{ globalThis.MiniLayout = api; }
3920
3921return api;
3922
3923})();
3924
3925if (typeof module !== 'undefined' && module.exports && typeof MiniLayout !== 'undefined')
3926{ module.exports = MiniLayout; }
3927
3928/*
3929 * End File:
3930 * /workspace/meteors/src/miniLayout.js
3931 */
3932
3752/*
3933/*
3753 * Start File:
3934 * Start File:
3754 * /workspace/meteors/src/online.js
3935 * /workspace/meteors/src/online.js
@@ -3958,8 +4139,15 @@ Online._handleTransitions = function (prevStatus, data)
3958 { this.onGameStart(lobby); }
4139 { this.onGameStart(lobby); }
3959 if (data && data.incoming && data.incoming.length && this.onIncoming)
4140 if (data && data.incoming && data.incoming.length && this.onIncoming)
3960 { this.onIncoming(data.incoming); }
4141 { this.onIncoming(data.incoming); }
4142 // Own outgoing results (immediate) and lobby-wide recent flights
4143 // (so every client can draw opponent and enemy-to-enemy arcs, t1125).
4144 var flights = [];
3961 if (data && data.shot_results && data.shot_results.length)
4145 if (data && data.shot_results && data.shot_results.length)
3962 { this.spawnFlights(data.shot_results, this._lastQueuedMeta); }
4146 { flights = flights.concat(data.shot_results); }
4147 if (data && data.shot_flights && data.shot_flights.length)
4148 { flights = flights.concat(data.shot_flights); }
4149 if (flights.length)
4150 { this.spawnFlights(flights, this._flightLocals); }
3963 if (status === 'finished' && prevStatus !== 'finished' && this.onFinished)
4151 if (status === 'finished' && prevStatus !== 'finished' && this.onFinished)
3964 { this.onFinished(lobby); }
4152 { this.onFinished(lobby); }
3965 if (status === 'waiting' && prevStatus === 'finished' && this.onLobbyReturn)
4153 if (status === 'waiting' && prevStatus === 'finished' && this.onLobbyReturn)
@@ -4050,6 +4238,20 @@ Online.renderMinis = function (container)
4050 + '<div class="mini-meta"></div>';
4238 + '<div class="mini-meta"></div>';
4051 container.appendChild(el);
4239 container.appendChild(el);
4052 }
4240 }
4241 var mz = (typeof app !== 'undefined' && app.miniLayout && app.miniLayout.mini)
4242 ? app.miniLayout.mini
4243 : { w: 80, h: 104 };
4244 var canvas = el.querySelector('canvas');
4245 if (canvas && (canvas.width !== mz.w || canvas.height !== mz.h))
4246 {
4247 canvas.width = mz.w;
4248 canvas.height = mz.h;
4249 }
4250 if (canvas)
4251 {
4252 canvas.style.width = mz.w + 'px';
4253 canvas.style.height = mz.h + 'px';
4254 }
4053 el.classList.toggle('eliminated', !!p.eliminated);
4255 el.classList.toggle('eliminated', !!p.eliminated);
4054 el.querySelector('.mini-name').textContent = p.name + (p.is_host ? ' (host)' : '');
4256 el.querySelector('.mini-name').textContent = p.name + (p.is_host ? ' (host)' : '');
4055 el.querySelector('.mini-meta').textContent = p.eliminated
4257 el.querySelector('.mini-meta').textContent = p.eliminated
@@ -4062,6 +4264,8 @@ Online.renderMinis = function (container)
4062 if (!seen[id])
4264 if (!seen[id])
4063 { existing[id].remove(); }
4265 { existing[id].remove(); }
4064 }
4266 }
4267 if (typeof applyMinisLayout === 'function')
4268 { applyMinisLayout(); }
4065};
4269};
4066
4270
4067var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];
4271var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];
@@ -4156,40 +4360,221 @@ function colorSpriteUrl (color, planetId)
4156 * startX, startY} in viewport pixels, filled by the view just after
4360 * startX, startY} in viewport pixels, filled by the view just after
4157 * consumeOutgoingShots.
4361 * consumeOutgoingShots.
4158 */
4362 */
4363Online.playerId = function ()
4364{
4365 if (typeof app !== 'undefined' && app.offline)
4366 { return 'player'; }
4367 if (this.lobby && this.lobby.players)
4368 {
4369 for (var i = 0; i < this.lobby.players.length; i++)
4370 {
4371 if (this.lobby.players[i].is_me)
4372 { return this.lobby.players[i].id; }
4373 }
4374 }
4375 return 'player';
4376};
4377
4378/**
4379 * Classify a shot for visual treatment (t1125).
4380 * player-to-enemy, enemy-to-player, enemy-to-enemy,
4381 * player-miss, enemy-miss.
4382 */
4383Online.flightKind = function (fromId, targetId, miss)
4384{
4385 var me = this.playerId();
4386 var fromMe = !fromId || fromId === me || fromId === 'player';
4387 if (miss)
4388 { return fromMe ? 'player-miss' : 'enemy-miss'; }
4389 if (fromMe)
4390 { return 'player-to-enemy'; }
4391 if (targetId === me || targetId === 'player')
4392 { return 'enemy-to-player'; }
4393 return 'enemy-to-enemy';
4394};
4395
4396/**
4397 * Parabolic arc: linear in x, a rise of `height` pixels above the
4398 * chord at mid-flight (screen y grows downward, so we subtract).
4399 */
4400Online.arcPoint = function (start, end, u, height)
4401{
4402 var t = u < 0 ? 0 : (u > 1 ? 1 : u);
4403 var x = start.x + (end.x - start.x) * t;
4404 var y = start.y + (end.y - start.y) * t - 4 * height * t * (1 - t);
4405 return { x: x, y: y };
4406};
4407
4408Online.arcHeight = function (start, end)
4409{
4410 var dx = end.x - start.x;
4411 var dy = end.y - start.y;
4412 var dist = Math.sqrt(dx * dx + dy * dy);
4413 return Math.max(48, Math.min(220, dist * 0.28));
4414};
4415
4416Online.easeInOutCubic = function (t)
4417{
4418 if (t < 0.5)
4419 { return 4 * t * t * t; }
4420 var u = -2 * t + 2;
4421 return 1 - (u * u * u) / 2;
4422};
4423
4424Online._miniCellSize = function (playerId)
4425{
4426 var el = this.miniElement(playerId);
4427 var canvas = el && el.querySelector('canvas');
4428 if (canvas)
4429 {
4430 var r = canvas.getBoundingClientRect();
4431 return Math.max(6, r.width / 10);
4432 }
4433 return 10;
4434};
4435
4436Online._fullTileSize = function ()
4437{
4438 if (typeof app !== 'undefined' && app.tile)
4439 { return app.tile; }
4440 return 40;
4441};
4442
4443Online._miniAnchor = function (playerId, dir)
4444{
4445 var el = this.miniElement(playerId);
4446 var canvas = el && (el.querySelector ? el.querySelector('canvas') : null);
4447 var box = canvas || el;
4448 if (!box)
4449 { return { x: window.innerWidth / 2, y: 48 }; }
4450 var r = box.getBoundingClientRect();
4451 if (dir === 'out')
4452 { return { x: r.left + r.width / 2, y: r.top + 4 }; }
4453 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
4454};
4455
4456Online._fieldTop = function (col)
4457{
4458 return this._flightStart(col);
4459};
4460
4461/**
4462 * Animate shot results. `locals` is a map of client_id → {col, y, color,
4463 * startX, startY, from_id} in viewport pixels.
4464 *
4465 * Visual-only (t1125): a parabolic arc whose scale goes from mini-cell
4466 * to full tile (or the reverse). Enemy-to-enemy arcs stay small and
4467 * are drawn behind the player's field. Delivery timing is unchanged;
4468 * a late-seen flight starts mid-arc via `age`.
4469 */
4159Online.spawnFlights = function (results, locals)
4470Online.spawnFlights = function (results, locals)
4160{
4471{
4161 locals = locals || this._flightLocals || {};
4472 locals = locals || this._flightLocals || {};
4162 var layer = document.getElementById('flights');
4473 var front = document.getElementById('flights');
4163 if (!layer)
4474 var back = document.getElementById('flights-back') || front;
4475 if (!front)
4164 { return; }
4476 { return; }
4477 if (!this._flightSeen)
4478 { this._flightSeen = Object.create(null); }
4479 var now = performance.now();
4480 var full = this._fullTileSize();
4165 for (var i = 0; i < results.length; i++)
4481 for (var i = 0; i < results.length; i++)
4166 {
4482 {
4167 var r = results[i];
4483 var r = results[i];
4168 var meta = locals[r.client_id] || {};
4484 var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));
4169 var start = this._flightStart(meta.col);
4485 if (this._flightSeen[sid])
4170 var end;
4486 { continue; }
4487 this._flightSeen[sid] = now;
4488
4489 var meta = locals[r.client_id] || locals[sid] || {};
4490 var fromId = r.from_id || r.from_user || meta.from_id || null;
4491 var targetId = r.target_id != null ? r.target_id : r.to_user;
4171 var miss = !!r.miss;
4492 var miss = !!r.miss;
4493 var kind = this.flightKind(fromId, targetId, miss);
4494 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
4495 if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)
4496 { continue; }
4497
4498 var start;
4499 if (meta.startX != null && isFinite(meta.startX))
4500 { start = { x: meta.startX, y: meta.startY }; }
4501 else if (kind === 'player-to-enemy' || kind === 'player-miss')
4502 { start = this._flightStart(meta.col != null ? meta.col : r.col); }
4503 else
4504 { start = this._miniAnchor(fromId, 'out'); }
4505
4506 var end;
4172 if (miss)
4507 if (miss)
4173 { end = this._missEnd(start); }
4508 { end = this._missEnd(start, kind === 'enemy-miss'); }
4509 else if (kind === 'enemy-to-player')
4510 { end = this._fieldTop(null); }
4174 else
4511 else
4175 { end = this._targetEnd(r.target_id, start); }
4512 { end = this._targetEnd(targetId, start); }
4513
4514 var startScale;
4515 var endScale;
4516 var mini = this._miniCellSize(fromId || targetId) / full;
4517 if (mini < 0.12)
4518 { mini = 0.2; }
4519 if (kind === 'player-to-enemy')
4520 {
4521 startScale = 1;
4522 endScale = mini;
4523 }
4524 else if (kind === 'enemy-to-player')
4525 {
4526 startScale = mini;
4527 endScale = 1;
4528 }
4529 else if (kind === 'enemy-to-enemy')
4530 {
4531 startScale = mini;
4532 endScale = mini;
4533 }
4534 else if (kind === 'enemy-miss')
4535 {
4536 startScale = mini;
4537 endScale = 0;
4538 }
4539 else
4540 {
4541 startScale = 1;
4542 endScale = 0;
4543 }
4544
4545 var layer = (kind === 'enemy-to-enemy' && back) ? back : front;
4176 var el = document.createElement('img');
4546 var el = document.createElement('img');
4177 el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);
4547 el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);
4178 el.alt = '';
4548 el.alt = '';
4179 el.className = 'flight';
4549 el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');
4550 el.style.width = full + 'px';
4551 el.style.height = full + 'px';
4180 layer.appendChild(el);
4552 layer.appendChild(el);
4181 var spin = (Math.random() * 2 - 1) * 720;
4553
4182 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
4554 var t0 = now;
4555 if (r.age != null && isFinite(r.age) && r.age > 0)
4556 {
4557 var u0 = Math.min(0.95, (r.age * 1000) / duration);
4558 t0 = now - u0 * duration;
4559 }
4560 var height = miss
4561 ? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
4562 : this.arcHeight(start, end);
4183 this._flights.push({
4563 this._flights.push({
4184 el: el,
4564 el: el,
4185 start: start,
4565 start: start,
4186 end: end,
4566 end: end,
4187 ctrl: miss ? this._missCtrl(start, end) : this._hitCtrl(start, end),
4567 ctrl: miss ? this._missCtrl(start, end) : null,
4188 t0: performance.now(),
4568 height: height,
4569 t0: t0,
4189 duration: duration,
4570 duration: duration,
4190 spin: spin,
4571 spin: (Math.random() * 2 - 1) * 720,
4191 miss: miss,
4572 miss: miss,
4192 angle: Math.random() * 360
4573 kind: kind,
4574 startScale: startScale,
4575 endScale: endScale,
4576 angle: Math.random() * 360,
4577 id: sid
4193 });
4578 });
4194 }
4579 }
4195 this._flightLocals = {};
4580 this._flightLocals = {};
@@ -4204,13 +4589,13 @@ Online.rememberFlightLocal = function (shot, startX, startY)
4204 y: shot.y,
4589 y: shot.y,
4205 color: shot.color,
4590 color: shot.color,
4206 startX: startX,
4591 startX: startX,
4207 startY: startY
4592 startY: startY,
4593 from_id: shot.from_id
4208 };
4594 };
4209};
4595};
4210
4596
4211Online._flightStart = function (col)
4597Online._flightStart = function (col)
4212{
4598{
4213 var field = document.querySelector('canvas');
4214 var appRef = typeof app !== 'undefined' ? app : null;
4599 var appRef = typeof app !== 'undefined' ? app : null;
4215 if (appRef && appRef.scene && appRef.scene.canvas)
4600 if (appRef && appRef.scene && appRef.scene.canvas)
4216 {
4601 {
@@ -4222,6 +4607,7 @@ Online._flightStart = function (col)
4222 y: rect.top + 4
4607 y: rect.top + 4
4223 };
4608 };
4224 }
4609 }
4610 var field = document.querySelector('canvas');
4225 if (field)
4611 if (field)
4226 {
4612 {
4227 var rect = field.getBoundingClientRect();
4613 var rect = field.getBoundingClientRect();
@@ -4235,19 +4621,25 @@ Online._targetEnd = function (targetId, start)
4235 var el = targetId && this.miniElement(targetId);
4621 var el = targetId && this.miniElement(targetId);
4236 if (el)
4622 if (el)
4237 {
4623 {
4238 var r = el.getBoundingClientRect();
4624 var canvas = el.querySelector('canvas') || el;
4625 var r = canvas.getBoundingClientRect();
4239 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
4626 return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
4240 }
4627 }
4241 return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };
4628 return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };
4242};
4629};
4243
4630
4244Online._missEnd = function (start)
4631Online._missEnd = function (start, fromMini)
4245{
4632{
4246 var dx = (Math.random() * 2 - 1) * window.innerWidth * 0.35;
4633 var w = window.innerWidth || 800;
4247 return {
4634 var outward;
4248 x: start.x + dx,
4635 if (start.x < w * 0.4)
4249 y: start.y - (120 + Math.random() * 220)
4636 { outward = -(80 + Math.random() * w * 0.25); }
4250 };
4637 else if (start.x > w * 0.6)
4638 { outward = (80 + Math.random() * w * 0.25); }
4639 else
4640 { outward = (Math.random() * 2 - 1) * w * 0.35; }
4641 var lift = fromMini ? (80 + Math.random() * 160) : (120 + Math.random() * 220);
4642 return { x: start.x + outward, y: start.y - lift };
4251};
4643};
4252
4644
4253Online._missCtrl = function (start, end)
4645Online._missCtrl = function (start, end)
@@ -4273,26 +4665,53 @@ Online.tickFlights = function (now)
4273 for (var i = 0; i < this._flights.length; i++)
4665 for (var i = 0; i < this._flights.length; i++)
4274 {
4666 {
4275 var f = this._flights[i];
4667 var f = this._flights[i];
4276 var u = (now - f.t0) / f.duration;
4668 var raw = (now - f.t0) / f.duration;
4277 if (u >= 1)
4669 if (raw >= 1)
4278 {
4670 {
4279 if (f.el && f.el.parentNode)
4671 if (f.el && f.el.parentNode)
4280 { f.el.parentNode.removeChild(f.el); }
4672 { f.el.parentNode.removeChild(f.el); }
4281 continue;
4673 continue;
4282 }
4674 }
4283 // Quadratic bezier, ease-in so they feel like they recede.
4675 if (raw < 0)
4284 var e = u * u;
4676 { raw = 0; }
4285 var mt = 1 - e;
4677 var u = this.easeInOutCubic(raw);
4286 var x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
4678 var x, y;
4287 var y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
4679 if (f.miss && f.ctrl)
4288 var scale = f.miss ? (1 - e) : (1 - 0.85 * e);
4680 {
4289 var angle = f.angle + f.spin * u;
4681 var e = raw * raw;
4682 var mt = 1 - e;
4683 x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
4684 y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
4685 }
4686 else
4687 {
4688 var pt = this.arcPoint(f.start, f.end, u, f.height || 80);
4689 x = pt.x;
4690 y = pt.y;
4691 }
4692 var scale = f.startScale + (f.endScale - f.startScale) * u;
4693 if (f.miss)
4694 {
4695 var fadeU = raw * raw;
4696 scale = f.startScale * (1 - fadeU);
4697 }
4698 var angle = f.angle + f.spin * raw;
4290 f.el.style.transform = 'translate(' + x + 'px,' + y + 'px) translate(-50%,-50%) rotate('
4699 f.el.style.transform = 'translate(' + x + 'px,' + y + 'px) translate(-50%,-50%) rotate('
4291 + angle + 'deg) scale(' + scale + ')';
4700 + angle + 'deg) scale(' + scale + ')';
4292 f.el.style.opacity = f.miss ? String(1 - e) : '1';
4701 f.el.style.opacity = f.miss ? String(Math.max(0, 1 - raw * raw)) : '1';
4293 leftover.push(f);
4702 leftover.push(f);
4294 }
4703 }
4295 this._flights = leftover;
4704 this._flights = leftover;
4705 if (this._flightSeen)
4706 {
4707 var cutoff = now - 8000;
4708 var ids = Object.keys(this._flightSeen);
4709 for (var k = 0; k < ids.length; k++)
4710 {
4711 if (this._flightSeen[ids[k]] < cutoff)
4712 { delete this._flightSeen[ids[k]]; }
4713 }
4714 }
4296};
4715};
4297
4716
4298Online.clearFlights = function ()
4717Online.clearFlights = function ()
@@ -4305,6 +4724,7 @@ Online.clearFlights = function ()
4305 }
4724 }
4306 this._flights = [];
4725 this._flights = [];
4307 this._flightLocals = {};
4726 this._flightLocals = {};
4727 this._flightSeen = Object.create(null);
4308};
4728};
4309
4729
4310if (typeof globalThis !== 'undefined')
4730if (typeof globalThis !== 'undefined')
@@ -5215,13 +5635,122 @@ function placeTile (obj, col, y)
5215 obj.transform.size = { x: t, y: t };
5635 obj.transform.size = { x: t, y: t };
5216}
5636}
5217
5637
5638function opponentCount ()
5639{
5640 if (app.offline && app.battle && app.battle.bots)
5641 { return app.battle.bots.length; }
5642 if (app.online && typeof Online !== 'undefined' && Online.opponents)
5643 { return Online.opponents().length; }
5644 return 0;
5645}
5646
5647function currentMiniSize ()
5648{
5649 if (app.miniLayout && app.miniLayout.mini)
5650 { return { w: app.miniLayout.mini.w, h: app.miniLayout.mini.h }; }
5651 var n = opponentCount();
5652 var mode = (app.miniLayout && app.miniLayout.mode) || 'top';
5653 if (typeof MiniLayout !== 'undefined' && MiniLayout.canvasSize)
5654 { return MiniLayout.canvasSize(n, mode, 0); }
5655 if (n >= 10)
5656 { return { w: 40, h: 52 }; }
5657 if (n >= 6)
5658 { return { w: 56, h: 73 }; }
5659 return { w: 80, h: 104 };
5660}
5661
5662function applyMinisContainer (plan)
5663{
5664 var minis = document.getElementById('minis');
5665 if (!minis)
5666 { return; }
5667 var n = plan ? plan.n : 0;
5668 minis.classList.toggle('crowded', n > 5);
5669 if (!plan || n === 0 || plan.mode !== 'sides')
5670 {
5671 minis.classList.remove('sides');
5672 minis.style.top = (app.hudH || 56) + 'px';
5673 minis.style.maxHeight = (plan && plan.miniH ? plan.miniH : 0) + 'px';
5674 minis.style.bottom = '';
5675 minis.style.left = '';
5676 minis.style.right = '';
5677 var kids = minis.querySelectorAll('.mini');
5678 for (var i = 0; i < kids.length; i++)
5679 {
5680 kids[i].style.left = '';
5681 kids[i].style.top = '';
5682 kids[i].style.width = '';
5683 kids[i].style.position = '';
5684 }
5685 return;
5686 }
5687 minis.classList.add('sides');
5688 minis.style.top = '0';
5689 minis.style.bottom = '0';
5690 minis.style.left = '0';
5691 minis.style.right = '0';
5692 minis.style.maxHeight = 'none';
5693}
5694
5695function applyMinisLayout ()
5696{
5697 var plan = app.miniLayout;
5698 var minis = document.getElementById('minis');
5699 if (!minis)
5700 { return; }
5701 applyMinisContainer(plan);
5702 if (!plan || plan.mode !== 'sides')
5703 { return; }
5704 var positions = plan.positions || [];
5705 var kids = minis.querySelectorAll('.mini');
5706 for (var i = 0; i < positions.length && i < kids.length; i++)
5707 {
5708 var p = positions[i];
5709 var el = kids[i];
5710 el.style.position = 'absolute';
5711 el.style.left = p.x + 'px';
5712 el.style.top = p.y + 'px';
5713 el.style.width = p.w + 'px';
5714 var canvas = el.querySelector('canvas');
5715 if (canvas)
5716 {
5717 canvas.style.width = p.canvasW + 'px';
5718 canvas.style.height = p.canvasH + 'px';
5719 }
5720 }
5721}
5722
5723function applyFlightsBackClip ()
5724{
5725 var back = document.getElementById('flights-back');
5726 if (!back)
5727 { return; }
5728 var x = app.fieldX || 0;
5729 var y = app.fieldY || 0;
5730 var w = app.fieldW || 0;
5731 var h = app.fieldH || 0;
5732 if (!w || !h)
5733 {
5734 back.style.clipPath = '';
5735 return;
5736 }
5737 // Even-odd polygon: full viewport with a hole over the player's field,
5738 // so enemy-to-enemy arcs travel behind the field (t1125).
5739 back.style.clipPath = 'polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0, '
5740 + x + 'px ' + y + 'px, ' + (x + w) + 'px ' + y + 'px, '
5741 + (x + w) + 'px ' + (y + h) + 'px, ' + x + 'px ' + (y + h) + 'px, '
5742 + x + 'px ' + y + 'px)';
5743}
5744
5218function layoutIfNeeded ()
5745function layoutIfNeeded ()
5219{
5746{
5220 if (app.core && app.core.drag)
5747 if (app.core && app.core.drag)
5221 { return; }
5748 { return; }
5222 var vw = window.innerWidth || 320;
5749 var vw = window.innerWidth || 320;
5223 var vh = window.innerHeight || 480;
5750 var vh = window.innerHeight || 480;
5224 if (app._layoutVw === vw && app._layoutVh === vh && app.scene && app.tile)
5751 var n = (app.online || app.offline) ? opponentCount() : 0;
5752 if (app._layoutVw === vw && app._layoutVh === vh && app._layoutN === n
5753 && app.scene && app.tile)
5225 { return; }
5754 { return; }
5226 layout();
5755 layout();
5227}
5756}
@@ -5232,8 +5761,10 @@ function layout ()
5232 { return; }
5761 { return; }
5233 var vw = window.innerWidth || 320;
5762 var vw = window.innerWidth || 320;
5234 var vh = window.innerHeight || 480;
5763 var vh = window.innerHeight || 480;
5764 var n = (app.online || app.offline) ? opponentCount() : 0;
5235 app._layoutVw = vw;
5765 app._layoutVw = vw;
5236 app._layoutVh = vh;
5766 app._layoutVh = vh;
5767 app._layoutN = n;
5237 var safeTop = 0;
5768 var safeTop = 0;
5238 try
5769 try
5239 {
5770 {
@@ -5242,30 +5773,34 @@ function layout ()
5242 }
5773 }
5243 catch (e) { /* ignore */ }
5774 catch (e) { /* ignore */ }
5244 app.hudH = Math.max(56, Math.round(vh * 0.09) + safeTop);
5775 app.hudH = Math.max(56, Math.round(vh * 0.09) + safeTop);
5245 app.miniH = 0;
5246 if (app.online || app.offline)
5247 {
5248 var nBots = (app.battle && app.battle.bots) ? app.battle.bots.length : 2;
5249 var share = nBots > 6 ? 0.26 : 0.20;
5250 app.miniH = Math.min(nBots > 6 ? 180 : 150, Math.max(86, Math.round(vh * share)));
5251 }
5252 var margin = Math.max(6, Math.round(Math.min(vw, vh) * 0.015));
5776 var margin = Math.max(6, Math.round(Math.min(vw, vh) * 0.015));
5253 var availW = Math.max(80, vw - margin * 2);
5777 var plan;
5254 var availH = Math.max(80, vh - app.hudH - app.miniH - margin);
5778 if (typeof MiniLayout !== 'undefined' && MiniLayout.plan)
5255 app.tile = Math.max(14, Math.floor(Math.min(availW / 10, availH / 13)));
5779 { plan = MiniLayout.plan(vw, vh, n, app.hudH, margin); }
5256 app.fieldW = app.tile * 10;
5780 else
5257 app.fieldH = app.tile * 13;
5258 app.fieldX = Math.floor((vw - app.fieldW) / 2);
5259 var topBand = app.hudH + app.miniH;
5260 app.fieldY = topBand + Math.floor((vh - topBand - app.fieldH - margin / 2) / 2);
5261 if (app.fieldY < topBand)
5262 { app.fieldY = topBand; }
5263 var minis = document.getElementById('minis');
5264 if (minis)
5265 {
5781 {
5266 minis.style.top = app.hudH + 'px';
5782 plan = {
5267 minis.style.maxHeight = app.miniH + 'px';
5783 mode: 'top',
5784 tile: 14,
5785 fieldW: 140,
5786 fieldH: 182,
5787 fieldX: Math.floor((vw - 140) / 2),
5788 fieldY: app.hudH,
5789 miniH: n > 0 ? 100 : 0,
5790 mini: { w: 80, h: 104 },
5791 positions: [],
5792 n: n
5793 };
5268 }
5794 }
5795 app.miniLayout = plan;
5796 app.miniH = plan.miniH;
5797 app.tile = plan.tile;
5798 app.fieldW = plan.fieldW;
5799 app.fieldH = plan.fieldH;
5800 app.fieldX = plan.fieldX;
5801 app.fieldY = plan.fieldY;
5802 applyMinisLayout();
5803 applyFlightsBackClip();
5269
5804
5270 if (app.scene)
5805 if (app.scene)
5271 {
5806 {
@@ -6101,6 +6636,7 @@ function tickOnline (dt)
6101 }
6636 }
6102 Online.tickFlights();
6637 Online.tickFlights();
6103 Online.renderMinis(document.getElementById('minis'));
6638 Online.renderMinis(document.getElementById('minis'));
6639 applyMinisLayout();
6104}
6640}
6105
6641
6106
6642
@@ -6179,7 +6715,8 @@ function tickOffline (dt)
6179 y: s.y,
6715 y: s.y,
6180 color: s.color,
6716 color: s.color,
6181 startX: start.x,
6717 startX: start.x,
6182 startY: start.y
6718 startY: start.y,
6719 from_id: s.from_id
6183 };
6720 };
6184 }
6721 }
6185 Online.spawnFlights(result.flights, locals);
6722 Online.spawnFlights(result.flights, locals);
@@ -6293,16 +6830,20 @@ function miniViewportCenter (botId)
6293 if (!el)
6830 if (!el)
6294 { return { x: window.innerWidth / 2, y: 40 }; }
6831 { return { x: window.innerWidth / 2, y: 40 }; }
6295 var rect = el.getBoundingClientRect();
6832 var rect = el.getBoundingClientRect();
6833 var plan = app.miniLayout;
6834 if (plan && plan.mode === 'sides')
6835 {
6836 var mid = plan.fieldX + plan.fieldW / 2;
6837 if (rect.left + rect.width / 2 < mid)
6838 { return { x: rect.right, y: rect.top + rect.height / 2 }; }
6839 return { x: rect.left, y: rect.top + rect.height / 2 };
6840 }
6296 return { x: rect.left + rect.width / 2, y: rect.bottom };
6841 return { x: rect.left + rect.width / 2, y: rect.bottom };
6297}
6842}
6298
6843
6299function offlineMiniSize (n)
6844function offlineMiniSize (n)
6300{
6845{
6301 if (n >= 10)
6846 return currentMiniSize();
6302 { return { w: 40, h: 52 }; }
6303 if (n >= 6)
6304 { return { w: 56, h: 73 }; }
6305 return { w: 80, h: 104 };
6306}
6847}
6307
6848
6308function updateOfflineMinis (dt, force)
6849function updateOfflineMinis (dt, force)
@@ -6365,6 +6906,7 @@ function renderOfflineMinis ()
6365 if (!seen[id])
6906 if (!seen[id])
6366 { existing[id].remove(); }
6907 { existing[id].remove(); }
6367 }
6908 }
6909 applyMinisLayout();
6368}
6910}
6369
6911
6370function buildColumnWarn ()
6912function buildColumnWarn ()