Compare commits

...

6 Commits

Author SHA1 Message Date
cottongin
06e375ccdc feat: continuous pulse glow when lobby is full, add horizontal offset for player list
Make the header meter pulse animation loop indefinitely (1.2s
ease-in-out) while playerCount equals maxPlayers. Stops when a
player leaves. Also add horizontal offset control for the player
list positioning.

Made-with: Cursor
2026-03-20 15:15:09 -04:00
cottongin
4c56b7f8f9 feat: show meter fill percentage in dashboard status
Made-with: Cursor
2026-03-20 15:03:16 -04:00
cottongin
7a2f8419d5 feat: add animated gradient meter to header text based on player count
CSS background-clip: text with dynamic linear-gradient replaces flat
header color. Fill sweeps left-to-right (pink to white) proportional
to playerCount/maxPlayers. Pulse glow fires when lobby is full.

Made-with: Cursor
2026-03-20 15:02:46 -04:00
cottongin
d775f74035 fix: disable player list by default
Made-with: Cursor
2026-03-20 14:59:32 -04:00
cottongin
228981bc2b docs: add header meter implementation plan
Made-with: Cursor
2026-03-20 14:57:28 -04:00
cottongin
c4929e54c3 docs: add header text player meter design
Made-with: Cursor
2026-03-20 14:56:17 -04:00
6 changed files with 608 additions and 5 deletions

View File

@@ -0,0 +1,83 @@
# Header Text Player Meter — Design
## Summary
Add a gradient fill meter to the "ROOM CODE:" header text that visually represents lobby fill (playerCount / maxPlayers). The fill sweeps left-to-right from the configured header color (pink) to white. A pulse/glow fires when the lobby is full.
Also: revert the player list checkbox to unchecked by default.
## Requirements
- Smooth CSS gradient across the header text, not per-character or per-word.
- Fill percentage = `playerCount / maxPlayers`, clamped to `[0, 1]`.
- 0 players → 100% pink. All players → 100% white.
- Gradient edge animates smoothly (~400ms ease) when player count changes.
- Brief pulse/glow animation when fill reaches 100%.
- Existing header settings (text, color, size, offset) continue to work. The configured header color becomes the "unfilled" color; white is always the "filled" color.
- Player list disabled by default.
## Approach
CSS `background-clip: text` with a dynamic `linear-gradient`.
### CSS Changes (`optimized-controls.html`)
Replace the static `#header` color with gradient-compatible styles:
```css
#header {
/* existing position, font, letter-spacing, opacity, transition stay */
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
/* drop-shadow replaces text-shadow (incompatible with transparent text) */
filter: drop-shadow(3px 3px 8px rgba(0, 0, 0, 0.8));
text-shadow: none;
}
```
New keyframes for the full-lobby pulse:
```css
@keyframes meter-full-pulse {
0% { filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); transform: scale(1) translateY(var(--header-offset)); }
50% { filter: drop-shadow(0 0 20px rgba(255,255,255,0.6)) drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); transform: scale(1.05) translateY(var(--header-offset)); }
100% { filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); transform: scale(1) translateY(var(--header-offset)); }
}
#header.meter-full-pulse {
animation: meter-full-pulse 0.6s ease-out;
}
```
### JS Changes (`js/room-code-display.js`)
1. **Track meter state** — new private fields: `#meterFill` (current 01), `#meterTarget` (target 01), `#meterRafId`.
2. **`#applySettings()`** — replace `header.style.color = headerColor` with `header.style.background = linear-gradient(...)` using current `#meterFill` and the configured header color.
3. **`update(ctx)`** — compute new target from `ctx.playerCount / ctx.maxPlayers`. If different from current target, call `#animateMeterTo(newTarget)`.
4. **`#animateMeterTo(target)`** — `requestAnimationFrame` loop that interpolates `#meterFill` toward target over ~400ms with ease-out. Each frame calls `#applyMeterGradient()`.
5. **`#applyMeterGradient()`** — sets `header.style.background` to `linear-gradient(to right, #fff 0%, #fff ${pct}%, ${headerColor} ${pct}%, ${headerColor} 100%)` plus re-applies `background-clip` properties.
6. **`#triggerFullPulse()`** — adds `meter-full-pulse` class, removes after `animationend` event.
7. **`deactivate()`** — cancels RAF, resets `#meterFill` to 0.
### HTML Change (`optimized-controls.html`)
Remove `checked` from `<input type="checkbox" id="player-list-enabled" checked>`.
## Data Flow
```
WebSocket event (lobby.player-joined / player-count-updated)
→ OverlayManager updates context.playerCount
→ OverlayManager calls RoomCodeDisplay.update(ctx)
→ RoomCodeDisplay computes target = playerCount / maxPlayers
→ #animateMeterTo(target) runs RAF interpolation
→ When target reaches 1.0, #triggerFullPulse() fires
```
## Edge Cases
- `maxPlayers` is 0 or missing → fill stays at 0%.
- `playerCount > maxPlayers` → clamp to 100%.
- Rapid successive joins → each new target interrupts the current animation, smoothly redirecting.
- Lobby reset (new game) → `deactivate()` resets fill to 0; next `activate()` starts fresh.

