The toss travels: the receiver watches the serve coming
One event on the toss, replayed as a real toss over O — update() already poses the server off the phase and drops an uncaught ball back to pretoss by plain physics, so the wind-up, the cancel and the re-toss all carry for free. The strike's shot event overwrites whatever drifted. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f302354bb2
commit
8face714a6
4 files changed
+36
-4
No files matched your search
+12
-1
@@ -19,7 +19,7 @@
|
||||
// plan calls reconnection "the bulk of the real work" and a prototype must not start there.
|
||||
import { COURT, UI } from './config.js';
|
||||
import { G, P, O, ball, score, setupPoint } from './state.js';
|
||||
import { pointTo, fault, showModal } from './gameplay.js';
|
||||
import { pointTo, fault, showModal, tossBall } from './gameplay.js';
|
||||
|
||||
let ws = null, hb = 0, posT = 0;
|
||||
let applying = false; // a remote verdict being applied must not echo back out
|
||||
@@ -39,6 +39,16 @@ function send(m) {
|
||||
export const netJudging = () => !!(G.net && G.net.ready) && !applying;
|
||||
export const netSendPoint = (side, reason) => send({ t: 'pt', win: side === 'P' ? 'me' : 'you', reason: reason || null });
|
||||
export const netSendFault = () => send({ t: 'fault' });
|
||||
export const netSendToss = () => { if (G.net && G.net.ready) send({ t: 'toss' }); };
|
||||
|
||||
// their toss: replay it as a REAL toss over O, so the receiver watches the serve coming. Everything
|
||||
// downstream is machinery that already exists — update() poses the server off phase 'toss', the
|
||||
// uncaught-toss reset drops a cancelled one back to pretoss on both phones by plain physics, and
|
||||
// the strike's shot event overwrites the ball wherever the two sims had drifted to.
|
||||
function netApplyToss() {
|
||||
if (score.server !== 'O' || G.phase === 'rally') return; // a stray toss must not touch a live rally
|
||||
tossBall(O);
|
||||
}
|
||||
|
||||
// called by gameplay the moment a local strike has finished writing the ball — the ball IS the message
|
||||
export function netSendShot() {
|
||||
@@ -106,6 +116,7 @@ export function netMsg(m) {
|
||||
else if (m.t === 'start') netStart(m.side);
|
||||
else if (m.t === 'gone') netDead('NO SUCH ROOM — RELOAD AND HOST ONE');
|
||||
else if (m.t === 'bye') netDead('YOUR OPPONENT LEFT — RELOAD TO PLAY AGAIN');
|
||||
else if (m.t === 'toss') netApplyToss();
|
||||
else if (m.t === 'shot') netApplyShot(m);
|
||||
else if (m.t === 'pt') netApplyPoint(m);
|
||||
else if (m.t === 'fault') netApplyFault();
|
||||
|
||||
Reference in new issue
Block a user