From 82b86a1060bf790ef4579a868d62e35c0ce6adbf Mon Sep 17 00:00:00 2001 From: Ian Massaro Date: Tue, 17 Nov 2026 23:30:58 -0500 Subject: [PATCH 1/5] Shell Crackers: spectator mode (?watch=1) and an N watching count (watchers.js) Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + e63334287a3deaa3/shell-crackers/index.html | 250 ++++++++++++++++++--- e63334287a3deaa3/watchers.js | 43 ++++ 3 files changed, 267 insertions(+), 27 deletions(-) create mode 100644 e63334287a3deaa3/watchers.js diff --git a/README.md b/README.md index d5e9d0a4..8531f79f 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ Personal site hosted with GitHub Pages at **https://ascoding11.github.io**, the - In-game leaderboards: every game page that loads stats.js gets a "Leaderboard" button that opens that game's boards in a panel over the page (the same boards, checks and data as the Leaderboards section of the Back Room page, which is unchanged). stats.js adds the button (`boardButton`) and, the first time it is pressed, loads `/namefilter.js` if the page hasn't and `leaderboard.js` with `data-game=""`: its game mode builds the usual section inside a dialog (`.lbd-modal`, with its own colours and type since game pages have none of the hub's CSS variables), fixed to that game, signed in through `BackRoomStats.conn()` (the connection stats.js already publishes with) instead of party.js, read when the panel opens, with the view remembered per game (`lb:view:`). Close, Escape or a press outside closes it; keys and presses inside stay inside. Where the button goes, so it never sits over play: in a game with a `#menu`, inside that menu as its last item, and while that menu is showing but its button is scrolled out of view (most menus are taller than the screen), a copy (`#brlb-pin`) is pinned bottom right and goes as soon as the real one scrolls into view, the menu is hidden or faded out, or the panel opens; on a page with no `#menu` and no canvas (the puzzles), at the end of the page; on a page with a canvas and no `#menu`, a small round button fixed bottom left that hides while the pointer is locked and for 8 s after any key or press. A game's stats.js tag can override it: `data-board="off"`, a corner (`tl`, `tr`, `bl`, `br`; 2048 uses `bl`), or `data-board-in=""` to put it inside a chosen element. A new game with a `#menu` needs nothing. The button is added inside frames too (the home page, phone page and party layer all open games in an iframe, which is how most people play); only the hidden stats sidecar frame has no stats.js of its own. - `e63334287a3deaa3/elo.js`: ranked ratings (Elo), one per game, for the online games that end with a winner: Boostball, Rumble Karts, Backrooms 1v1–4v4, Driftfall, Slipstream, Turbo Trail, Tumble Trials, Chromaflage, Odd One Out, Puffer Party, Deepword's Brawl and Lokop. Shell Crackers keeps its own older rating (`shellcr-rank`, `rooms/sc-ratings`) and doesn't load this file; the maths here is the same as its. Each game loads it next to stats.js (``) and calls `BackRoomElo.report({ id, won, opp: [{ u: uid, s }, { bot: 1, s }] })` once where its online match or round ends (search each game for `BackRoomElo`): `opp` is everyone you played against, not teammates, and `s` is your result against that one opponent (1 beat them or your team won, 0 lost, 0.5 drew), so team games give every opponent the same `s`, races and free-for-alls go by finishing place, Driftfall counts everyone already out as beaten and everyone still alive as a loss, Tumble Trials rates once per show (when you go out or the final ends), and in Chromaflage a seeker beats each hider that was found while a hider beats the seekers by staying hidden. The change is the usual Elo one (K 36 for the first 10 matches, then 24), averaged over the opponents and multiplied by the number of real opponents (×1 for one, 25% more for each extra, at most ×3); bots count as rated 1000, and a match with no real opponent isn't rated, so practice and bot-only rooms never move a rating. Everyone starts at 1000 and stays in 100–3000. `id` stops a match being rated twice (results screens can be drawn more than once). Storage: this browser's `elo:` (`{ r, g, wn, pk, uid }`) and the Realtime Database at `rooms/elo-/players/` (`n, c, x, z, h, ts` as the shared rules need, plus `r, g, wn, pk`), written by the player's own browser; on load the account's saved rating wins, and opponents' ratings are read from their nodes when a match is reported. So, like every Back Room stat, it is self-reported and not cheat-proof. It never signs in or makes a Firebase app itself (it uses the game's), and every call swallows its own errors, so it can't stop a game. After a rated match a small pill at the top shows the new rating and the change. stats.js reads `elo:` into the game's `elo` stat (the list of folders is next to `READ`), and leaderboard.js has an Elo board first for each of these games (for Slipstream, after its lap and record boards); as with Shell Crackers, the board keeps the best value it has seen, so it shows a player's highest rating. To rate another game: add the script tag and one `report` call, add its folder to the list in stats.js, and add the Elo row to its entry in leaderboard.js. - `e63334287a3deaa3/netsmooth.js`: smooth movement for other players in the online games. Updates over school Wi-Fi and Firebase arrive late and in bursts, so a game that moves someone to their newest update makes them lurch and stall, and one that shows them a fixed time in the past freezes them whenever an update is later than that. Each remote player gets a `NetSmooth.lag()`, which measures how late their updates really arrive and shows them just far enough in the past that the next one is almost always already here (about a tenth of a second on good Wi-Fi, more on bad, never more than 0.45 s), easing that delay so the timeline never jumps; `NetSmooth.sample()` draws them between the two updates around that moment and carries them on for up to 0.3 s if an update is late. Used by Shell Crackers, Backrooms 1v1–4v4, Hail Mary, Coil, Quarry, Chromaflage, Odd One Out, Spire, Turbo Trail, Escapade, Updraft, Driftfall and Blockstorm. Kartwheel, Slipstream, Boostball, Rumble Karts and Tumble Trials keep their own approach: cars, karts and racers are projected forward to the present from their speed, which matters more there than perfectly even motion. Settings were tuned with a simulation of good, school and bad Wi-Fi: compared with chasing the newest update, other players stall about a fifth as often and almost never lurch, for roughly a tenth of a second more delay. +- `e63334287a3deaa3/watchers.js` and spectating (Back Room). Shell Crackers, Backrooms 1v1–4v4 and Boostball can be watched without playing: the game opened as `/?watch=1#-` (the Watch buttons on the Back Room page, or a watch link: the home page or phone page with `?watch=1#sc-…`, `#br-…` or `#bb-…`) goes straight into that room as a spectator. A spectator writes nothing inside the game room (no player node, round, events, rating or stats; stats.js and elo.js aren't loaded for it), so it never counts as a player, never hosts and never affects a match, the Leaderboards or Elo, and a full room can still be watched. It gets a Spectating banner, the players' names, a scoreboard, a Leave button (Back closes the game layer), a follow camera that steps through the players and a free camera. **The "N watching" count** is the only thing a spectator stores: `BackRoomWatchers.join` writes its own node `rooms/-_watch/players/` (`n`, `c`, `x`, `z`, `h`, `ts` as the rules require, `x`/`z`/`h` always 0, plus `r`, the room code without its prefix), refreshed every 10 s and removed on leaving or disconnecting; `BackRoomWatchers.count` reads that list and counts fresh nodes (under 30 s old) for one room. The underscore can't be typed into a room code, so no game room can have that name. **Shell Crackers** (`WATCH` / `Spec` in its script): Q / E or ← → (◀ ▶ on a phone) step through the eggs, F or Free cam (or dragging the view) flies a free camera (WASD, Space / Shift, drag to look; the move stick on a phone), Tab or Scores shows the scoreboard, Esc or Leave leaves. Its own egg stays inactive, so it never moves a capture-the-flag flag, starts or ends a match, or takes hits; the end card says who won and the next match shows when the players start it. Players see "N watching" in the line under the scores. - `e63334287a3deaa3/autores.js`: automatic resolution for the 3D games, so they stay smooth on school laptops. Every three.js game except Quarry (which has its own version) loads it right after `three.min.js`. It watches the frame rate, and when frames drop below about 45 a second it makes every three.js renderer on the page draw at a lower resolution, a tenth at a time, down to half; when frames stay smooth it steps back up (more slowly towards a resolution that was too slow before, so it doesn't keep flipping). It multiplies whatever `setPixelRatio` the game asks for, so a game's own graphics setting still counts. The scale each game settles on is remembered in the browser (`localStorage` key `autores:`), so the next visit starts there. No game code calls it; it wraps `THREE.WebGLRenderer`. `AutoRes.scale` shows the current scale and `AutoRes.off()` turns it off for a visit. - `e63334287a3deaa3/account-nudge.js`: the sign-in nudge and account save (Back Room). Loaded on the Back Room page and the phone page (one ` + + + @@ -499,6 +526,23 @@