View File

@@ -0,0 +1,388 @@
# Header Text Player Meter — Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Add a gradient fill meter to the "ROOM CODE:" header that visually indicates lobby fill (playerCount / maxPlayers), animating left-to-right from the header color (pink) to white, with a pulse effect at 100%.
**Architecture:** The existing `RoomCodeDisplay` component gains meter state tracking and a `requestAnimationFrame` interpolation loop. CSS `background-clip: text` with a dynamic `linear-gradient` replaces the flat `header.style.color`. The `OverlayManager` already broadcasts `playerCount` and `maxPlayers` in context — no state management changes needed.
**Tech Stack:** Vanilla JS (ES modules), CSS `background-clip: text`, `requestAnimationFrame`.
---
### Task 1: Revert Player List Default to Unchecked
**Files:**
- Modify: `optimized-controls.html:669` (the `player-list-enabled` checkbox)
**Step 1: Remove the `checked` attribute**
In `optimized-controls.html`, change:
```html
<input type="checkbox" id="player-list-enabled" checked>
```
to:
```html
<input type="checkbox" id="player-list-enabled">
```
**Step 2: Verify in browser**
Open `http://localhost:8080/optimized-controls.html`, expand Player List Settings, confirm the checkbox is unchecked by default.
**Step 3: Commit**
```bash
git add optimized-controls.html
git commit -m "fix: disable player list by default"
```
---
### Task 2: Update `#header` CSS for Gradient Text Support
**Files:**
- Modify: `optimized-controls.html``<style>` block, `#header` rule (lines ~30-42)
**Step 1: Replace `#header` CSS**
Find the existing `#header` rule:
```css
#header {
position: absolute;
width: 100%;
text-align: center;
transform: translateY(-220px);
color: #f35dcb;
font-size: 80px;
font-weight: bold;
text-shadow: 3px 3px 8px rgba(0, 0, 0, 0.8);
letter-spacing: 2px;
opacity: 0;
transition: opacity 0.5s ease;
}
```
Replace with:
```css
#header {
position: absolute;
width: 100%;
text-align: center;
transform: translateY(-220px);
color: #f35dcb;
font-size: 80px;
font-weight: bold;
letter-spacing: 2px;
opacity: 0;
transition: opacity 0.5s ease;
/* Meter gradient support */
background: linear-gradient(to right, #ffffff 0%, #ffffff 0%, #f35dcb 0%, #f35dcb 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(3px 3px 8px rgba(0, 0, 0, 0.8));
}
```
Key changes: removed `text-shadow` (incompatible with transparent text), added `background` gradient, `background-clip: text`, `-webkit-text-fill-color: transparent`, and `filter: drop-shadow()` to replace the shadow.
**Step 2: Add pulse keyframes and class**
After the `#header` rule, add:
```css
@keyframes meter-full-pulse {
0% { filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); }
50% { filter: drop-shadow(0 0 20px rgba(255,255,255,0.6)) drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); }
100% { filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); }
}
#header.meter-full-pulse {
animation: meter-full-pulse 0.6s ease-out;
}
```
**Step 3: Verify in browser**
Load the page. The header text should still appear pink during the animation cycle but now rendered via gradient clip instead of flat color. The shadow should look the same (via `drop-shadow`).
**Step 4: Commit**
```bash
git add optimized-controls.html
git commit -m "feat: add CSS gradient-clip and pulse keyframes for header meter"
```
---
### Task 3: Add Meter State and Gradient Logic to `RoomCodeDisplay`
**Files:**
- Modify: `js/room-code-display.js`
**Step 1: Add private meter fields**
After the existing private fields (`#elements`, `#inputs`, `#animationTimers`, `#active`), add:
```javascript
/** @type {number} Current fill 0-1 */
#meterFill = 0;
/** @type {number} Target fill 0-1 */
#meterTarget = 0;
/** @type {number | null} */
#meterRafId = null;
/** @type {boolean} Whether the pulse has fired for the current 100% state */
#meterPulseFired = false;
```
**Step 2: Add `#applyMeterGradient()` method**
This reads the current `#meterFill` and the configured header color, then sets the gradient on the header element.
```javascript
#applyMeterGradient() {
const header = this.#elements?.header;
const inputs = this.#inputs;
if (!header || !inputs) return;
const pct = Math.round(this.#meterFill * 100);
const baseColor = inputs.headerColor.value || '#f35dcb';
header.style.background =
`linear-gradient(to right, #ffffff 0%, #ffffff ${pct}%, ${baseColor} ${pct}%, ${baseColor} 100%)`;
header.style.webkitBackgroundClip = 'text';
header.style.backgroundClip = 'text';
header.style.webkitTextFillColor = 'transparent';
}
```
**Step 3: Add `#animateMeterTo(target)` method**
Smooth `requestAnimationFrame` interpolation from current fill to target over ~400ms.
```javascript
#animateMeterTo(target) {
const clamped = Math.max(0, Math.min(1, target));
this.#meterTarget = clamped;
if (this.#meterRafId != null) {
cancelAnimationFrame(this.#meterRafId);
this.#meterRafId = null;
}
const start = this.#meterFill;
const delta = clamped - start;
if (Math.abs(delta) < 0.001) {
this.#meterFill = clamped;
this.#applyMeterGradient();
this.#checkFullPulse();
return;
}
const duration = 400;
const startTime = performance.now();
const step = (now) => {
const elapsed = now - startTime;
const t = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - t, 3); // ease-out cubic
this.#meterFill = start + delta * eased;
this.#applyMeterGradient();
if (t < 1) {
this.#meterRafId = requestAnimationFrame(step);
} else {
this.#meterRafId = null;
this.#meterFill = clamped;
this.#applyMeterGradient();
this.#checkFullPulse();
}
};
this.#meterRafId = requestAnimationFrame(step);
}
```
**Step 4: Add `#checkFullPulse()` method**
```javascript
#checkFullPulse() {
const header = this.#elements?.header;
if (!header) return;
if (this.#meterFill >= 1 && !this.#meterPulseFired) {
this.#meterPulseFired = true;
header.classList.add('meter-full-pulse');
header.addEventListener('animationend', () => {
header.classList.remove('meter-full-pulse');
}, { once: true });
}
if (this.#meterFill < 1) {
this.#meterPulseFired = false;
}
}
```
**Step 5: Modify `#applySettings()` — replace color line with gradient**
In the existing `#applySettings()` method, find:
```javascript
header.style.color = inputs.headerColor.value;
```
Replace with:
```javascript
this.#applyMeterGradient();
```
This ensures that whenever settings are applied, the gradient is re-rendered with the correct header color and current fill level.
**Step 6: Modify `update(ctx)` — add meter update logic**
The existing `update()` only checks roomCode changes. After the existing roomCode check, add meter logic:
```javascript
// After the existing roomCode change check:
const count = Number(ctx?.playerCount ?? 0);
const max = Number(ctx?.maxPlayers ?? 0);
const newTarget = max > 0 ? count / max : 0;
if (Math.abs(newTarget - this.#meterTarget) > 0.001) {
this.#animateMeterTo(newTarget);
}
```
**Step 7: Modify `deactivate()` — cancel RAF and reset meter**
Add before the existing opacity fade-out code:
```javascript
if (this.#meterRafId != null) {
cancelAnimationFrame(this.#meterRafId);
this.#meterRafId = null;
}
this.#meterFill = 0;
this.#meterTarget = 0;
this.#meterPulseFired = false;
```
**Step 8: Modify `activate(ctx)` — seed initial meter from context**
After the existing `this.#applySettings()` call, add:
```javascript
const count = Number(ctx?.playerCount ?? 0);
const max = Number(ctx?.maxPlayers ?? 0);
const initialFill = max > 0 ? count / max : 0;
this.#meterFill = Math.max(0, Math.min(1, initialFill));
this.#meterTarget = this.#meterFill;
this.#meterPulseFired = false;
this.#applyMeterGradient();
```
**Step 9: Update `getStatus()` — include meter info**
Add `meterFill` to the returned object:
```javascript
getStatus() {
// ... existing code ...
return {
active: this.#active,
roomCode,
timersRunning: this.#animationTimers.length > 0,
meterFill: Math.round(this.#meterFill * 100),
};
}
```
**Step 10: Verify in browser**
1. Open the overlay, connect to API.
2. Trigger a game (or use Update/Preview button).
3. The header should appear 100% pink (0 players).
4. As players join, the gradient should animate left-to-right toward white.
5. At full capacity, a brief pulse/glow should fire.
**Step 11: Commit**
```bash
git add js/room-code-display.js
git commit -m "feat: add animated gradient meter to header text based on player count"
```
---
### Task 4: Update Dashboard Status for Meter
**Files:**
- Modify: `js/controls.js``formatStatusRow` function
**Step 1: Include meter fill in roomCode status display**
In `formatStatusRow`, find the `roomCode` case:
```javascript
if (name === 'roomCode') {
const rc = /** @type {{ active?: boolean, roomCode?: string }} */ (s);
return rc.active ? `Active (${rc.roomCode ?? ''})` : 'Inactive';
}
```
Change to:
```javascript
if (name === 'roomCode') {
const rc = /** @type {{ active?: boolean, roomCode?: string, meterFill?: number }} */ (s);
if (!rc.active) return 'Inactive';
const meter = rc.meterFill != null ? ` | Meter: ${rc.meterFill}%` : '';
return `Active (${rc.roomCode ?? ''})${meter}`;
}
```
**Step 2: Commit**
```bash
git add js/controls.js
git commit -m "feat: show meter fill percentage in dashboard status"
```
---
### Task 5: End-to-End Verification
**Step 1: Full flow test**
1. Load `http://localhost:8080/optimized-controls.html`.
2. Confirm player list checkbox is unchecked by default.
3. Connect to the API WebSocket.
4. Trigger a game via the Game Picker (or use Preview/Update button with a room code).
5. Observe: header appears 100% pink.
6. As players join, gradient fills left-to-right, animating smoothly.
7. When lobby is full, text is 100% white and pulse fires.
8. When game starts/ends, header deactivates, meter resets.
9. New lobby → header starts fresh at 0% fill.
**Step 2: Edge case test**
- Use Update/Preview with `max_players: 2`. Join 1 player (50%), then 2nd (100% + pulse).
- Disconnect/reconnect mid-lobby — meter should reset and re-seed from context.
**Step 3: Final commit (if any polish needed)**
```bash
git add -A
git commit -m "polish: header meter edge cases and cleanup"
```

