chore: rebuild game.js (t1173)
@@ -1301,7 +1301,11 @@ var I18N_CATALOG = {
1301
1301
"block.forge-brass": "Forge brass",
1302
1302
"block.forge-soot": "Forge soot",
1303
1303
"error.webgl": "This game needs WebGL. Please try another browser, or turn on hardware acceleration.",
1304
"error.startFailed": "Could not start the game."
1304
"error.startFailed": "Could not start the game.",
1305
"reward.won": "You won!",
1306
"reward.lost": "You lost...",
1307
"reward.total": "Total points",
1308
"reward.continue": "Tap to continue"
1305
1309
},
1306
1310
"nl": {
1307
1311
"menu.tagline": "Drie op een rij, en je blokjes krijgen raketmotoren.",
@@ -1582,7 +1586,11 @@ var I18N_CATALOG = {
1582
1586
"block.forge-brass": "Forge-messing",
1583
1587
"block.forge-soot": "Forge-roet",
1584
1588
"error.webgl": "Dit spel heeft WebGL nodig. Probeer een andere browser, of zet hardwareversnelling aan.",
1585
"error.startFailed": "Het spel kon niet worden gestart."
1589
"error.startFailed": "Het spel kon niet worden gestart.",
1590
"reward.won": "Gewonnen!",
1591
"reward.lost": "Verloren...",
1592
"reward.total": "Totaal punten",
1593
"reward.continue": "Tik om verder te gaan"
1586
1594
},
1587
1595
"de": {
1588
1596
"menu.tagline": "Drei in einer Reihe — und deine Blöcke bekommen Raketenantrieb.",
@@ -1863,7 +1871,11 @@ var I18N_CATALOG = {
1863
1871
"block.forge-brass": "Forge-Messing",
1864
1872
"block.forge-soot": "Forge-Ruß",
1865
1873
"error.webgl": "Dieses Spiel benötigt WebGL. Bitte verwende einen anderen Browser oder aktiviere die Hardwarebeschleunigung.",
1866
"error.startFailed": "Das Spiel konnte nicht gestartet werden."
1874
"error.startFailed": "Das Spiel konnte nicht gestartet werden.",
1875
"reward.won": "Gewonnen!",
1876
"reward.lost": "Verloren...",
1877
"reward.total": "Punkte gesamt",
1878
"reward.continue": "Tippen zum Fortfahren"
1867
1879
},
1868
1880
"fr": {
1869
1881
"menu.tagline": "Trois d’affilée, et tes blocs s’équipent de propulseurs.",
@@ -2144,7 +2156,11 @@ var I18N_CATALOG = {
2144
2156
"block.forge-brass": "Forge laiton",
2145
2157
"block.forge-soot": "Forge suie",
2146
2158
"error.webgl": "Ce jeu a besoin de WebGL. Essayez un autre navigateur, ou activez l’accélération matérielle.",
2147
"error.startFailed": "Impossible de lancer le jeu."
2159
"error.startFailed": "Impossible de lancer le jeu.",
2160
"reward.won": "Victoire !",
2161
"reward.lost": "Perdu...",
2162
"reward.total": "Total des points",
2163
"reward.continue": "Touchez pour continuer"
2148
2164
},
2149
2165
"ja": {
2150
2166
"menu.tagline": "三つ揃えると、ブロックにロケットが点火します。",
@@ -2425,7 +2441,11 @@ var I18N_CATALOG = {
2425
2441
"block.forge-brass": "フォージの真鍮",
2426
2442
"block.forge-soot": "フォージの煤",
2427
2443
"error.webgl": "このゲームにはWebGLが必要です。別のブラウザを使うか、ハードウェアアクセラレーションを有効にしてください。",
2428
"error.startFailed": "ゲームを開始できませんでした。"
2444
"error.startFailed": "ゲームを開始できませんでした。",
2445
"reward.won": "勝利!",
2446
"reward.lost": "敗北...",
2447
"reward.total": "合計ポイント",
2448
"reward.continue": "タップして続ける"
2429
2449
},
2430
2450
"zh": {
2431
2451
"menu.tagline": "三个一排,你的方块就会装上火箭。",
@@ -2706,7 +2726,11 @@ var I18N_CATALOG = {
2706
2726
"block.forge-brass": "Forge黄铜",
2707
2727
"block.forge-soot": "Forge煤烟",
2708
2728
"error.webgl": "本游戏需要 WebGL。请尝试其他浏览器,或开启硬件加速。",
2709
"error.startFailed": "无法开始游戏。"
2729
"error.startFailed": "无法开始游戏。",
2730
"reward.won": "你赢了!",
2731
"reward.lost": "你输了...",
2732
"reward.total": "总积分",
2733
"reward.continue": "点击继续"
2710
2734
},
2711
2735
"ko": {
2712
2736
"menu.tagline": "세 개를 나란히 맞추면 블록에 로켓이 점화됩니다.",
@@ -2987,7 +3011,11 @@ var I18N_CATALOG = {
2987
3011
"block.forge-brass": "Forge 황동",
2988
3012
"block.forge-soot": "Forge 그을음",
2989
3013
"error.webgl": "이 게임은 WebGL이 필요합니다. 다른 브라우저를 사용하거나 하드웨어 가속을 켜 주세요.",
2990
"error.startFailed": "게임을 시작할 수 없습니다."
3014
"error.startFailed": "게임을 시작할 수 없습니다.",
3015
"reward.won": "승리!",
3016
"reward.lost": "패배...",
3017
"reward.total": "총 포인트",
3018
"reward.continue": "탭하여 계속"
2991
3019
},
2992
3020
"pl": {
2993
3021
"menu.tagline": "Trzy w rzędzie, a twoje klocki dostają napęd rakietowy.",
@@ -3268,7 +3296,11 @@ var I18N_CATALOG = {
3268
3296
"block.forge-brass": "Forge mosiądz",
3269
3297
"block.forge-soot": "Forge sadza",
3270
3298
"error.webgl": "Ta gra wymaga WebGL. Spróbuj innej przeglądarki albo włącz akcelerację sprzętową.",
3271
"error.startFailed": "Nie udało się uruchomić gry."
3299
"error.startFailed": "Nie udało się uruchomić gry.",
3300
"reward.won": "Wygrana!",
3301
"reward.lost": "Przegrana...",
3302
"reward.total": "Suma punktów",
3303
"reward.continue": "Dotknij, aby kontynuować"
3272
3304
},
3273
3305
"ru": {
3274
3306
"menu.tagline": "Три в ряд — и твои блоки получают ракетные двигатели.",
@@ -3549,7 +3581,11 @@ var I18N_CATALOG = {
3549
3581
"block.forge-brass": "Forge (латунь)",
3550
3582
"block.forge-soot": "Forge (сажа)",
3551
3583
"error.webgl": "Этой игре нужен WebGL. Попробуйте другой браузер или включите аппаратное ускорение.",
3552
"error.startFailed": "Не удалось начать игру."
3584
"error.startFailed": "Не удалось начать игру.",
3585
"reward.won": "Победа!",
3586
"reward.lost": "Поражение...",
3587
"reward.total": "Всего очков",
3588
"reward.continue": "Нажмите, чтобы продолжить"
3553
3589
},
3554
3590
"es": {
3555
3591
"menu.tagline": "Tres en raya, y tus bloques ganan motores cohete.",
@@ -3830,7 +3866,11 @@ var I18N_CATALOG = {
3830
3866
"block.forge-brass": "Forge latón",
3831
3867
"block.forge-soot": "Forge hollín",
3832
3868
"error.webgl": "Este juego necesita WebGL. Prueba con otro navegador o activa la aceleración por hardware.",
3833
"error.startFailed": "No se pudo iniciar el juego."
3869
"error.startFailed": "No se pudo iniciar el juego.",
3870
"reward.won": "¡Has ganado!",
3871
"reward.lost": "Has perdido...",
3872
"reward.total": "Puntos totales",
3873
"reward.continue": "Toca para continuar"
3834
3874
}
3835
3875
},
3836
3876
"errors": {
@@ -11195,6 +11235,530 @@ if (typeof module !== 'undefined' && module.exports && typeof Offline !== 'undef
11195
11235
* /workspace/meteors/src/offline.js
11196
11236
*/
11197
11237
11238
/*
11239
* Start File:
11240
* /workspace/meteors/src/reward.js
11241
*/
11242
/*
11243
* End-of-round reward screen (t1173 / t1174).
11244
*
11245
* Logged-in only. Sequence: a centred "You won!" / "You lost..." for
11246
* INTRO seconds, then it tweens to the top (RISE seconds). Once the
11247
* server has confirmed the new profile total, blocks of the player's
11248
* planet arc from the top of the screen into a counter at the bottom
11249
* centre, one block per newly earned point. Each arrival adds 1.
11250
*
11251
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the
11252
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and
11253
* block i (0-based) leaves at T(i) = the t where N(t) = i.
11254
* 253 points → the last block leaves at exactly 18 s.
11255
*
11256
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)
11257
* has no DOM and is unit-tested. Reward.play wires it to an overlay.
11258
*/
11259
(function (root)
11260
{
11261
'use strict';
11262
11263
var RATE0 = 5; // blocks per second at t = 0
11264
var ACCEL = 1; // +1 block/s every second
11265
var INTRO = 1.0; // centred title before it rises
11266
var RISE = 0.6; // title tween to the top
11267
var FLIGHT = 0.7; // one block's arc duration
11268
var HOLD = 1.5; // final total shown before continuing
11269
var HOLD_ZERO = 1.5; // earned 0: show the number briefly
11270
var WAIT_MAX = 8; // give up waiting for the server after this
11271
11272
/** Seconds after the start of counting when block i (0-based) leaves. */
11273
function spawnTime (i)
11274
{
11275
if (!(i > 0))
11276
{ return 0; }
11277
if (ACCEL === 0)
11278
{ return i / RATE0; }
11279
return (-RATE0 + Math.sqrt(RATE0 * RATE0 + 2 * ACCEL * i)) / ACCEL;
11280
}
11281
11282
/** Blocks spawned (left the top) by time t, capped at n. */
11283
function spawnedBy (t, n)
11284
{
11285
if (!(t >= 0) || !(n > 0))
11286
{ return 0; }
11287
// Block i has left when T(i) <= t, i.e. i <= N(t).
11288
var k = Math.floor(RATE0 * t + ACCEL * t * t / 2 + 1e-9) + 1;
11289
return Math.min(n, Math.max(0, k));
11290
}
11291
11292
/** Blocks that have arrived in the counter by time t. */
11293
function arrivedBy (t, n, flight)
11294
{
11295
flight = flight == null ? FLIGHT : flight;
11296
return spawnedBy(t - flight, n);
11297
}
11298
11299
/** Total seconds from the first spawn until the last block arrives. */
11300
function countDuration (n, flight)
11301
{
11302
flight = flight == null ? FLIGHT : flight;
11303
if (!(n > 0))
11304
{ return 0; }
11305
return spawnTime(n - 1) + flight;
11306
}
11307
11308
/**
11309
* A pure, dt-driven sequence. Phases: intro → rise → wait → count →
11310
* hold → done. `setResult({ before, after })` supplies the confirmed
11311
* totals (earned = after − before, never negative); `setResult(null)`
11312
* means the server did not confirm, so nothing is counted and the
11313
* title is held briefly. tick(dt) returns
11314
* { phase, counter, spawn: [indices], arrived, done }.
11315
*/
11316
function createSequence (opts)
11317
{
11318
opts = opts || {};
11319
var s = {
11320
phase: 'intro',
11321
t: 0, // time inside the current phase
11322
countT: 0,
11323
won: !!opts.won,
11324
flight: opts.flight == null ? FLIGHT : opts.flight,
11325
intro: opts.intro == null ? INTRO : opts.intro,
11326
rise: opts.rise == null ? RISE : opts.rise,
11327
hold: opts.hold == null ? HOLD : opts.hold,
11328
holdZero: opts.holdZero == null ? HOLD_ZERO : opts.holdZero,
11329
waitMax: opts.waitMax == null ? WAIT_MAX : opts.waitMax,
11330
hasResult: false,
11331
failed: false,
11332
before: 0,
11333
after: 0,
11334
earned: 0,
11335
spawned: 0,
11336
arrived: 0,
11337
counter: 0
11338
};
11339
11340
s.setResult = function (res)
11341
{
11342
if (s.hasResult)
11343
{ return; }
11344
s.hasResult = true;
11345
if (!res || typeof res.after !== 'number' || !isFinite(res.after))
11346
{
11347
s.failed = true;
11348
return;
11349
}
11350
var after = Math.max(0, Math.floor(res.after));
11351
var before = typeof res.before === 'number' && isFinite(res.before)
11352
? Math.max(0, Math.floor(res.before)) : after;
11353
if (before > after)
11354
{ before = after; }
11355
s.before = before;
11356
s.after = after;
11357
s.earned = after - before;
11358
s.counter = before;
11359
};
11360
11361
s.finish = function ()
11362
{
11363
if (s.phase !== 'hold')
11364
{ return false; }
11365
s.phase = 'done';
11366
return true;
11367
};
11368
11369
function enter (phase)
11370
{
11371
s.phase = phase;
11372
s.t = 0;
11373
}
11374
11375
s.tick = function (dt)
11376
{
11377
var out = { phase: s.phase, counter: s.counter, spawn: [], arrived: 0, done: false };
11378
if (s.phase === 'done')
11379
{
11380
out.done = true;
11381
return out;
11382
}
11383
dt = Math.max(0, Number(dt) || 0);
11384
var left = dt;
11385
// Allow several phase changes inside one large dt.
11386
for (var guard = 0; guard < 8 && left >= 0; guard++)
11387
{
11388
if (s.phase === 'intro')
11389
{
11390
if (s.t + left < s.intro)
11391
{ s.t += left; left = -1; break; }
11392
left -= (s.intro - s.t);
11393
enter('rise');
11394
}
11395
else if (s.phase === 'rise')
11396
{
11397
if (s.t + left < s.rise)
11398
{ s.t += left; left = -1; break; }
11399
left -= (s.rise - s.t);
11400
enter('wait');
11401
}
11402
else if (s.phase === 'wait')
11403
{
11404
if (!s.hasResult)
11405
{
11406
s.t += left;
11407
if (s.t >= s.waitMax)
11408
{
11409
s.hasResult = true;
11410
s.failed = true;
11411
enter('hold');
11412
continue;
11413
}
11414
left = -1;
11415
break;
11416
}
11417
if (s.failed || s.earned <= 0)
11418
{ enter('hold'); continue; }
11419
enter('count');
11420
s.countT = 0;
11421
}
11422
else if (s.phase === 'count')
11423
{
11424
s.countT += left;
11425
left = -1;
11426
var sp = spawnedBy(s.countT, s.earned);
11427
for (var i = s.spawned; i < sp; i++)
11428
{ out.spawn.push(i); }
11429
s.spawned = sp;
11430
var ar = arrivedBy(s.countT, s.earned, s.flight);
11431
out.arrived = ar - s.arrived;
11432
s.arrived = ar;
11433
s.counter = s.before + ar;
11434
if (ar >= s.earned)
11435
{
11436
s.counter = s.after;
11437
enter('hold');
11438
}
11439
break;
11440
}
11441
else if (s.phase === 'hold')
11442
{
11443
var need = (s.failed || s.earned <= 0) ? s.holdZero : s.hold;
11444
if (s.t + left < need)
11445
{ s.t += left; left = -1; break; }
11446
enter('done');
11447
break;
11448
}
11449
else
11450
{ break; }
11451
}
11452
out.phase = s.phase;
11453
out.counter = s.counter;
11454
out.done = s.phase === 'done';
11455
return out;
11456
};
11457
11458
return s;
11459
}
11460
11461
/* ---------------- DOM / canvas player (browser only) ---------------- */
11462
11463
var active = null;
11464
11465
function reducedMotion ()
11466
{
11467
try
11468
{
11469
return !!(root.matchMedia && root.matchMedia('(prefers-reduced-motion: reduce)').matches);
11470
}
11471
catch (e) { return false; }
11472
}
11473
11474
function tr (key, fallback)
11475
{
11476
if (typeof I18n !== 'undefined' && I18n.t)
11477
{
11478
var v = I18n.t(key);
11479
if (v && v !== key)
11480
{ return v; }
11481
}
11482
return fallback;
11483
}
11484
11485
function planetImages (planet)
11486
{
11487
var list = [];
11488
var colors = (planet && planet.colors) || [];
11489
for (var i = 0; i < colors.length; i++)
11490
{
11491
if (!colors[i] || !colors[i].image)
11492
{ continue; }
11493
var img = new Image();
11494
img.decoding = 'async';
11495
img.src = colors[i].image;
11496
list.push({ img: img, hex: colors[i].hex || '#ffffff' });
11497
}
11498
if (!list.length)
11499
{ list.push({ img: null, hex: '#ffffff' }); }
11500
return list;
11501
}
11502
11503
/**
11504
* Show the reward overlay. opts: { won, planet, result: Promise<{before,
11505
* after}|null>, onDone }. Returns a handle with .active and .cancel().
11506
*/
11507
function play (opts)
11508
{
11509
opts = opts || {};
11510
if (active)
11511
{ active.cancel(); }
11512
var doc = root.document;
11513
var overlay = doc.getElementById('reward');
11514
var title = doc.getElementById('reward-title');
11515
var counter = doc.getElementById('reward-total');
11516
var label = doc.getElementById('reward-label');
11517
var canvas = doc.getElementById('reward-canvas');
11518
var hint = doc.getElementById('reward-hint');
11519
if (!overlay || !title || !counter || !canvas)
11520
{
11521
if (opts.onDone)
11522
{ opts.onDone(); }
11523
return null;
11524
}
11525
var still = reducedMotion();
11526
var seq = createSequence({ won: opts.won, rise: still ? 0 : RISE });
11527
var imgs = planetImages(opts.planet);
11528
var flying = [];
11529
var last = 0;
11530
var raf = 0;
11531
var pop = 0;
11532
var ctx = canvas.getContext('2d');
11533
var dpr = Math.min(2, root.devicePixelRatio || 1);
11534
var W = 0;
11535
var H = 0;
11536
11537
title.textContent = opts.won ? tr('reward.won', 'You won!') : tr('reward.lost', 'You lost...');
11538
title.className = 'reward-title' + (opts.won ? ' won' : ' lost');
11539
if (label)
11540
{ label.textContent = tr('reward.total', 'Total points'); }
11541
counter.textContent = '';
11542
counter.parentNode.hidden = true;
11543
if (hint)
11544
{ hint.hidden = true; hint.textContent = tr('reward.continue', 'Tap to continue'); }
11545
overlay.classList.toggle('reduced', still);
11546
overlay.hidden = false;
11547
11548
function resize ()
11549
{
11550
W = root.innerWidth || 360;
11551
H = root.innerHeight || 640;
11552
canvas.width = Math.round(W * dpr);
11553
canvas.height = Math.round(H * dpr);
11554
canvas.style.width = W + 'px';
11555
canvas.style.height = H + 'px';
11556
if (ctx)
11557
{ ctx.setTransform(dpr, 0, 0, dpr, 0, 0); }
11558
}
11559
resize();
11560
root.addEventListener('resize', resize);
11561
11562
function target ()
11563
{
11564
var r = counter.getBoundingClientRect();
11565
if (r.width > 0)
11566
{ return { x: r.left + r.width / 2, y: r.top + r.height / 2 }; }
11567
return { x: W / 2, y: H - 80 };
11568
}
11569
11570
function spawn ()
11571
{
11572
var size = Math.max(28, Math.min(56, Math.round(Math.min(W, H) * 0.075)));
11573
var sx = size + Math.random() * Math.max(1, W - 2 * size);
11574
var sy = -size;
11575
var tg = target();
11576
// Random arc: control point pushed sideways and up.
11577
var mx = (sx + tg.x) / 2 + (Math.random() - 0.5) * W * 0.9;
11578
var my = Math.min(sy, tg.y) + (Math.random() * 0.5) * H;
11579
flying.push({
11580
t: 0,
11581
sx: sx, sy: sy, cx: mx, cy: my,
11582
pick: imgs[Math.floor(Math.random() * imgs.length)],
11583
size: size,
11584
rot: (Math.random() - 0.5) * 6
11585
});
11586
}
11587
11588
function draw (dt)
11589
{
11590
if (!ctx)
11591
{ return; }
11592
ctx.clearRect(0, 0, W, H);
11593
var tg = target();
11594
for (var i = flying.length - 1; i >= 0; i--)
11595
{
11596
var f = flying[i];
11597
f.t += dt / FLIGHT;
11598
if (f.t >= 1)
11599
{
11600
flying.splice(i, 1);
11601
continue;
11602
}
11603
var u = f.t;
11604
// Ease in a little so blocks accelerate into the counter.
11605
var e = u * u * (3 - 2 * u) * 0.35 + u * 0.65;
11606
var a = 1 - e;
11607
var x = a * a * f.sx + 2 * a * e * f.cx + e * e * tg.x;
11608
var y = a * a * f.sy + 2 * a * e * f.cy + e * e * tg.y;
11609
var s = f.size * (1 - 0.45 * e);
11610
ctx.save();
11611
ctx.translate(x, y);
11612
ctx.rotate(f.rot * e);
11613
if (f.pick.img && f.pick.img.complete && f.pick.img.naturalWidth)
11614
{ ctx.drawImage(f.pick.img, -s / 2, -s / 2, s, s); }
11615
else
11616
{
11617
ctx.fillStyle = f.pick.hex;
11618
ctx.fillRect(-s / 2, -s / 2, s, s);
11619
}
11620
ctx.restore();
11621
}
11622
}
11623
11624
function setCounter (v)
11625
{
11626
counter.textContent = String(v);
11627
}
11628
11629
var handle = {
11630
active: true,
11631
seq: seq,
11632
flyingCount: function () { return flying.length; },
11633
cancel: function ()
11634
{ cleanup(false); }
11635
};
11636
11637
function onTap (e)
11638
{
11639
if (seq.phase !== 'hold')
11640
{ return; }
11641
if (e && e.type === 'keydown' && e.key !== ' ' && e.key !== 'Enter' && e.key !== 'Spacebar')
11642
{ return; }
11643
if (e && e.preventDefault)
11644
{ e.preventDefault(); }
11645
seq.finish();
11646
}
11647
overlay.addEventListener('pointerup', onTap);
11648
doc.addEventListener('keydown', onTap);
11649
11650
function cleanup (callDone)
11651
{
11652
if (!handle.active)
11653
{ return; }
11654
handle.active = false;
11655
if (raf && root.cancelAnimationFrame)
11656
{ root.cancelAnimationFrame(raf); }
11657
root.removeEventListener('resize', resize);
11658
overlay.removeEventListener('pointerup', onTap);
11659
doc.removeEventListener('keydown', onTap);
11660
overlay.hidden = true;
11661
overlay.classList.remove('risen');
11662
if (ctx)
11663
{ ctx.clearRect(0, 0, W, H); }
11664
if (active === handle)
11665
{ active = null; }
11666
if (callDone && opts.onDone)
11667
{ opts.onDone(); }
11668
}
11669
11670
Promise.resolve(opts.result).then(function (res)
11671
{ seq.setResult(res); }, function ()
11672
{ seq.setResult(null); });
11673
11674
function frame (now)
11675
{
11676
if (!handle.active)
11677
{ return; }
11678
var dt = last ? Math.min(0.1, (now - last) / 1000) : 0;
11679
last = now;
11680
var prev = seq.phase;
11681
var out = seq.tick(dt);
11682
if (prev === 'intro' && out.phase !== 'intro')
11683
{ overlay.classList.add('risen'); }
11684
if ((out.phase === 'count' || out.phase === 'hold' || out.phase === 'done')
11685
&& counter.parentNode.hidden && seq.hasResult && !seq.failed)
11686
{
11687
counter.parentNode.hidden = false;
11688
setCounter(seq.before);
11689
}
11690
if (!still)
11691
{
11692
for (var i = 0; i < out.spawn.length; i++)
11693
{ spawn(); }
11694
}
11695
if (out.arrived > 0)
11696
{
11697
pop = 1;
11698
setCounter(out.counter);
11699
}
11700
if (out.phase === 'hold' && !seq.failed)
11701
{ setCounter(seq.after); }
11702
if (out.phase === 'hold' && hint && hint.hidden)
11703
{ hint.hidden = false; }
11704
if (pop > 0)
11705
{
11706
pop = Math.max(0, pop - dt * 6);
11707
counter.style.transform = 'scale(' + (1 + 0.18 * pop).toFixed(3) + ')';
11708
}
11709
draw(dt);
11710
if (out.done)
11711
{
11712
cleanup(true);
11713
return;
11714
}
11715
raf = root.requestAnimationFrame(frame);
11716
}
11717
raf = root.requestAnimationFrame(frame);
11718
active = handle;
11719
return handle;
11720
}
11721
11722
var Reward = {
11723
RATE0: RATE0,
11724
ACCEL: ACCEL,
11725
INTRO: INTRO,
11726
RISE: RISE,
11727
FLIGHT: FLIGHT,
11728
HOLD: HOLD,
11729
HOLD_ZERO: HOLD_ZERO,
11730
WAIT_MAX: WAIT_MAX,
11731
spawnTime: spawnTime,
11732
spawnedBy: spawnedBy,
11733
arrivedBy: arrivedBy,
11734
countDuration: countDuration,
11735
createSequence: createSequence,
11736
play: play,
11737
isActive: function () { return !!(active && active.active); },
11738
/** Read-only snapshot for tests and debugging. */
11739
debugState: function ()
11740
{
11741
if (!active)
11742
{ return null; }
11743
var q = active.seq;
11744
return {
11745
phase: q.phase, counter: q.counter, before: q.before, after: q.after,
11746
earned: q.earned, spawned: q.spawned, arrived: q.arrived,
11747
failed: q.failed, won: q.won, flying: active.flyingCount()
11748
};
11749
}
11750
};
11751
11752
if (typeof module !== 'undefined' && module.exports)
11753
{ module.exports = Reward; }
11754
root.Reward = Reward;
11755
})(typeof globalThis !== 'undefined' ? globalThis : this);
11756
11757
/*
11758
* End File:
11759
* /workspace/meteors/src/reward.js
11760
*/
11761
11198
11762
/*
11199
11763
* Start File:
11200
11764
* /workspace/meteors/src/designer.js
@@ -11829,7 +12393,10 @@ var app = {
11829
12393
miniAcc: 0,
11830
12394
offlineResultShown: false,
11831
12395
roundWonDelay: 0,
11832
roundWonHandled: false
12396
roundWonHandled: false,
12397
rewardActive: false,
12398
onlineBefore: 0,
12399
pendingLobbyReturn: null
11833
12400
};
11834
12401
11835
12402
window.onload = function ()
@@ -12641,13 +13208,15 @@ function tickView (dt)
12641
13208
{ onOnlineEliminated(); }
12642
13209
else if (app.offline)
12643
13210
{ /* Offline result is shown from tickOffline. */ }
13211
else if (rewardEnabled())
13212
{ showReward(false, finishPlaySession(app.lastScore), returnToMenu); }
12644
13213
else
12645
13214
{
12646
13215
showEl('game-over');
12647
13216
finishPlaySession(app.lastScore);
12648
13217
}
12649
13218
}
12650
if (!app.online && !app.offline && app.core.state === 'gameover'
13219
if (!app.online && !app.offline && !app.rewardActive && app.core.state === 'gameover'
12651
13220
&& app.core.gameOverTime >= GAME_OVER_DELAY)
12652
13221
{ returnToMenu(); }
12653
13222
}
@@ -13201,6 +13770,13 @@ function tickOffline (dt)
13201
13770
{
13202
13771
app.roundWonHandled = true;
13203
13772
app.roundWonDelay = Offline.ROUND_WON_DELAY || 1.5;
13773
if (rewardEnabled())
13774
{ showReward(true, finishPlaySession(app.core.score), startNextOfflineRound); }
13775
}
13776
if (app.rewardActive)
13777
{
13778
updateOfflineMinis(dt, true);
13779
return;
13204
13780
}
13205
13781
app.roundWonDelay -= dt;
13206
13782
if (app.roundWonDelay <= 0)
@@ -13242,7 +13818,17 @@ function tickOffline (dt)
13242
13818
updateOfflineMinis(dt, false);
13243
13819
13244
13820
if (app.battle.state === 'lost' && !app.offlineResultShown)
13245
{ showOfflineResult(); }
13821
{
13822
if (rewardEnabled())
13823
{
13824
// Guard against starting the reward twice; showOfflineResult
13825
// sets the flag again when it runs afterwards.
13826
app.offlineResultShown = true;
13827
showReward(false, finishPlaySession(app.core ? app.core.score : 0), showOfflineResult);
13828
}
13829
else
13830
{ showOfflineResult(); }
13831
}
13246
13832
}
13247
13833
13248
13834
function startNextOfflineRound ()
@@ -13593,6 +14179,8 @@ function onOnlineEliminated ()
13593
14179
app.spectating = true;
13594
14180
unbindPointer();
13595
14181
hideEl('game-over');
14182
if (app.rewardActive)
14183
{ return; }
13596
14184
var lobby = typeof Online !== 'undefined' && Online.lobby;
13597
14185
if (lobby && lobby.status === 'finished')
13598
14186
{
@@ -13648,6 +14236,8 @@ function startOnlineMatch ()
13648
14236
if (typeof me.planet.miss_chance === 'number')
13649
14237
{ miss = me.planet.miss_chance; }
13650
14238
}
14239
app.onlineBefore = (typeof Online !== 'undefined' && Online.lifetimePoints) || 0;
14240
app.pendingLobbyReturn = null;
13651
14241
startPlay({ online: true, planet: planet, missChance: miss });
13652
14242
if (typeof Online !== 'undefined')
13653
14243
{ Online.startPolling(onlinePayload); }
@@ -13797,9 +14387,32 @@ function bindOnlineUi ()
13797
14387
}
13798
14388
};
13799
14389
Online.onFinished = function (lobby)
13800
{ showPodium(lobby); };
14390
{
14391
if (app.mode === 'playing' && app.online && rewardEnabled() && !app.rewardActive)
14392
{
14393
// Lifetime points in this same poll already include the
14394
// server's online award (maybeAwardOnlineLobby).
14395
var result = { before: app.onlineBefore || 0, after: Online.lifetimePoints || 0 };
14396
showReward(myOnlinePlace(lobby) === 1, Promise.resolve(result), function ()
14397
{
14398
var pending = app.pendingLobbyReturn;
14399
app.pendingLobbyReturn = null;
14400
if (pending || !(Online.lobby && Online.lobby.status === 'finished'))
14401
{ Online.onLobbyReturn(pending || Online.lobby); }
14402
else
14403
{ showPodium(Online.lobby); }
14404
});
14405
return;
14406
}
14407
showPodium(lobby);
14408
};
13801
14409
Online.onLobbyReturn = function (lobby)
13802
14410
{
14411
if (app.rewardActive)
14412
{
14413
app.pendingLobbyReturn = lobby;
14414
return;
14415
}
13803
14416
teardownPlay();
13804
14417
app.online = false;
13805
14418
app.mode = 'online';
@@ -13888,7 +14501,7 @@ function renderOnline ()
13888
14501
if (app.mode === 'playing' && app.online)
13889
14502
{
13890
14503
Online.renderMinis(document.getElementById('minis'));
13891
if (Online.lobby && Online.lobby.status === 'finished')
14504
if (Online.lobby && Online.lobby.status === 'finished' && !app.rewardActive)
13892
14505
{ showPodium(Online.lobby); }
13893
14506
return;
13894
14507
}
@@ -14178,14 +14791,78 @@ function beginPlaySession (mode)
14178
14791
});
14179
14792
}
14180
14793
14794
/**
14795
* Ends the solo/offline play session. Resolves to the server-confirmed
14796
* { before, after } profile totals (t1173), or null when there is no
14797
* logged-in user or the server did not confirm. Without a token (e.g.
14798
* play_begin failed) a logged-in player gets { before = after = current }.
14799
*/
14181
14800
function finishPlaySession (score)
14182
14801
{
14183
14802
var token = app.playToken;
14184
14803
app.playToken = null;
14185
if (!token || typeof Online === 'undefined' || !Online.playFinish)
14186
{ return; }
14187
Online.playFinish(token, score || 0).then(function ()
14188
{ refreshMenuAccount(); });
14804
var hasOnline = typeof Online !== 'undefined';
14805
var current = hasOnline ? (Online.lifetimePoints || 0) : 0;
14806
if (!token || !hasOnline || !Online.playFinish)
14807
{
14808
return Promise.resolve(hasOnline && Online.me ? { before: current, after: current } : null);
14809
}
14810
return Promise.resolve(Online.playFinish(token, score || 0)).then(function (data)
14811
{
14812
refreshMenuAccount();
14813
if (data && data.ok !== false && typeof data.lifetime_points === 'number')
14814
{
14815
var awarded = Math.max(0, Number(data.awarded) || 0);
14816
return { before: data.lifetime_points - awarded, after: data.lifetime_points };
14817
}
14818
return null;
14819
}, function ()
14820
{ return null; });
14821
}
14822
14823
/* ---------- t1173 reward screen (logged in only) ------------------- */
14824
14825
function rewardEnabled ()
14826
{
14827
return typeof Reward !== 'undefined' && typeof Online !== 'undefined' && !!Online.me;
14828
}
14829
14830
/**
14831
* Shows "You won!" / "You lost..." and the points fly-in, then calls
14832
* next() — the same destination the mode used before (menu, next
14833
* offline round, offline result, or the online lobby/podium).
14834
*/
14835
function showReward (won, resultPromise, next)
14836
{
14837
app.rewardActive = true;
14838
hideEl('game-over');
14839
hideEl('spectator');
14840
hideEl('podium');
14841
var handle = Reward.play({
14842
won: won,
14843
planet: app.planet,
14844
result: resultPromise,
14845
onDone: function ()
14846
{
14847
app.rewardActive = false;
14848
if (next)
14849
{ next(); }
14850
}
14851
});
14852
if (!handle)
14853
{ app.rewardActive = false; }
14854
}
14855
14856
function myOnlinePlace (lobby)
14857
{
14858
var me = typeof Online !== 'undefined' ? Online.me : null;
14859
var ranks = (lobby && lobby.rankings) || [];
14860
for (var i = 0; i < ranks.length; i++)
14861
{
14862
if (me && ranks[i].id === me.id)
14863
{ return ranks[i].place; }
14864
}
14865
return null;
14189
14866
}
14190
14867
14191
14868
@@ -1301,7 +1301,11 @@ var I18N_CATALOG = {1301
"block.forge-brass": "Forge brass",1301
"block.forge-brass": "Forge brass",1302
"block.forge-soot": "Forge soot",1302
"block.forge-soot": "Forge soot",1303
"error.webgl": "This game needs WebGL. Please try another browser, or turn on hardware acceleration.",1303
"error.webgl": "This game needs WebGL. Please try another browser, or turn on hardware acceleration.",1304
"error.startFailed": "Could not start the game."1304
"error.startFailed": "Could not start the game.",1305
"reward.won": "You won!",1306
"reward.lost": "You lost...",1307
"reward.total": "Total points",1308
"reward.continue": "Tap to continue"1305
},1309
},1306
"nl": {1310
"nl": {1307
"menu.tagline": "Drie op een rij, en je blokjes krijgen raketmotoren.",1311
"menu.tagline": "Drie op een rij, en je blokjes krijgen raketmotoren.",@@ -1582,7 +1586,11 @@ var I18N_CATALOG = {1582
"block.forge-brass": "Forge-messing",1586
"block.forge-brass": "Forge-messing",1583
"block.forge-soot": "Forge-roet",1587
"block.forge-soot": "Forge-roet",1584
"error.webgl": "Dit spel heeft WebGL nodig. Probeer een andere browser, of zet hardwareversnelling aan.",1588
"error.webgl": "Dit spel heeft WebGL nodig. Probeer een andere browser, of zet hardwareversnelling aan.",1585
"error.startFailed": "Het spel kon niet worden gestart."1589
"error.startFailed": "Het spel kon niet worden gestart.",1590
"reward.won": "Gewonnen!",1591
"reward.lost": "Verloren...",1592
"reward.total": "Totaal punten",1593
"reward.continue": "Tik om verder te gaan"1586
},1594
},1587
"de": {1595
"de": {1588
"menu.tagline": "Drei in einer Reihe — und deine Blöcke bekommen Raketenantrieb.",1596
"menu.tagline": "Drei in einer Reihe — und deine Blöcke bekommen Raketenantrieb.",@@ -1863,7 +1871,11 @@ var I18N_CATALOG = {1863
"block.forge-brass": "Forge-Messing",1871
"block.forge-brass": "Forge-Messing",1864
"block.forge-soot": "Forge-Ruß",1872
"block.forge-soot": "Forge-Ruß",1865
"error.webgl": "Dieses Spiel benötigt WebGL. Bitte verwende einen anderen Browser oder aktiviere die Hardwarebeschleunigung.",1873
"error.webgl": "Dieses Spiel benötigt WebGL. Bitte verwende einen anderen Browser oder aktiviere die Hardwarebeschleunigung.",1866
"error.startFailed": "Das Spiel konnte nicht gestartet werden."1874
"error.startFailed": "Das Spiel konnte nicht gestartet werden.",1875
"reward.won": "Gewonnen!",1876
"reward.lost": "Verloren...",1877
"reward.total": "Punkte gesamt",1878
"reward.continue": "Tippen zum Fortfahren"1867
},1879
},1868
"fr": {1880
"fr": {1869
"menu.tagline": "Trois d’affilée, et tes blocs s’équipent de propulseurs.",1881
"menu.tagline": "Trois d’affilée, et tes blocs s’équipent de propulseurs.",@@ -2144,7 +2156,11 @@ var I18N_CATALOG = {2144
"block.forge-brass": "Forge laiton",2156
"block.forge-brass": "Forge laiton",2145
"block.forge-soot": "Forge suie",2157
"block.forge-soot": "Forge suie",2146
"error.webgl": "Ce jeu a besoin de WebGL. Essayez un autre navigateur, ou activez l’accélération matérielle.",2158
"error.webgl": "Ce jeu a besoin de WebGL. Essayez un autre navigateur, ou activez l’accélération matérielle.",2147
"error.startFailed": "Impossible de lancer le jeu."2159
"error.startFailed": "Impossible de lancer le jeu.",2160
"reward.won": "Victoire !",2161
"reward.lost": "Perdu...",2162
"reward.total": "Total des points",2163
"reward.continue": "Touchez pour continuer"2148
},2164
},2149
"ja": {2165
"ja": {2150
"menu.tagline": "三つ揃えると、ブロックにロケットが点火します。",2166
"menu.tagline": "三つ揃えると、ブロックにロケットが点火します。",@@ -2425,7 +2441,11 @@ var I18N_CATALOG = {2425
"block.forge-brass": "フォージの真鍮",2441
"block.forge-brass": "フォージの真鍮",2426
"block.forge-soot": "フォージの煤",2442
"block.forge-soot": "フォージの煤",2427
"error.webgl": "このゲームにはWebGLが必要です。別のブラウザを使うか、ハードウェアアクセラレーションを有効にしてください。",2443
"error.webgl": "このゲームにはWebGLが必要です。別のブラウザを使うか、ハードウェアアクセラレーションを有効にしてください。",2428
"error.startFailed": "ゲームを開始できませんでした。"2444
"error.startFailed": "ゲームを開始できませんでした。",2445
"reward.won": "勝利!",2446
"reward.lost": "敗北...",2447
"reward.total": "合計ポイント",2448
"reward.continue": "タップして続ける"2429
},2449
},2430
"zh": {2450
"zh": {2431
"menu.tagline": "三个一排,你的方块就会装上火箭。",2451
"menu.tagline": "三个一排,你的方块就会装上火箭。",@@ -2706,7 +2726,11 @@ var I18N_CATALOG = {2706
"block.forge-brass": "Forge黄铜",2726
"block.forge-brass": "Forge黄铜",2707
"block.forge-soot": "Forge煤烟",2727
"block.forge-soot": "Forge煤烟",2708
"error.webgl": "本游戏需要 WebGL。请尝试其他浏览器,或开启硬件加速。",2728
"error.webgl": "本游戏需要 WebGL。请尝试其他浏览器,或开启硬件加速。",2709
"error.startFailed": "无法开始游戏。"2729
"error.startFailed": "无法开始游戏。",2730
"reward.won": "你赢了!",2731
"reward.lost": "你输了...",2732
"reward.total": "总积分",2733
"reward.continue": "点击继续"2710
},2734
},2711
"ko": {2735
"ko": {2712
"menu.tagline": "세 개를 나란히 맞추면 블록에 로켓이 점화됩니다.",2736
"menu.tagline": "세 개를 나란히 맞추면 블록에 로켓이 점화됩니다.",@@ -2987,7 +3011,11 @@ var I18N_CATALOG = {2987
"block.forge-brass": "Forge 황동",3011
"block.forge-brass": "Forge 황동",2988
"block.forge-soot": "Forge 그을음",3012
"block.forge-soot": "Forge 그을음",2989
"error.webgl": "이 게임은 WebGL이 필요합니다. 다른 브라우저를 사용하거나 하드웨어 가속을 켜 주세요.",3013
"error.webgl": "이 게임은 WebGL이 필요합니다. 다른 브라우저를 사용하거나 하드웨어 가속을 켜 주세요.",2990
"error.startFailed": "게임을 시작할 수 없습니다."3014
"error.startFailed": "게임을 시작할 수 없습니다.",3015
"reward.won": "승리!",3016
"reward.lost": "패배...",3017
"reward.total": "총 포인트",3018
"reward.continue": "탭하여 계속"2991
},3019
},2992
"pl": {3020
"pl": {2993
"menu.tagline": "Trzy w rzędzie, a twoje klocki dostają napęd rakietowy.",3021
"menu.tagline": "Trzy w rzędzie, a twoje klocki dostają napęd rakietowy.",@@ -3268,7 +3296,11 @@ var I18N_CATALOG = {3268
"block.forge-brass": "Forge mosiądz",3296
"block.forge-brass": "Forge mosiądz",3269
"block.forge-soot": "Forge sadza",3297
"block.forge-soot": "Forge sadza",3270
"error.webgl": "Ta gra wymaga WebGL. Spróbuj innej przeglądarki albo włącz akcelerację sprzętową.",3298
"error.webgl": "Ta gra wymaga WebGL. Spróbuj innej przeglądarki albo włącz akcelerację sprzętową.",3271
"error.startFailed": "Nie udało się uruchomić gry."3299
"error.startFailed": "Nie udało się uruchomić gry.",3300
"reward.won": "Wygrana!",3301
"reward.lost": "Przegrana...",3302
"reward.total": "Suma punktów",3303
"reward.continue": "Dotknij, aby kontynuować"3272
},3304
},3273
"ru": {3305
"ru": {3274
"menu.tagline": "Три в ряд — и твои блоки получают ракетные двигатели.",3306
"menu.tagline": "Три в ряд — и твои блоки получают ракетные двигатели.",@@ -3549,7 +3581,11 @@ var I18N_CATALOG = {3549
"block.forge-brass": "Forge (латунь)",3581
"block.forge-brass": "Forge (латунь)",3550
"block.forge-soot": "Forge (сажа)",3582
"block.forge-soot": "Forge (сажа)",3551
"error.webgl": "Этой игре нужен WebGL. Попробуйте другой браузер или включите аппаратное ускорение.",3583
"error.webgl": "Этой игре нужен WebGL. Попробуйте другой браузер или включите аппаратное ускорение.",3552
"error.startFailed": "Не удалось начать игру."3584
"error.startFailed": "Не удалось начать игру.",3585
"reward.won": "Победа!",3586
"reward.lost": "Поражение...",3587
"reward.total": "Всего очков",3588
"reward.continue": "Нажмите, чтобы продолжить"3553
},3589
},3554
"es": {3590
"es": {3555
"menu.tagline": "Tres en raya, y tus bloques ganan motores cohete.",3591
"menu.tagline": "Tres en raya, y tus bloques ganan motores cohete.",@@ -3830,7 +3866,11 @@ var I18N_CATALOG = {3830
"block.forge-brass": "Forge latón",3866
"block.forge-brass": "Forge latón",3831
"block.forge-soot": "Forge hollín",3867
"block.forge-soot": "Forge hollín",3832
"error.webgl": "Este juego necesita WebGL. Prueba con otro navegador o activa la aceleración por hardware.",3868
"error.webgl": "Este juego necesita WebGL. Prueba con otro navegador o activa la aceleración por hardware.",3833
"error.startFailed": "No se pudo iniciar el juego."3869
"error.startFailed": "No se pudo iniciar el juego.",3870
"reward.won": "¡Has ganado!",3871
"reward.lost": "Has perdido...",3872
"reward.total": "Puntos totales",3873
"reward.continue": "Toca para continuar"3834
}3874
}3835
},3875
},3836
"errors": {3876
"errors": {@@ -11195,6 +11235,530 @@ if (typeof module !== 'undefined' && module.exports && typeof Offline !== 'undef11195
* /workspace/meteors/src/offline.js11235
* /workspace/meteors/src/offline.js11196
*/ 11236
*/ 11197
11237
11238
/*11239
* Start File:11240
* /workspace/meteors/src/reward.js11241
*/ 11242
/*11243
* End-of-round reward screen (t1173 / t1174).11244
*11245
* Logged-in only. Sequence: a centred "You won!" / "You lost..." for11246
* INTRO seconds, then it tweens to the top (RISE seconds). Once the11247
* server has confirmed the new profile total, blocks of the player's11248
* planet arc from the top of the screen into a counter at the bottom11249
* centre, one block per newly earned point. Each arrival adds 1.11250
*11251
* Spawn rate accelerates: rate(t) = RATE0 + ACCEL·t blocks/s, so the11252
* number spawned after t seconds is N(t) = RATE0·t + ACCEL·t²/2, and11253
* block i (0-based) leaves at T(i) = the t where N(t) = i.11254
* 253 points → the last block leaves at exactly 18 s.11255
*11256
* The pure timing / sequencing part (Reward.spawnTime, Reward.createSequence)11257
* has no DOM and is unit-tested. Reward.play wires it to an overlay.11258
*/11259
(function (root)11260
{11261
'use strict';11262
11263
var RATE0 = 5; // blocks per second at t = 011264
var ACCEL = 1; // +1 block/s every second11265
var INTRO = 1.0; // centred title before it rises11266
var RISE = 0.6; // title tween to the top11267
var FLIGHT = 0.7; // one block's arc duration11268
var HOLD = 1.5; // final total shown before continuing11269
var HOLD_ZERO = 1.5; // earned 0: show the number briefly11270
var WAIT_MAX = 8; // give up waiting for the server after this11271
11272
/** Seconds after the start of counting when block i (0-based) leaves. */11273
function spawnTime (i)11274
{11275
if (!(i > 0))11276
{ return 0; }11277
if (ACCEL === 0)11278
{ return i / RATE0; }11279
return (-RATE0 + Math.sqrt(RATE0 * RATE0 + 2 * ACCEL * i)) / ACCEL;11280
}11281
11282
/** Blocks spawned (left the top) by time t, capped at n. */11283
function spawnedBy (t, n)11284
{11285
if (!(t >= 0) || !(n > 0))11286
{ return 0; }11287
// Block i has left when T(i) <= t, i.e. i <= N(t).11288
var k = Math.floor(RATE0 * t + ACCEL * t * t / 2 + 1e-9) + 1;11289
return Math.min(n, Math.max(0, k));11290
}11291
11292
/** Blocks that have arrived in the counter by time t. */11293
function arrivedBy (t, n, flight)11294
{11295
flight = flight == null ? FLIGHT : flight;11296
return spawnedBy(t - flight, n);11297
}11298
11299
/** Total seconds from the first spawn until the last block arrives. */11300
function countDuration (n, flight)11301
{11302
flight = flight == null ? FLIGHT : flight;11303
if (!(n > 0))11304
{ return 0; }11305
return spawnTime(n - 1) + flight;11306
}11307
11308
/**11309
* A pure, dt-driven sequence. Phases: intro → rise → wait → count →11310
* hold → done. `setResult({ before, after })` supplies the confirmed11311
* totals (earned = after − before, never negative); `setResult(null)`11312
* means the server did not confirm, so nothing is counted and the11313
* title is held briefly. tick(dt) returns11314
* { phase, counter, spawn: [indices], arrived, done }.11315
*/11316
function createSequence (opts)11317
{11318
opts = opts || {};11319
var s = {11320
phase: 'intro',11321
t: 0, // time inside the current phase11322
countT: 0,11323
won: !!opts.won,11324
flight: opts.flight == null ? FLIGHT : opts.flight,11325
intro: opts.intro == null ? INTRO : opts.intro,11326
rise: opts.rise == null ? RISE : opts.rise,11327
hold: opts.hold == null ? HOLD : opts.hold,11328
holdZero: opts.holdZero == null ? HOLD_ZERO : opts.holdZero,11329
waitMax: opts.waitMax == null ? WAIT_MAX : opts.waitMax,11330
hasResult: false,11331
failed: false,11332
before: 0,11333
after: 0,11334
earned: 0,11335
spawned: 0,11336
arrived: 0,11337
counter: 011338
};11339
11340
s.setResult = function (res)11341
{11342
if (s.hasResult)11343
{ return; }11344
s.hasResult = true;11345
if (!res || typeof res.after !== 'number' || !isFinite(res.after))11346
{11347
s.failed = true;11348
return;11349
}11350
var after = Math.max(0, Math.floor(res.after));11351
var before = typeof res.before === 'number' && isFinite(res.before)11352
? Math.max(0, Math.floor(res.before)) : after;11353
if (before > after)11354
{ before = after; }11355
s.before = before;11356
s.after = after;11357
s.earned = after - before;11358
s.counter = before;11359
};11360
11361
s.finish = function ()11362
{11363
if (s.phase !== 'hold')11364
{ return false; }11365
s.phase = 'done';11366
return true;11367
};11368
11369
function enter (phase)11370
{11371
s.phase = phase;11372
s.t = 0;11373
}11374
11375
s.tick = function (dt)11376
{11377
var out = { phase: s.phase, counter: s.counter, spawn: [], arrived: 0, done: false };11378
if (s.phase === 'done')11379
{11380
out.done = true;11381
return out;11382
}11383
dt = Math.max(0, Number(dt) || 0);11384
var left = dt;11385
// Allow several phase changes inside one large dt.11386
for (var guard = 0; guard < 8 && left >= 0; guard++)11387
{11388
if (s.phase === 'intro')11389
{11390
if (s.t + left < s.intro)11391
{ s.t += left; left = -1; break; }11392
left -= (s.intro - s.t);11393
enter('rise');11394
}11395
else if (s.phase === 'rise')11396
{11397
if (s.t + left < s.rise)11398
{ s.t += left; left = -1; break; }11399
left -= (s.rise - s.t);11400
enter('wait');11401
}11402
else if (s.phase === 'wait')11403
{11404
if (!s.hasResult)11405
{11406
s.t += left;11407
if (s.t >= s.waitMax)11408
{11409
s.hasResult = true;11410
s.failed = true;11411
enter('hold');11412
continue;11413
}11414
left = -1;11415
break;11416
}11417
if (s.failed || s.earned <= 0)11418
{ enter('hold'); continue; }11419
enter('count');11420
s.countT = 0;11421
}11422
else if (s.phase === 'count')11423
{11424
s.countT += left;11425
left = -1;11426
var sp = spawnedBy(s.countT, s.earned);11427
for (var i = s.spawned; i < sp; i++)11428
{ out.spawn.push(i); }11429
s.spawned = sp;11430
var ar = arrivedBy(s.countT, s.earned, s.flight);11431
out.arrived = ar - s.arrived;11432
s.arrived = ar;11433
s.counter = s.before + ar;11434
if (ar >= s.earned)11435
{11436
s.counter = s.after;11437
enter('hold');11438
}11439
break;11440
}11441
else if (s.phase === 'hold')11442
{11443
var need = (s.failed || s.earned <= 0) ? s.holdZero : s.hold;11444
if (s.t + left < need)11445
{ s.t += left; left = -1; break; }11446
enter('done');11447
break;11448
}11449
else11450
{ break; }11451
}11452
out.phase = s.phase;11453
out.counter = s.counter;11454
out.done = s.phase === 'done';11455
return out;11456
};11457
11458
return s;11459
}11460
11461
/* ---------------- DOM / canvas player (browser only) ---------------- */11462
11463
var active = null;11464
11465
function reducedMotion ()11466
{11467
try11468
{11469
return !!(root.matchMedia && root.matchMedia('(prefers-reduced-motion: reduce)').matches);11470
}11471
catch (e) { return false; }11472
}11473
11474
function tr (key, fallback)11475
{11476
if (typeof I18n !== 'undefined' && I18n.t)11477
{11478
var v = I18n.t(key);11479
if (v && v !== key)11480
{ return v; }11481
}11482
return fallback;11483
}11484
11485
function planetImages (planet)11486
{11487
var list = [];11488
var colors = (planet && planet.colors) || [];11489
for (var i = 0; i < colors.length; i++)11490
{11491
if (!colors[i] || !colors[i].image)11492
{ continue; }11493
var img = new Image();11494
img.decoding = 'async';11495
img.src = colors[i].image;11496
list.push({ img: img, hex: colors[i].hex || '#ffffff' });11497
}11498
if (!list.length)11499
{ list.push({ img: null, hex: '#ffffff' }); }11500
return list;11501
}11502
11503
/**11504
* Show the reward overlay. opts: { won, planet, result: Promise<{before,11505
* after}|null>, onDone }. Returns a handle with .active and .cancel().11506
*/11507
function play (opts)11508
{11509
opts = opts || {};11510
if (active)11511
{ active.cancel(); }11512
var doc = root.document;11513
var overlay = doc.getElementById('reward');11514
var title = doc.getElementById('reward-title');11515
var counter = doc.getElementById('reward-total');11516
var label = doc.getElementById('reward-label');11517
var canvas = doc.getElementById('reward-canvas');11518
var hint = doc.getElementById('reward-hint');11519
if (!overlay || !title || !counter || !canvas)11520
{11521
if (opts.onDone)11522
{ opts.onDone(); }11523
return null;11524
}11525
var still = reducedMotion();11526
var seq = createSequence({ won: opts.won, rise: still ? 0 : RISE });11527
var imgs = planetImages(opts.planet);11528
var flying = [];11529
var last = 0;11530
var raf = 0;11531
var pop = 0;11532
var ctx = canvas.getContext('2d');11533
var dpr = Math.min(2, root.devicePixelRatio || 1);11534
var W = 0;11535
var H = 0;11536
11537
title.textContent = opts.won ? tr('reward.won', 'You won!') : tr('reward.lost', 'You lost...');11538
title.className = 'reward-title' + (opts.won ? ' won' : ' lost');11539
if (label)11540
{ label.textContent = tr('reward.total', 'Total points'); }11541
counter.textContent = '';11542
counter.parentNode.hidden = true;11543
if (hint)11544
{ hint.hidden = true; hint.textContent = tr('reward.continue', 'Tap to continue'); }11545
overlay.classList.toggle('reduced', still);11546
overlay.hidden = false;11547
11548
function resize ()11549
{11550
W = root.innerWidth || 360;11551
H = root.innerHeight || 640;11552
canvas.width = Math.round(W * dpr);11553
canvas.height = Math.round(H * dpr);11554
canvas.style.width = W + 'px';11555
canvas.style.height = H + 'px';11556
if (ctx)11557
{ ctx.setTransform(dpr, 0, 0, dpr, 0, 0); }11558
}11559
resize();11560
root.addEventListener('resize', resize);11561
11562
function target ()11563
{11564
var r = counter.getBoundingClientRect();11565
if (r.width > 0)11566
{ return { x: r.left + r.width / 2, y: r.top + r.height / 2 }; }11567
return { x: W / 2, y: H - 80 };11568
}11569
11570
function spawn ()11571
{11572
var size = Math.max(28, Math.min(56, Math.round(Math.min(W, H) * 0.075)));11573
var sx = size + Math.random() * Math.max(1, W - 2 * size);11574
var sy = -size;11575
var tg = target();11576
// Random arc: control point pushed sideways and up.11577
var mx = (sx + tg.x) / 2 + (Math.random() - 0.5) * W * 0.9;11578
var my = Math.min(sy, tg.y) + (Math.random() * 0.5) * H;11579
flying.push({11580
t: 0,11581
sx: sx, sy: sy, cx: mx, cy: my,11582
pick: imgs[Math.floor(Math.random() * imgs.length)],11583
size: size,11584
rot: (Math.random() - 0.5) * 611585
});11586
}11587
11588
function draw (dt)11589
{11590
if (!ctx)11591
{ return; }11592
ctx.clearRect(0, 0, W, H);11593
var tg = target();11594
for (var i = flying.length - 1; i >= 0; i--)11595
{11596
var f = flying[i];11597
f.t += dt / FLIGHT;11598
if (f.t >= 1)11599
{11600
flying.splice(i, 1);11601
continue;11602
}11603
var u = f.t;11604
// Ease in a little so blocks accelerate into the counter.11605
var e = u * u * (3 - 2 * u) * 0.35 + u * 0.65;11606
var a = 1 - e;11607
var x = a * a * f.sx + 2 * a * e * f.cx + e * e * tg.x;11608
var y = a * a * f.sy + 2 * a * e * f.cy + e * e * tg.y;11609
var s = f.size * (1 - 0.45 * e);11610
ctx.save();11611
ctx.translate(x, y);11612
ctx.rotate(f.rot * e);11613
if (f.pick.img && f.pick.img.complete && f.pick.img.naturalWidth)11614
{ ctx.drawImage(f.pick.img, -s / 2, -s / 2, s, s); }11615
else11616
{11617
ctx.fillStyle = f.pick.hex;11618
ctx.fillRect(-s / 2, -s / 2, s, s);11619
}11620
ctx.restore();11621
}11622
}11623
11624
function setCounter (v)11625
{11626
counter.textContent = String(v);11627
}11628
11629
var handle = {11630
active: true,11631
seq: seq,11632
flyingCount: function () { return flying.length; },11633
cancel: function ()11634
{ cleanup(false); }11635
};11636
11637
function onTap (e)11638
{11639
if (seq.phase !== 'hold')11640
{ return; }11641
if (e && e.type === 'keydown' && e.key !== ' ' && e.key !== 'Enter' && e.key !== 'Spacebar')11642
{ return; }11643
if (e && e.preventDefault)11644
{ e.preventDefault(); }11645
seq.finish();11646
}11647
overlay.addEventListener('pointerup', onTap);11648
doc.addEventListener('keydown', onTap);11649
11650
function cleanup (callDone)11651
{11652
if (!handle.active)11653
{ return; }11654
handle.active = false;11655
if (raf && root.cancelAnimationFrame)11656
{ root.cancelAnimationFrame(raf); }11657
root.removeEventListener('resize', resize);11658
overlay.removeEventListener('pointerup', onTap);11659
doc.removeEventListener('keydown', onTap);11660
overlay.hidden = true;11661
overlay.classList.remove('risen');11662
if (ctx)11663
{ ctx.clearRect(0, 0, W, H); }11664
if (active === handle)11665
{ active = null; }11666
if (callDone && opts.onDone)11667
{ opts.onDone(); }11668
}11669
11670
Promise.resolve(opts.result).then(function (res)11671
{ seq.setResult(res); }, function ()11672
{ seq.setResult(null); });11673
11674
function frame (now)11675
{11676
if (!handle.active)11677
{ return; }11678
var dt = last ? Math.min(0.1, (now - last) / 1000) : 0;11679
last = now;11680
var prev = seq.phase;11681
var out = seq.tick(dt);11682
if (prev === 'intro' && out.phase !== 'intro')11683
{ overlay.classList.add('risen'); }11684
if ((out.phase === 'count' || out.phase === 'hold' || out.phase === 'done')11685
&& counter.parentNode.hidden && seq.hasResult && !seq.failed)11686
{11687
counter.parentNode.hidden = false;11688
setCounter(seq.before);11689
}11690
if (!still)11691
{11692
for (var i = 0; i < out.spawn.length; i++)11693
{ spawn(); }11694
}11695
if (out.arrived > 0)11696
{11697
pop = 1;11698
setCounter(out.counter);11699
}11700
if (out.phase === 'hold' && !seq.failed)11701
{ setCounter(seq.after); }11702
if (out.phase === 'hold' && hint && hint.hidden)11703
{ hint.hidden = false; }11704
if (pop > 0)11705
{11706
pop = Math.max(0, pop - dt * 6);11707
counter.style.transform = 'scale(' + (1 + 0.18 * pop).toFixed(3) + ')';11708
}11709
draw(dt);11710
if (out.done)11711
{11712
cleanup(true);11713
return;11714
}11715
raf = root.requestAnimationFrame(frame);11716
}11717
raf = root.requestAnimationFrame(frame);11718
active = handle;11719
return handle;11720
}11721
11722
var Reward = {11723
RATE0: RATE0,11724
ACCEL: ACCEL,11725
INTRO: INTRO,11726
RISE: RISE,11727
FLIGHT: FLIGHT,11728
HOLD: HOLD,11729
HOLD_ZERO: HOLD_ZERO,11730
WAIT_MAX: WAIT_MAX,11731
spawnTime: spawnTime,11732
spawnedBy: spawnedBy,11733
arrivedBy: arrivedBy,11734
countDuration: countDuration,11735
createSequence: createSequence,11736
play: play,11737
isActive: function () { return !!(active && active.active); },11738
/** Read-only snapshot for tests and debugging. */11739
debugState: function ()11740
{11741
if (!active)11742
{ return null; }11743
var q = active.seq;11744
return {11745
phase: q.phase, counter: q.counter, before: q.before, after: q.after,11746
earned: q.earned, spawned: q.spawned, arrived: q.arrived,11747
failed: q.failed, won: q.won, flying: active.flyingCount()11748
};11749
}11750
};11751
11752
if (typeof module !== 'undefined' && module.exports)11753
{ module.exports = Reward; }11754
root.Reward = Reward;11755
})(typeof globalThis !== 'undefined' ? globalThis : this);11756
11757
/*11758
* End File:11759
* /workspace/meteors/src/reward.js11760
*/ 11761
11198
/*11762
/*11199
* Start File:11763
* Start File:11200
* /workspace/meteors/src/designer.js11764
* /workspace/meteors/src/designer.js@@ -11829,7 +12393,10 @@ var app = {11829
miniAcc: 0,12393
miniAcc: 0,11830
offlineResultShown: false,12394
offlineResultShown: false,11831
roundWonDelay: 0,12395
roundWonDelay: 0,11832
roundWonHandled: false12396
roundWonHandled: false,12397
rewardActive: false,12398
onlineBefore: 0,12399
pendingLobbyReturn: null11833
};12400
};11834
12401
11835
window.onload = function ()12402
window.onload = function ()@@ -12641,13 +13208,15 @@ function tickView (dt)12641
{ onOnlineEliminated(); }13208
{ onOnlineEliminated(); }12642
else if (app.offline)13209
else if (app.offline)12643
{ /* Offline result is shown from tickOffline. */ }13210
{ /* Offline result is shown from tickOffline. */ }13211
else if (rewardEnabled())13212
{ showReward(false, finishPlaySession(app.lastScore), returnToMenu); }12644
else13213
else12645
{13214
{12646
showEl('game-over');13215
showEl('game-over');12647
finishPlaySession(app.lastScore);13216
finishPlaySession(app.lastScore);12648
}13217
}12649
}13218
}12650
if (!app.online && !app.offline && app.core.state === 'gameover'13219
if (!app.online && !app.offline && !app.rewardActive && app.core.state === 'gameover'12651
&& app.core.gameOverTime >= GAME_OVER_DELAY)13220
&& app.core.gameOverTime >= GAME_OVER_DELAY)12652
{ returnToMenu(); }13221
{ returnToMenu(); }12653
}13222
}@@ -13201,6 +13770,13 @@ function tickOffline (dt)13201
{13770
{13202
app.roundWonHandled = true;13771
app.roundWonHandled = true;13203
app.roundWonDelay = Offline.ROUND_WON_DELAY || 1.5;13772
app.roundWonDelay = Offline.ROUND_WON_DELAY || 1.5;13773
if (rewardEnabled())13774
{ showReward(true, finishPlaySession(app.core.score), startNextOfflineRound); }13775
}13776
if (app.rewardActive)13777
{13778
updateOfflineMinis(dt, true);13779
return;13204
}13780
}13205
app.roundWonDelay -= dt;13781
app.roundWonDelay -= dt;13206
if (app.roundWonDelay <= 0)13782
if (app.roundWonDelay <= 0)@@ -13242,7 +13818,17 @@ function tickOffline (dt)13242
updateOfflineMinis(dt, false);13818
updateOfflineMinis(dt, false);13243
13819
13244
if (app.battle.state === 'lost' && !app.offlineResultShown)13820
if (app.battle.state === 'lost' && !app.offlineResultShown)13245
{ showOfflineResult(); }13821
{13822
if (rewardEnabled())13823
{13824
// Guard against starting the reward twice; showOfflineResult13825
// sets the flag again when it runs afterwards.13826
app.offlineResultShown = true;13827
showReward(false, finishPlaySession(app.core ? app.core.score : 0), showOfflineResult);13828
}13829
else13830
{ showOfflineResult(); }13831
}13246
}13832
}13247
13833
13248
function startNextOfflineRound ()13834
function startNextOfflineRound ()@@ -13593,6 +14179,8 @@ function onOnlineEliminated ()13593
app.spectating = true;14179
app.spectating = true;13594
unbindPointer();14180
unbindPointer();13595
hideEl('game-over');14181
hideEl('game-over');14182
if (app.rewardActive)14183
{ return; }13596
var lobby = typeof Online !== 'undefined' && Online.lobby;14184
var lobby = typeof Online !== 'undefined' && Online.lobby;13597
if (lobby && lobby.status === 'finished')14185
if (lobby && lobby.status === 'finished')13598
{14186
{@@ -13648,6 +14236,8 @@ function startOnlineMatch ()13648
if (typeof me.planet.miss_chance === 'number')14236
if (typeof me.planet.miss_chance === 'number')13649
{ miss = me.planet.miss_chance; }14237
{ miss = me.planet.miss_chance; }13650
}14238
}14239
app.onlineBefore = (typeof Online !== 'undefined' && Online.lifetimePoints) || 0;14240
app.pendingLobbyReturn = null;13651
startPlay({ online: true, planet: planet, missChance: miss });14241
startPlay({ online: true, planet: planet, missChance: miss });13652
if (typeof Online !== 'undefined')14242
if (typeof Online !== 'undefined')13653
{ Online.startPolling(onlinePayload); }14243
{ Online.startPolling(onlinePayload); }@@ -13797,9 +14387,32 @@ function bindOnlineUi ()13797
}14387
}13798
};14388
};13799
Online.onFinished = function (lobby)14389
Online.onFinished = function (lobby)13800
{ showPodium(lobby); };14390
{14391
if (app.mode === 'playing' && app.online && rewardEnabled() && !app.rewardActive)14392
{14393
// Lifetime points in this same poll already include the14394
// server's online award (maybeAwardOnlineLobby).14395
var result = { before: app.onlineBefore || 0, after: Online.lifetimePoints || 0 };14396
showReward(myOnlinePlace(lobby) === 1, Promise.resolve(result), function ()14397
{14398
var pending = app.pendingLobbyReturn;14399
app.pendingLobbyReturn = null;14400
if (pending || !(Online.lobby && Online.lobby.status === 'finished'))14401
{ Online.onLobbyReturn(pending || Online.lobby); }14402
else14403
{ showPodium(Online.lobby); }14404
});14405
return;14406
}14407
showPodium(lobby);14408
};13801
Online.onLobbyReturn = function (lobby)14409
Online.onLobbyReturn = function (lobby)13802
{14410
{14411
if (app.rewardActive)14412
{14413
app.pendingLobbyReturn = lobby;14414
return;14415
}13803
teardownPlay();14416
teardownPlay();13804
app.online = false;14417
app.online = false;13805
app.mode = 'online';14418
app.mode = 'online';@@ -13888,7 +14501,7 @@ function renderOnline ()13888
if (app.mode === 'playing' && app.online)14501
if (app.mode === 'playing' && app.online)13889
{14502
{13890
Online.renderMinis(document.getElementById('minis'));14503
Online.renderMinis(document.getElementById('minis'));13891
if (Online.lobby && Online.lobby.status === 'finished')14504
if (Online.lobby && Online.lobby.status === 'finished' && !app.rewardActive)13892
{ showPodium(Online.lobby); }14505
{ showPodium(Online.lobby); }13893
return;14506
return;13894
}14507
}@@ -14178,14 +14791,78 @@ function beginPlaySession (mode)14178
});14791
});14179
}14792
}14180
14793
14794
/**14795
* Ends the solo/offline play session. Resolves to the server-confirmed14796
* { before, after } profile totals (t1173), or null when there is no14797
* logged-in user or the server did not confirm. Without a token (e.g.14798
* play_begin failed) a logged-in player gets { before = after = current }.14799
*/14181
function finishPlaySession (score)14800
function finishPlaySession (score)14182
{14801
{14183
var token = app.playToken;14802
var token = app.playToken;14184
app.playToken = null;14803
app.playToken = null;14185
if (!token || typeof Online === 'undefined' || !Online.playFinish)14804
var hasOnline = typeof Online !== 'undefined';14186
{ return; }14805
var current = hasOnline ? (Online.lifetimePoints || 0) : 0;14187
Online.playFinish(token, score || 0).then(function ()14806
if (!token || !hasOnline || !Online.playFinish)14188
{ refreshMenuAccount(); });14807
{14808
return Promise.resolve(hasOnline && Online.me ? { before: current, after: current } : null);14809
}14810
return Promise.resolve(Online.playFinish(token, score || 0)).then(function (data)14811
{14812
refreshMenuAccount();14813
if (data && data.ok !== false && typeof data.lifetime_points === 'number')14814
{14815
var awarded = Math.max(0, Number(data.awarded) || 0);14816
return { before: data.lifetime_points - awarded, after: data.lifetime_points };14817
}14818
return null;14819
}, function ()14820
{ return null; });14821
}14822
14823
/* ---------- t1173 reward screen (logged in only) ------------------- */14824
14825
function rewardEnabled ()14826
{14827
return typeof Reward !== 'undefined' && typeof Online !== 'undefined' && !!Online.me;14828
}14829
14830
/**14831
* Shows "You won!" / "You lost..." and the points fly-in, then calls14832
* next() — the same destination the mode used before (menu, next14833
* offline round, offline result, or the online lobby/podium).14834
*/14835
function showReward (won, resultPromise, next)14836
{14837
app.rewardActive = true;14838
hideEl('game-over');14839
hideEl('spectator');14840
hideEl('podium');14841
var handle = Reward.play({14842
won: won,14843
planet: app.planet,14844
result: resultPromise,14845
onDone: function ()14846
{14847
app.rewardActive = false;14848
if (next)14849
{ next(); }14850
}14851
});14852
if (!handle)14853
{ app.rewardActive = false; }14854
}14855
14856
function myOnlinePlace (lobby)14857
{14858
var me = typeof Online !== 'undefined' ? Online.me : null;14859
var ranks = (lobby && lobby.rankings) || [];14860
for (var i = 0; i < ranks.length; i++)14861
{14862
if (me && ranks[i].id === me.id)14863
{ return ranks[i].place; }14864
}14865
return null;14189
}14866
}14190
14867
14191
14868