Champion egg!

+ + + @@ -509,6 +553,11 @@

Champion egg!

diff --git a/e63334287a3deaa3/watchers.js b/e63334287a3deaa3/watchers.js new file mode 100644 index 00000000..2ff9b508 --- /dev/null +++ b/e63334287a3deaa3/watchers.js @@ -0,0 +1,43 @@ +/* + * watchers.js: the "N watching" count for games with a spectator mode (Shell Crackers, Backrooms 1v1, Boostball). + * + * A spectator (the game opened as /?watch=1#-) must never have a node in the game room itself, + * because every node in rooms/-/players counts as a player there. So spectators are listed in one + * room of their own per game, rooms/-_watch/players/ (the underscore can't be typed into a room code, + * so no game room can ever have that name). The node has the fields the shared rules require (n, c, x, z, h, ts; + * x/z/h always 0) plus r, the room being watched. It is refreshed every 10 s and removed on leaving or disconnecting; + * a node not refreshed for 30 s is ignored. Players (and spectators) of a room listen to that list and count the + * fresh nodes whose r is their room. Nothing else is stored and nothing here touches matches, stats or ratings. + * + * BackRoomWatchers.join(db, uid, prefix, room, now) -> stop() a spectator announces itself + * BackRoomWatchers.count(db, prefix, room, now, cb) -> stop() cb(n) whenever the number watching changes + * db: the game's firebase.database(); uid: the signed-in uid; now: the game's server-time clock (ms). + */ +(function () { + 'use strict'; + var BEAT = 10000, LIVE = 30000; + function list(db, pre) { return db.ref('rooms/' + pre + '-_watch/players'); } + window.BackRoomWatchers = { + join: function (db, uid, pre, room, now) { + if (!db || !uid || !room) return function () {}; + var ref = list(db, pre).child(uid), on = true; + var put = function () { if (on) ref.set({ n: 'Spectator', c: '#8a8a8a', x: 0, z: 0, h: 0, ts: Math.round(now()), r: String(room) }).catch(function () {}); }; + try { ref.onDisconnect().remove(); } catch (e) {} + put(); + var t = setInterval(put, BEAT); + return function () { on = false; clearInterval(t); try { ref.onDisconnect().cancel(); ref.remove().catch(function () {}); } catch (e) {} }; + }, + count: function (db, pre, room, now, cb) { + if (!db || !room) return function () {}; + var ref = list(db, pre), val = {}, last = -1; + var calc = function () { + var n = 0, t = now(); + for (var k in val) { var v = val[k]; if (v && v.r === room && t - (+v.ts || 0) < LIVE) n++; } + if (n !== last) { last = n; try { cb(n); } catch (e) {} } + }; + var h = ref.on('value', function (s) { val = s.val() || {}; calc(); }, function () {}); + var t = setInterval(calc, 5000); + return function () { clearInterval(t); try { ref.off('value', h); } catch (e) {} if (last > 0) try { cb(0); } catch (e) {} }; + } + }; +})(); From 57ffb02edf8935d0a2a2541e2d15b6bb1a9e5e5e Mon Sep 17 00:00:00 2001 From: Ian Massaro Date: Tue, 17 Nov 2026 23:36:11 -0500 Subject: [PATCH 2/5] Backrooms 1v1: spectator mode (?watch=1) with the N watching count; watchers.js keeps the onDisconnect so a closed tab is cleared Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- e63334287a3deaa3/backrooms-1v1/index.html | 178 ++++++++++++++++++---- e63334287a3deaa3/watchers.js | 3 +- 3 files changed, 155 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8531f79f..a5948454 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Personal site hosted with GitHub Pages at **https://ascoding11.github.io**, the - In-game leaderboards: every game page that loads stats.js gets a "Leaderboard" button that opens that game's boards in a panel over the page (the same boards, checks and data as the Leaderboards section of the Back Room page, which is unchanged). stats.js adds the button (`boardButton`) and, the first time it is pressed, loads `/namefilter.js` if the page hasn't and `leaderboard.js` with `data-game=""`: its game mode builds the usual section inside a dialog (`.lbd-modal`, with its own colours and type since game pages have none of the hub's CSS variables), fixed to that game, signed in through `BackRoomStats.conn()` (the connection stats.js already publishes with) instead of party.js, read when the panel opens, with the view remembered per game (`lb:view:`). Close, Escape or a press outside closes it; keys and presses inside stay inside. Where the button goes, so it never sits over play: in a game with a `#menu`, inside that menu as its last item, and while that menu is showing but its button is scrolled out of view (most menus are taller than the screen), a copy (`#brlb-pin`) is pinned bottom right and goes as soon as the real one scrolls into view, the menu is hidden or faded out, or the panel opens; on a page with no `#menu` and no canvas (the puzzles), at the end of the page; on a page with a canvas and no `#menu`, a small round button fixed bottom left that hides while the pointer is locked and for 8 s after any key or press. A game's stats.js tag can override it: `data-board="off"`, a corner (`tl`, `tr`, `bl`, `br`; 2048 uses `bl`), or `data-board-in=""` to put it inside a chosen element. A new game with a `#menu` needs nothing. The button is added inside frames too (the home page, phone page and party layer all open games in an iframe, which is how most people play); only the hidden stats sidecar frame has no stats.js of its own. - `e63334287a3deaa3/elo.js`: ranked ratings (Elo), one per game, for the online games that end with a winner: Boostball, Rumble Karts, Backrooms 1v1–4v4, Driftfall, Slipstream, Turbo Trail, Tumble Trials, Chromaflage, Odd One Out, Puffer Party, Deepword's Brawl and Lokop. Shell Crackers keeps its own older rating (`shellcr-rank`, `rooms/sc-ratings`) and doesn't load this file; the maths here is the same as its. Each game loads it next to stats.js (``) and calls `BackRoomElo.report({ id, won, opp: [{ u: uid, s }, { bot: 1, s }] })` once where its online match or round ends (search each game for `BackRoomElo`): `opp` is everyone you played against, not teammates, and `s` is your result against that one opponent (1 beat them or your team won, 0 lost, 0.5 drew), so team games give every opponent the same `s`, races and free-for-alls go by finishing place, Driftfall counts everyone already out as beaten and everyone still alive as a loss, Tumble Trials rates once per show (when you go out or the final ends), and in Chromaflage a seeker beats each hider that was found while a hider beats the seekers by staying hidden. The change is the usual Elo one (K 36 for the first 10 matches, then 24), averaged over the opponents and multiplied by the number of real opponents (×1 for one, 25% more for each extra, at most ×3); bots count as rated 1000, and a match with no real opponent isn't rated, so practice and bot-only rooms never move a rating. Everyone starts at 1000 and stays in 100–3000. `id` stops a match being rated twice (results screens can be drawn more than once). Storage: this browser's `elo:` (`{ r, g, wn, pk, uid }`) and the Realtime Database at `rooms/elo-/players/` (`n, c, x, z, h, ts` as the shared rules need, plus `r, g, wn, pk`), written by the player's own browser; on load the account's saved rating wins, and opponents' ratings are read from their nodes when a match is reported. So, like every Back Room stat, it is self-reported and not cheat-proof. It never signs in or makes a Firebase app itself (it uses the game's), and every call swallows its own errors, so it can't stop a game. After a rated match a small pill at the top shows the new rating and the change. stats.js reads `elo:` into the game's `elo` stat (the list of folders is next to `READ`), and leaderboard.js has an Elo board first for each of these games (for Slipstream, after its lap and record boards); as with Shell Crackers, the board keeps the best value it has seen, so it shows a player's highest rating. To rate another game: add the script tag and one `report` call, add its folder to the list in stats.js, and add the Elo row to its entry in leaderboard.js. - `e63334287a3deaa3/netsmooth.js`: smooth movement for other players in the online games. Updates over school Wi-Fi and Firebase arrive late and in bursts, so a game that moves someone to their newest update makes them lurch and stall, and one that shows them a fixed time in the past freezes them whenever an update is later than that. Each remote player gets a `NetSmooth.lag()`, which measures how late their updates really arrive and shows them just far enough in the past that the next one is almost always already here (about a tenth of a second on good Wi-Fi, more on bad, never more than 0.45 s), easing that delay so the timeline never jumps; `NetSmooth.sample()` draws them between the two updates around that moment and carries them on for up to 0.3 s if an update is late. Used by Shell Crackers, Backrooms 1v1–4v4, Hail Mary, Coil, Quarry, Chromaflage, Odd One Out, Spire, Turbo Trail, Escapade, Updraft, Driftfall and Blockstorm. Kartwheel, Slipstream, Boostball, Rumble Karts and Tumble Trials keep their own approach: cars, karts and racers are projected forward to the present from their speed, which matters more there than perfectly even motion. Settings were tuned with a simulation of good, school and bad Wi-Fi: compared with chasing the newest update, other players stall about a fifth as often and almost never lurch, for roughly a tenth of a second more delay. -- `e63334287a3deaa3/watchers.js` and spectating (Back Room). Shell Crackers, Backrooms 1v1–4v4 and Boostball can be watched without playing: the game opened as `/?watch=1#-` (the Watch buttons on the Back Room page, or a watch link: the home page or phone page with `?watch=1#sc-…`, `#br-…` or `#bb-…`) goes straight into that room as a spectator. A spectator writes nothing inside the game room (no player node, round, events, rating or stats; stats.js and elo.js aren't loaded for it), so it never counts as a player, never hosts and never affects a match, the Leaderboards or Elo, and a full room can still be watched. It gets a Spectating banner, the players' names, a scoreboard, a Leave button (Back closes the game layer), a follow camera that steps through the players and a free camera. **The "N watching" count** is the only thing a spectator stores: `BackRoomWatchers.join` writes its own node `rooms/-_watch/players/` (`n`, `c`, `x`, `z`, `h`, `ts` as the rules require, `x`/`z`/`h` always 0, plus `r`, the room code without its prefix), refreshed every 10 s and removed on leaving or disconnecting; `BackRoomWatchers.count` reads that list and counts fresh nodes (under 30 s old) for one room. The underscore can't be typed into a room code, so no game room can have that name. **Shell Crackers** (`WATCH` / `Spec` in its script): Q / E or ← → (◀ ▶ on a phone) step through the eggs, F or Free cam (or dragging the view) flies a free camera (WASD, Space / Shift, drag to look; the move stick on a phone), Tab or Scores shows the scoreboard, Esc or Leave leaves. Its own egg stays inactive, so it never moves a capture-the-flag flag, starts or ends a match, or takes hits; the end card says who won and the next match shows when the players start it. Players see "N watching" in the line under the scores. +- `e63334287a3deaa3/watchers.js` and spectating (Back Room). Shell Crackers, Backrooms 1v1–4v4 and Boostball can be watched without playing: the game opened as `/?watch=1#-` (the Watch buttons on the Back Room page, or a watch link: the home page or phone page with `?watch=1#sc-…`, `#br-…` or `#bb-…`) goes straight into that room as a spectator. A spectator writes nothing inside the game room (no player node, round, events, rating or stats; stats.js and elo.js aren't loaded for it), so it never counts as a player, never hosts and never affects a match, the Leaderboards or Elo, and a full room can still be watched. It gets a Spectating banner, the players' names, a scoreboard, a Leave button (Back closes the game layer), a follow camera that steps through the players and a free camera. **The "N watching" count** is the only thing a spectator stores: `BackRoomWatchers.join` writes its own node `rooms/-_watch/players/` (`n`, `c`, `x`, `z`, `h`, `ts` as the rules require, `x`/`z`/`h` always 0, plus `r`, the room code without its prefix), refreshed every 10 s and removed on leaving or disconnecting; `BackRoomWatchers.count` reads that list and counts fresh nodes (under 30 s old) for one room. The underscore can't be typed into a room code, so no game room can have that name. **Shell Crackers** (`WATCH` / `Spec` in its script): Q / E or ← → (◀ ▶ on a phone) step through the eggs, F or Free cam (or dragging the view) flies a free camera (WASD, Space / Shift, drag to look; the move stick on a phone), Tab or Scores shows the scoreboard, Esc or Leave leaves. Its own egg stays inactive, so it never moves a capture-the-flag flag, starts or ends a match, or takes hits; the end card says who won and the next match shows when the players start it. Players see "N watching" in the line under the scores. **Backrooms 1v1–4v4** (`WATCH` in its script): it uses the game's own way of watching a match you're not in (the follow camera on any standing player, either team), straight into the room with no name or menu; Q / E or ← → (Prev / Next on a phone) or a click switch player, F (Free cam) flies through walls (WASD, Space / Shift, drag to look; the move stick on a phone), Tab (Scores) shows the teams panel, Esc or Leave leaves. Its `Net.uid` is a stand-in (`~watch`) no node has, so it never takes a player's node for its own, is never elected host and never asks for or is counted in a forfeit; it also reads the host's late-joiner piece list (`bs`) meant for anyone, so it sees what has been built. Players see "N watching" next to the room count in the lobby and under the scores in play. - `e63334287a3deaa3/autores.js`: automatic resolution for the 3D games, so they stay smooth on school laptops. Every three.js game except Quarry (which has its own version) loads it right after `three.min.js`. It watches the frame rate, and when frames drop below about 45 a second it makes every three.js renderer on the page draw at a lower resolution, a tenth at a time, down to half; when frames stay smooth it steps back up (more slowly towards a resolution that was too slow before, so it doesn't keep flipping). It multiplies whatever `setPixelRatio` the game asks for, so a game's own graphics setting still counts. The scale each game settles on is remembered in the browser (`localStorage` key `autores:`), so the next visit starts there. No game code calls it; it wraps `THREE.WebGLRenderer`. `AutoRes.scale` shows the current scale and `AutoRes.off()` turns it off for a visit. - `e63334287a3deaa3/account-nudge.js`: the sign-in nudge and account save (Back Room). Loaded on the Back Room page and the phone page (one ` - + + @@ -320,6 +340,17 @@
+