One player defends, the other plays the Internet: earns credits over time and spends them on packets, upgrades and sabotage. Two rounds with swapped roles, timed (the faster fall wins). Built end to end, NOT yet QA'd or balanced. Sim (public/js/sim.js, TD.VS table): attacker economy (income, lifetime bonus, leak payback), spawn / stage / launch convoys, 7 tech tracks, abilities (EMP, decoy, surge, DDoS), defender tools (scan, patch, repair, quarantine), role-checked commands, round result, role-private state. Co-op/solo unchanged (24 scripted games replay identically). Bots (public/js/bot.js, tools/versus.js): defender (maze + turrets) and attacker (budgeted spender reading the tower mix); headless bot-vs-bot runner. Server (server/versus.js, protocol doc): versus rooms with lobby / countdown / playing / roundover / matchover, role stamping, cross-role refusal, role-private priv messages at 4 Hz, computer seat, freeze/forfeit rules, no pause/speed. Client (public/js/versus.js): setup dialog (role, length, vs computer or online), countdown, defender tools row, attacker unit shop with convoy + launch, tech and abilities, gateway choice, round/match screens, sounds, phone-first dock rows. Status and next steps (balance: the attacker currently wins ~100% of bot rounds; QA with two browsers; layout matrix rerun) are in docs/NEXT.md and docs/VERSUS.md. The full planned workflow incl. balance/QA prompts is in docs/workflows/versus-full.js. 253 unit tests pass; one smoke e2e run; no other e2e per the user's request. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
39 lines
2.1 KiB
JavaScript
39 lines
2.1 KiB
JavaScript
/* Netwall service worker: network-first so updates always win, cache as an offline fallback (solo play offline). */
|
|
const CACHE = 'netwall-v1';
|
|
const CORE = ['./', 'index.html', 'css/style.css', 'js/sim.js', 'js/bot.js', 'js/audio.js', 'js/controllers.js', 'js/render.js', 'js/versus.js', 'js/main.js',
|
|
'manifest.webmanifest', 'icons/icon.svg', 'icons/icon-192.png', 'assets/music/tracks.json'];
|
|
|
|
self.addEventListener('install', (e) => {
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(CORE)).then(() => self.skipWaiting()).catch(() => self.skipWaiting()));
|
|
});
|
|
self.addEventListener('activate', (e) => {
|
|
e.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim()));
|
|
});
|
|
// An error page from the proxy in front of the app (nginx answers 502/503/504 while the Node process restarts or is
|
|
// down) is a "network failure" for our purposes: serve the cached copy instead of the proxy's error page.
|
|
const GATEWAY_ERRORS = [502, 503, 504];
|
|
|
|
// The cached copy of this request; a navigation (also /?room=ABCD, which has no cache entry of its own) falls back to the
|
|
// cached app shell. `res` is the proxy's error response, still better than nothing for a file that was never cached.
|
|
function offline(req, res) {
|
|
return caches.match(req)
|
|
.then((r) => r || (req.mode === 'navigate' ? caches.match('index.html') : null))
|
|
.then((r) => r || res || Response.error());
|
|
}
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
const req = e.request;
|
|
if (req.method !== 'GET') return;
|
|
const url = new URL(req.url);
|
|
if (url.origin !== self.location.origin) return;
|
|
e.respondWith(
|
|
fetch(req)
|
|
.then((res) => {
|
|
if (GATEWAY_ERRORS.includes(res.status)) return offline(req, res);
|
|
// Only complete responses: a 206 (a range request for audio) is ok but is not the whole file.
|
|
if (res.status === 200 && res.type === 'basic') { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {}); }
|
|
return res;
|
|
})
|
|
.catch(() => offline(req)),
|
|
);
|
|
});
|