Give the friend's racket a sound and the duel a rematch
Two netplay-only finds from Oliver's two-phone session. THE FRIEND'S STRIKE was silent: every other opponent is simulated locally and cracks through gameplay's shared return path, but the friend's swing runs on their phone alone and arrives as a 'shot' message that wrote the ball and nothing else. netApplyShot now plays the same sample at the same volume, pitched off the pace that was actually sent (strikeRate, read after the ball is written). Both netplay modes, not just the death match. THE REMATCH: the summary's only netplay door was THE CLUBHOUSE, so playing the same friend again meant two trips through the lobby and a fresh code. The relay cannot re-pair, so the rematch is the socket that is still open — one 'again' frame and both phones reset the run under the decisions the room already carries (same side, same mode, same court, host serves). netAgain keeps G.net across restartRun(true) and replays netFresh, netStart's own tail split out so pairing and rematch cannot drift into two courts. Applied, never echoed; a 2 s window swallows the second frame when both tap at once; a dead line refuses and falls through to the clubhouse. Also: the dev server runs with SPLAT_AUTH= (server.py always said local dev should), which the shared password had been 401-ing. audio.sfxTest is a new test seam in netTest's shape. 146 tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b53fc07dd1
commit
78946015b4
9 files changed
+189
-17
No files matched your search
@@ -122,7 +122,9 @@ export function voiceSeq(names, gap = 0.12) {
|
||||
// Recorded one-shot SFX (assets/audio/tennis-*.wav): ball hits, applause, the crowd's aww.
|
||||
// Same load-once-then-cache pattern as voice(), but dry (no PA reverb) and with a volume knob.
|
||||
const SFX = {};
|
||||
export const sfxTest = { log: null }; // test seam: an array here catches the names played (netTest's pattern)
|
||||
export function sfx(name, vol = 1, opts = {}) {
|
||||
if (sfxTest.log) sfxTest.log.push(name);
|
||||
const ac = audio();
|
||||
const play = buf => {
|
||||
const src = ac.createBufferSource(); src.buffer = buf;
|
||||
|
||||
+5
-3
@@ -22,7 +22,7 @@ import { netSendShot, netSendToss, netTick, netJudging, netSendPoint, netSendFau
|
||||
// dink at 0.93, a 52 m/s serve at 1.09. Deliberately narrow: past about a tenth either way the
|
||||
// sample stops sounding like the same racket. Read off the LIVE ball, so it is one call site's
|
||||
// worth of code for every strike in the game.
|
||||
const strikeRate = () => 0.93 + Math.max(0, Math.min(0.16, (Math.hypot(ball.vx, ball.vz) - 20) / 200));
|
||||
export const strikeRate = () => 0.93 + Math.max(0, Math.min(0.16, (Math.hypot(ball.vx, ball.vz) - 20) / 200));
|
||||
// ...and a fast ball KICKS THE CAMERA as it leaves. The third answer to the same report: the trail
|
||||
// says how fast the ball is, the crack says how hard it was hit, and this says it in the one channel
|
||||
// the striker cannot miss, because it moves the whole picture rather than something inside it.
|
||||
@@ -1031,9 +1031,11 @@ const xLimit = () => Math.max(xVisible(), COURT.W / 2);
|
||||
// is supposed to pick up the track that was already playing over the death summary. Every mutable
|
||||
// bag has a pristine copy (state.resetState) and the two modules with timers of their own put them
|
||||
// back themselves, so nothing here has to know the shape of any of it.
|
||||
export function restartRun() {
|
||||
export function restartRun(keepNet = false) {
|
||||
recordEvent('run_end', { outcome: G.done?.won ? 'won' : G.mode === 'eaten' ? 'lost' : 'abandoned' });
|
||||
netClose(); // netplay: resetState wipes G.net below; the socket must not outlive the run it carried
|
||||
// netplay: resetState wipes G.net below; the socket must not outlive the run it carried — unless
|
||||
// the REMATCH is what asked for the reset, in which case the same pairing carries the next one
|
||||
if (!keepNet) netClose();
|
||||
resetZombies(); resetInput(); resetState(); setupPoint();
|
||||
beginRun(); // ...and the stats bag, which is the only state that does not live on G
|
||||
beginRunXp(); // ...and the profile's run delta, same rule (the xp itself is already banked)
|
||||
|
||||
+5
-1
@@ -7,7 +7,7 @@ import { TUNE, COURTS, TOURS, KITS, SKINS, MODES, MENU, DIFFS, EATEN_RESTART, DO
|
||||
import { P, O, ball, score, G, setupPoint, sendBoy, selectCourt, selectTour, selectKit, selectSkin } from './state.js';
|
||||
import { update, restartRun, keyPressed, solveShot, inServeBox, inCourt, forceZombies, startGore, splatPoint, deliverTin, selectWeapon, grantWeapon, showModal, dismissModal, flickTarget, dragServe, toggleTestMode } from './gameplay.js';
|
||||
import { startDuel, resolveInterlude, startHorde, startBossFight, endBossFight, startDrill, endDrill, startMatch, endMatch, startBench, endBench, FALL, benchFall, startNetVs, endNetVs } from './beats.js';
|
||||
import { netConnect, netHooks } from './net.js';
|
||||
import { netConnect, netHooks, netAgain } from './net.js';
|
||||
import { fitViewport, render, proj, RES, SPRV, LOAD, SPR, drawLook, endHit } from './render.js';
|
||||
import { voice, ambient, menuMusic, menuDuck } from './audio.js';
|
||||
import { zombies, spawnZombie, spawnRacketZombie, spawnMachine, spawnChapterBoss, piles, gore, parts, pellets, extras, shots, pops, explode, hurtPlayer, killPlayer , spawnBarrel } from './zombies.js';
|
||||
@@ -1019,6 +1019,10 @@ const maybeRestart = e => {
|
||||
const r = cv.getBoundingClientRect();
|
||||
door = endHit((e.clientX - r.left) / r.width, (e.clientY - r.top) / r.height);
|
||||
}
|
||||
// THE REMATCH is the one door that does not end the run here: the socket is still up, so net.js
|
||||
// resets both phones itself and the menu never comes back. It refuses (and falls through to the
|
||||
// clubhouse) if the friend has already hung up.
|
||||
if (door === 'rematch' && netAgain()) return;
|
||||
restartRun();
|
||||
profile.push(); // the run's xp is banked — mirror it while the moment is quiet
|
||||
refreshSplash(); // the run just ended: the splash count has moved
|
||||
|
||||
+49
-2
@@ -19,9 +19,10 @@
|
||||
// plan calls reconnection "the bulk of the real work" and a prototype must not start there.
|
||||
import { COURT, UI, KITS, SKINS, TOURS, NATIVE, HOST } from './config.js';
|
||||
import { G, P, O, ball, score, setupPoint, selectCourt, court, kit, skin, tour } from './state.js';
|
||||
import { pointTo, fault, tossBall } from './gameplay.js';
|
||||
import { pointTo, fault, tossBall, strikeRate, restartRun } from './gameplay.js';
|
||||
import { startMatch, matchReady, resolveInterlude, netMatchWon } from './beats.js'; // runtime-only cycle: beats sends verdicts back through this module
|
||||
import { zombies } from './zombies.js';
|
||||
import { sfx } from './audio.js';
|
||||
import { savedName, tidyName } from './stats.js';
|
||||
|
||||
// main.js hangs its court builders and its LOBBY here, so this module never has to know how a
|
||||
@@ -84,6 +85,12 @@ export function netApplyShot(m) {
|
||||
G.phase = 'rally'; G.swung = false; G.rallyNear = null;
|
||||
O.x = s.x; O.z = s.z; // the strike happened where the ball says it did
|
||||
O.pose = m.serve ? 'serve' : 'swing'; O.poseT = 0;
|
||||
// ...AND IT MAKES A NOISE (Oliver, 2026-09-11: "der ballsound des gegners wird nicht abgespielt").
|
||||
// Every other opponent in the game is simulated locally and cracks through gameplay's own strike
|
||||
// line; the friend's racket is the ONE swing no phone but theirs ever runs, so the sound had
|
||||
// nowhere to come from and a netplay rally was half silent. Same sample, same volume and the same
|
||||
// pace-pitched rate the CPU's gets — read off the ball we have just been handed.
|
||||
sfx('tennis-opponent', 0.9, { reverb: true, rate: strikeRate() });
|
||||
}
|
||||
|
||||
function netApplyPoint(m) {
|
||||
@@ -140,6 +147,18 @@ function netStart(side, death, courtId) {
|
||||
// guest never chose. Safe mid-run: selectCourt copies the bounce pair into TUNE and the backdrop
|
||||
// cache keys on court.id, so the next frame repaints.
|
||||
if (courtId && courtId !== court.id) selectCourt(courtId);
|
||||
netFresh(side, death);
|
||||
}
|
||||
|
||||
// TAKE THE COURT AND PLAY: everything netStart does once the pairing is settled, and everything a
|
||||
// REMATCH has to do all over again on the same socket. Split out for netAgain below — the two
|
||||
// must not drift, because a rematch that sets the court up even slightly differently from the
|
||||
// pairing is a desync waiting for the first serve.
|
||||
function netFresh(side, death, again = false) {
|
||||
// WHICH GAME IS ON THIS COURT. The first time round netHooks.paired -> main.start('classic')
|
||||
// sets this; on a rematch the menu is long gone and start() refuses, so it is said here instead
|
||||
// (the death branch below turns it off again exactly as netStart always did).
|
||||
G.classic = !death;
|
||||
if (death && !G.match) {
|
||||
// THE HOST PICKED DEATH MATCH, and the start message carries it to both phones — the joiner
|
||||
// (and the host itself) has been waiting on an ordinary classic court, so the court is rebuilt
|
||||
@@ -166,7 +185,34 @@ function netStart(side, death, courtId) {
|
||||
score.pts = [0, 0];
|
||||
G.serveNum = 1;
|
||||
if (G.match) matchReady(); else setupPoint();
|
||||
G.flash = { text: side === 'A' ? 'AN OPPONENT — YOUR SERVE' : 'AN OPPONENT — THEIR SERVE', t: 2.4 };
|
||||
G.flash = { text: (again ? 'REMATCH' : 'AN OPPONENT')
|
||||
+ (side === 'A' ? ' — YOUR SERVE' : ' — THEIR SERVE'), t: 2.4 };
|
||||
}
|
||||
|
||||
// THE REMATCH (Oliver, 2026-09-11: "nach einem vs. a friend duell gibt es kein retry / replay
|
||||
// button"). The summary's only door was THE CLUBHOUSE, so playing the same friend again meant both
|
||||
// of them walking back through the lobby and reading a fresh code aloud — for a mode whose whole
|
||||
// point is the person sitting opposite you. The relay cannot re-pair (the room code is single-use
|
||||
// and popped on pairing), so the rematch is the SOCKET THAT IS STILL OPEN: one 'again' frame and
|
||||
// both phones reset their run and take the court under the decisions the room already carries —
|
||||
// same side, same mode, same court.
|
||||
// It lives here rather than beside startNetVs in beats.js because it is netStart's own path
|
||||
// replayed: the court-ownership contract was settled when the room paired and is never re-entered.
|
||||
// `tell` is false when THEY asked: a rematch is applied, never echoed back (same rule as every
|
||||
// verdict in this file — see the `applying` latch).
|
||||
export function netAgain(tell = true) {
|
||||
const n = G.net;
|
||||
if (!n || !n.ready || n.dead) return false; // the line has to still be there
|
||||
// BOTH TAPPED AT ONCE: their 'again' lands a moment after ours and would restart a court that is
|
||||
// already fresh — mid-toss, if they were quick. One restart per handshake, either way round.
|
||||
const now = performance.now();
|
||||
if (now - (n.againT || -1e9) < 2000) return true;
|
||||
n.againT = now;
|
||||
if (tell) send({ t: 'again' });
|
||||
restartRun(true); // a fresh run, and the pairing rides through it
|
||||
G.net = n;
|
||||
netFresh(n.side, !!n.death, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
function netDead(text) {
|
||||
@@ -196,6 +242,7 @@ export function netMsg(m) {
|
||||
else if (m.t === 'pt') netApplyPoint(m);
|
||||
else if (m.t === 'fault') netApplyFault();
|
||||
else if (m.t === 'dead') netMatchWon(); // their blood ran out: this side's win ending
|
||||
else if (m.t === 'again') netAgain(false); // they tapped REMATCH: the same room, one run later
|
||||
else if (m.t === 'pos') { G.net.opp = m; if (m.srv) netSync(m); }
|
||||
// WHAT THEY LOOK LIKE AND WHAT THEY ARE CALLED. Their phone's kit and skin, resolved against our
|
||||
// own tables so a build that has never heard of a colour falls back to the drawn one rather than
|
||||
|
||||
+16
-8
@@ -3088,12 +3088,18 @@ export function render() {
|
||||
: G.classic ? 'LONGEST MATCH ' + G.best.games + ' GAMES'
|
||||
: 'BEST ' + G.best.games + ' GAMES · ' + G.best.sets + ' SETS')
|
||||
: null;
|
||||
// THE FRIEND IS STILL ON THE LINE — so the duel has a door back into itself (the REMATCH,
|
||||
// 2026-09-11). Netplay used to end on THE CLUBHOUSE alone, which meant a fresh room code and
|
||||
// a second trip through the lobby to play the same person again.
|
||||
const online = !promo && !!(G.net && G.net.ready && !G.net.dead);
|
||||
const fxLines = ready ? wrapText(promo ? 'THE CLUB WANTS A WORD'
|
||||
: online ? 'YOUR FRIEND IS STILL ON THE LINE'
|
||||
: G.net ? 'THE CLUB IS WAITING' : fx.line, F(8, 0), inner) : [];
|
||||
let h = pad + headLines.length * 24 + lineLines.length * 13 + 6;
|
||||
if (xd.xp > 0) h += MODAL_GAP + 32;
|
||||
if (G.newBest || mark) h += MODAL_GAP + (G.newBest ? 20 : 13);
|
||||
const twoUp = ready && !promo && !G.net; // is there a second door to draw?
|
||||
const solo = !promo && !G.net;
|
||||
const twoUp = ready && (solo || online); // is there a second door to draw?
|
||||
if (ready) h += MODAL_GAP + 16 + fxLines.length * 12 + MODAL_FOOT + MODAL_BTN
|
||||
+ (stack && twoUp ? MODAL_BTN + 8 : 0);
|
||||
h += pad;
|
||||
@@ -3151,7 +3157,8 @@ export function render() {
|
||||
ctx.font = F(7, 0);
|
||||
shadowText('NEXT', inX, y + 6, UI.dim);
|
||||
ctx.font = F(9, 700);
|
||||
shadowText(promo ? 'THE PROMOTION' : G.net ? 'BACK TO THE CLUBHOUSE' : fx.title,
|
||||
shadowText(promo ? 'THE PROMOTION' : online ? 'ANOTHER DUEL'
|
||||
: G.net ? 'BACK TO THE CLUBHOUSE' : fx.title,
|
||||
inX + 34, y + 6, UI.warm);
|
||||
y += 16;
|
||||
ctx.font = F(8, 0);
|
||||
@@ -3159,9 +3166,8 @@ export function render() {
|
||||
y += fxLines.length * 12 + MODAL_FOOT;
|
||||
// one button when the ceremony owns the tap, two when there is a real choice: the fixture
|
||||
// (the canonical path) and the way back to what you were just doing
|
||||
// NETPLAY ends on one door only: the other phone's socket is still being torn down, and
|
||||
// "enter the draw" would deal a solo cup into a live session.
|
||||
const solo = !promo && !G.net;
|
||||
// NETPLAY never offers the cup — "enter the draw" would deal a solo tournament into a live
|
||||
// session. Its own two doors are the rematch and the way out (see `online` above).
|
||||
// THE SECOND DOOR NAMES ITS MODE (2026-08-31, Oliver: "auf dem gleichen screen steht dann
|
||||
// PLAY AGAIN — wo ist der unterschied?"). Beside ENTER THE CUP an unqualified "again" is
|
||||
// an instruction without a subject: both read as "start something", and which something
|
||||
@@ -3171,13 +3177,15 @@ export function render() {
|
||||
: G.match && G.match.train ? 'TRAIN AGAIN'
|
||||
: G.match ? 'CLIMB AGAIN' : 'GORE AGAIN';
|
||||
const second = solo ? (cup || (G.done && G.done.cup) ? ['club', 'THE CLUBHOUSE']
|
||||
: ['again', againLabel]) : null;
|
||||
: ['again', againLabel])
|
||||
: online ? ['club', 'THE CLUBHOUSE'] : null;
|
||||
const bw = second && !stack ? Math.round((inner - 8) / 2) : inner;
|
||||
// "THE DRAW" was tennis for the field of entrants — and nothing is drawn any more since the
|
||||
// cup went deterministic (2026-08-29). The button names what it opens instead.
|
||||
const label = promo ? 'TAKE THE FLOOR' : solo ? 'ENTER THE CUP' : 'THE CLUBHOUSE';
|
||||
const label = promo ? 'TAKE THE FLOOR' : solo ? 'ENTER THE CUP'
|
||||
: online ? 'REMATCH' : 'THE CLUBHOUSE';
|
||||
drawButton(inX, y, bw, MODAL_BTN, label, UI.pick, true);
|
||||
endBtns.push({ id: solo ? 'next' : 'club', x: inX, y, w: bw, h: MODAL_BTN });
|
||||
endBtns.push({ id: solo ? 'next' : online ? 'rematch' : 'club', x: inX, y, w: bw, h: MODAL_BTN });
|
||||
if (second) {
|
||||
const sx = stack ? inX : inX + bw + 8, sy = stack ? y + MODAL_BTN + 8 : y;
|
||||
drawButton(sx, sy, bw, MODAL_BTN, second[1], UI.warm, false);
|
||||
|
||||
Reference in new issue
Block a user