6
js/controls.js vendored
View File

@@ -68,8 +68,10 @@ export function initControls(manager, wsClient, components) {
const s = info?.status;
if (!s || typeof s !== 'object') return '—';
if (name === 'roomCode') {
const rc = /** @type {{ active?: boolean, roomCode?: string }} */ (s);
return rc.active ? `Active (${rc.roomCode ?? ''})` : 'Inactive';
const rc = /** @type {{ active?: boolean, roomCode?: string, meterFill?: number }} */ (s);
if (!rc.active) return 'Inactive';
const meter = rc.meterFill != null ? ` | Meter: ${rc.meterFill}%` : '';
return `Active (${rc.roomCode ?? ''})${meter}`;
}
if (name === 'audio') {
const a = /** @type {{ active?: boolean, playing?: boolean }} */ (s);

View File

@@ -13,6 +13,7 @@ const DEFAULT_MAX_PLAYERS = 8;
* @property {HTMLInputElement} textColor
* @property {HTMLInputElement} emptyColor
* @property {HTMLInputElement} offset
* @property {HTMLInputElement} offsetX
*/
/**
@@ -214,9 +215,18 @@ export class PlayerList {
const textColor = inputs.textColor.value;
const emptyColor = inputs.emptyColor.value;
const offsetY = `${parseInt(inputs.offset.value, 10) || 0}px`;
const offsetX = parseInt(inputs.offsetX?.value, 10) || 0;
container.style.transform = `translateY(calc(-50% + ${offsetY}))`;
if (pos === 'right') {
container.style.right = `${24 + offsetX}px`;
container.style.left = '';
} else {
container.style.left = `${24 + offsetX}px`;
container.style.right = '';
}
for (const slot of this._slots) {
slot.nameEl.style.fontSize = fontPx;
slot.element.querySelector('.player-slot-number').style.fontSize = fontPx;

View File

@@ -56,6 +56,16 @@ export class RoomCodeDisplay {
/** @type {boolean} */
#active = false;
/** @type {number} */
#meterFill = 0;
/** @type {number} */
#meterTarget = 0;
/** @type {number | null} */
#meterRafId = null;
/**
* @param {RoomCodeDisplayElements} elements
* @param {RoomCodeDisplayInputs} inputs
@@ -89,6 +99,14 @@ export class RoomCodeDisplay {
}
this.#applySettings();
const count = Number(ctx?.playerCount ?? 0);
const max = Number(ctx?.maxPlayers ?? 0);
const initialFill = max > 0 ? count / max : 0;
this.#meterFill = Math.max(0, Math.min(1, initialFill));
this.#meterTarget = this.#meterFill;
this.#applyMeterGradient();
this.#startAnimation();
}
@@ -96,6 +114,13 @@ export class RoomCodeDisplay {
this.#active = false;
this.#clearAnimationTimers();
if (this.#meterRafId != null) {
cancelAnimationFrame(this.#meterRafId);
this.#meterRafId = null;
}
this.#meterFill = 0;
this.#meterTarget = 0;
const { header, footer, codePart1, codePart2 } = this.#elements ?? {};
if (!header || !footer || !codePart1 || !codePart2) {
return;
@@ -127,6 +152,14 @@ export class RoomCodeDisplay {
if (next && next !== current) {
this.activate(ctx);
return;
}
const count = Number(ctx?.playerCount ?? 0);
const max = Number(ctx?.maxPlayers ?? 0);
const newTarget = max > 0 ? count / max : 0;
if (Math.abs(newTarget - this.#meterTarget) > 0.001) {
this.#animateMeterTo(newTarget);
}
}
@@ -140,6 +173,7 @@ export class RoomCodeDisplay {
active: this.#active,
roomCode,
timersRunning: this.#animationTimers.length > 0,
meterFill: Math.round(this.#meterFill * 100),
};
}
@@ -175,7 +209,7 @@ export class RoomCodeDisplay {
codePart2.style.fontSize = `${inputs.size.value}px`;
header.textContent = inputs.headerText.value;
header.style.color = inputs.headerColor.value;
this.#applyMeterGradient();
header.style.fontSize = `${inputs.headerSize.value}px`;
header.style.transform = `translateY(${inputs.headerOffset.value}px)`;
@@ -279,4 +313,71 @@ export class RoomCodeDisplay {
}, cycleDuration),
);
}
#applyMeterGradient() {
const header = this.#elements?.header;
const inputs = this.#inputs;
if (!header || !inputs) return;
const pct = Math.round(this.#meterFill * 100);
const baseColor = inputs.headerColor.value || '#f35dcb';
header.style.background =
`linear-gradient(to right, #ffffff 0%, #ffffff ${pct}%, ${baseColor} ${pct}%, ${baseColor} 100%)`;
header.style.webkitBackgroundClip = 'text';
header.style.backgroundClip = 'text';
header.style.webkitTextFillColor = 'transparent';
}
#animateMeterTo(target) {
const clamped = Math.max(0, Math.min(1, target));
this.#meterTarget = clamped;
if (this.#meterRafId != null) {
cancelAnimationFrame(this.#meterRafId);
this.#meterRafId = null;
}
const start = this.#meterFill;
const delta = clamped - start;
if (Math.abs(delta) < 0.001) {
this.#meterFill = clamped;
this.#applyMeterGradient();
this.#checkFullPulse();
return;
}
const duration = 400;
const startTime = performance.now();
const step = (now) => {
const elapsed = now - startTime;
const t = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
this.#meterFill = start + delta * eased;
this.#applyMeterGradient();
if (t < 1) {
this.#meterRafId = requestAnimationFrame(step);
} else {
this.#meterRafId = null;
this.#meterFill = clamped;
this.#applyMeterGradient();
this.#checkFullPulse();
}
};
this.#meterRafId = requestAnimationFrame(step);
}
#checkFullPulse() {
const header = this.#elements?.header;
if (!header) return;
if (this.#meterFill >= 1) {
header.classList.add('meter-full-pulse');
} else {
header.classList.remove('meter-full-pulse');
}
}
}

View File

@@ -35,10 +35,24 @@
color: #f35dcb;
font-size: 80px;
font-weight: bold;
text-shadow: 3px 3px 8px rgba(0, 0, 0, 0.8);
letter-spacing: 2px;
opacity: 0;
transition: opacity 0.5s ease;
background: linear-gradient(to right, #ffffff 0%, #ffffff 0%, #f35dcb 0%, #f35dcb 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(3px 3px 8px rgba(0, 0, 0, 0.8));
}
@keyframes meter-full-pulse {
0% { filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); }
50% { filter: drop-shadow(0 0 20px rgba(255,255,255,0.6)) drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); }
100% { filter: drop-shadow(3px 3px 8px rgba(0,0,0,0.8)); }
}
#header.meter-full-pulse {
animation: meter-full-pulse 1.2s ease-in-out infinite;
}
#footer {
@@ -666,7 +680,7 @@
<div class="section-content">
<div class="control-row">
<label>Enable Player List:</label>
<input type="checkbox" id="player-list-enabled" checked>
<input type="checkbox" id="player-list-enabled">
</div>
<div class="control-row">
<label>Position:</label>
@@ -691,6 +705,10 @@
<label>Vertical Offset:</label>
<input type="number" id="player-list-offset" value="0" step="10">
</div>
<div class="control-row">
<label>Horizontal Offset:</label>
<input type="number" id="player-list-offset-x" value="0" step="10">
</div>
</div>
</div>
@@ -860,6 +878,7 @@
textColor: document.getElementById('player-list-text-color'),
emptyColor: document.getElementById('player-list-empty-color'),
offset: document.getElementById('player-list-offset'),
offsetX: document.getElementById('player-list-offset-x'),
},
{
headerAppearDelay: document.getElementById('header-appear-delay'),