Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ The game is a static site, deployed to GitHub Pages from `main` by [.github/work

The **API** lives in [server/](server/) (its README lists settings and routes): Fastify, SQLite via `node:sqlite` (loaded with `createRequire`, since Vite can't bundle it), bundles and covers stored by SHA-256 ([server/blobs.ts](server/blobs.ts)). It imports the game's own `readBundle` / `buildRegistry` / `defaultPack`, so a published pack passes exactly the checks the game runs; keep `src/content` free of browser-only code. Sessions are an opaque token in an HttpOnly cookie (hash stored); state-changing requests need the `x-fight-forge: 1` header. `npm run server` runs it (`DEV_LOGIN=1` allows sign-in by name for development); its tests (`server/app.test.ts`, `fastify.inject`, in-memory store) run with the rest. The client is [src/net/api.ts](src/net/api.ts): with no `VITE_API_URL`, `apiEnabled()` is false and online UI stays hidden. The Forge's pack page has [PublishTools](src/components/forge/PublishTools.tsx): sign in, choose visibility, publish the current version (a published version must be newer; it offers the next patch version). The start menu's BROWSE PACKS opens the **gallery** (`gameScreen: 'gallery'`, [src/components/Gallery.tsx](src/components/Gallery.tsx)): search, sort, a creator filter, and a pack page with Play (`fetchBundle`, cached per version in the Cache API since bundles are immutable, then `installBundle` and `startRun` at the pack's first own level) and a share link. `?pack=<id>` (`linkedPack()`) opens straight to that pack's page. **Remix in Forge** (`remixBundle` in workspace.ts) copies a published pack into the workspace under a new id (`<id>-remix`), version 1.0.0, with `meta.remixOf` crediting the original; the server links a published remix to its original (`remix_of`), and pack pages show "Remix of" and the list of remixes. Likes are one per user (`POST /packs/:id/like`, sort `likes`). The gallery marks packs updated since this browser last played them ([src/net/played.ts](src/net/played.ts), localStorage). **Moderation**: anyone signed in can ⚑ Report a pack; moderators (`ADMINS` setting, `provider:name`) get a Reports panel ([Moderation.tsx](src/components/Moderation.tsx)) to take a pack down, dismiss reports or ban its owner, each logged in `moderation_actions`, and Take down / Put back on pack pages. A taken-down pack, or any pack of a banned user, is visible only to its owner (marked in PublishTools) and admins. Owners can remove their pack from the server. Limits are server-side: publishes and reports per user per hour, and writes per IP. Bundles check models with `glbProblem` (a whole glTF 2.0 file with no outside URIs) and audio with `audioType`; tests build models with `tinyGlb` from [src/test/glb.ts](src/test/glb.ts).

### Audio
Sound is content. The content's `sounds` (`SoundDef`, [src/audio/types.ts](src/audio/types.ts)) are `synth` (wave, pitch sweep, duration: no file needed) or `file` (an `audio` asset or a site URL); `music` is a looping `pattern` (tempo and tracks of space-separated notes like `A2 . C3 -`, parsed by [src/audio/notes.ts](src/audio/notes.ts)) or a `file`. `settings.audio` names the sound for each event (`hit`, `hurt`, `block`, `ko`, `pickup`, `clear`); a move can add `sound` (played as its active frames begin) and `hitSound`; a level can name `music`. [src/audio/engine.ts](src/audio/engine.ts) is the WebAudio engine: `playSound(id)` (from CombatSystem, Pickups, LevelDirector), `playMusic` / `stopMusic` (GameScene, per level), `duckMusic` while frozen, and `previewSound` / `previewMusic` for the Forge's [SoundTools](src/components/forge/SoundTools.tsx) (▶ Play, and "Use an audio file…" via `addAudioAsset`). Audio starts on the first click or key (`installAudioUnlock` in main.tsx). Master / music / effects volumes are a per-browser preference ([src/audio/volume.ts](src/audio/volume.ts)) set from [VolumeControls](src/components/VolumeControls.tsx) on the start menu (SOUND) and the pause menu. `audioLog` keeps the last sounds asked for, for headless tests.

### Fighters and controllers
Player and enemies are both **fighters**. [src/components/FighterBody.tsx](src/components/FighterBody.tsx) is the one shared body: rigid body and collider, a `fighter:<name>` sim system (order `SYSTEM_ORDER.fighters`, before attacks and combat) that steps the hit reaction, asks a controller for an `Intent`, moves (or slides with knockback while reacting), jumps, updates facing and the fighter state machine, plus the model, attack tint, hurt flash and hitbox overlay. [Player.tsx](src/components/Player.tsx) and [Enemy.tsx](src/components/Enemy.tsx) are thin wrappers that supply the controller and start moves (the player's combo; an enemy's attack when it takes the slot). Both use `forwardRef<RapierRigidBody, …>` so `GameScene` holds refs to their bodies.

Expand Down
2 changes: 2 additions & 0 deletions content/default/levels.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"id": "level-1",
"name": "Back Alley",
"theme": "default",
"music": "alley",
"segments": [
{
"length": 45,
Expand Down Expand Up @@ -252,6 +253,7 @@
"id": "level-2",
"name": "The Docks",
"theme": "docks",
"music": "docks",
"segments": [
{
"length": 40,
Expand Down
12 changes: 12 additions & 0 deletions content/default/moves.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"jab": {
"sound": "whoosh",
"startup": 0.05,
"active": 0.08,
"recovery": 0.17,
Expand All @@ -25,6 +26,7 @@
"next": "jab2"
},
"jab2": {
"sound": "whoosh",
"startup": 0.05,
"active": 0.08,
"recovery": 0.17,
Expand All @@ -50,6 +52,7 @@
"next": "hook"
},
"hook": {
"sound": "whoosh",
"startup": 0.08,
"active": 0.1,
"recovery": 0.22,
Expand All @@ -75,6 +78,8 @@
"next": "uppercut"
},
"uppercut": {
"sound": "whoosh",
"hitSound": "heavy",
"startup": 0.12,
"active": 0.1,
"recovery": 0.35,
Expand All @@ -100,6 +105,8 @@
}
},
"jumpKick": {
"sound": "whoosh",
"hitSound": "heavy",
"startup": 0.06,
"active": 0.25,
"recovery": 0.1,
Expand All @@ -125,6 +132,8 @@
"air": true
},
"dashPunch": {
"sound": "whoosh",
"hitSound": "heavy",
"startup": 0.1,
"active": 0.15,
"recovery": 0.35,
Expand All @@ -151,6 +160,8 @@
"lunge": 7
},
"rushPunch": {
"sound": "whoosh",
"hitSound": "heavy",
"startup": 0.2,
"active": 0.15,
"recovery": 0.5,
Expand All @@ -176,6 +187,7 @@
"lunge": 9
},
"enemyPunch": {
"sound": "whoosh",
"startup": 0.4,
"active": 0.1,
"recovery": 0.4,
Expand Down
36 changes: 36 additions & 0 deletions content/default/music.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"alley": {
"kind": "pattern",
"tempo": 112,
"volume": 0.35,
"tracks": [
{
"wave": "square",
"volume": 0.35,
"notes": "A2 . A2 . C3 . A2 . G2 . G2 . E2 . G2 . A2 . A2 . C3 . D3 . E3 - D3 . C3 . G2 ."
},
{
"wave": "triangle",
"volume": 0.5,
"notes": "A4 - - - . . E4 . G4 - - - . . D4 . A4 - - - . . C5 . B4 - A4 - G4 - E4 -"
}
]
},
"docks": {
"kind": "pattern",
"tempo": 96,
"volume": 0.35,
"tracks": [
{
"wave": "sawtooth",
"volume": 0.25,
"notes": "D2 . D2 D2 . . F2 . G2 . G2 G2 . . A2 . D2 . D2 D2 . . C3 . A2 . G2 . F2 . E2 ."
},
{
"wave": "sine",
"volume": 0.5,
"notes": "D4 - - - F4 - - - A4 - - - G4 - F4 - E4 - - - C4 - - - D4 - - - - - - -"
}
]
}
}
8 changes: 8 additions & 0 deletions content/default/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,13 @@
"pause": ["escape"],
"hitboxes": ["h"]
}
},
"audio": {
"hit": "punch",
"hurt": "hurt",
"block": "block",
"ko": "ko",
"pickup": "pickup",
"clear": "clear"
}
}
66 changes: 66 additions & 0 deletions content/default/sounds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"whoosh": {
"kind": "synth",
"wave": "noise",
"freq": 1800,
"freqEnd": 600,
"duration": 0.09,
"volume": 0.25
},
"punch": {
"kind": "synth",
"wave": "square",
"freq": 180,
"freqEnd": 55,
"duration": 0.11,
"volume": 0.5
},
"heavy": {
"kind": "synth",
"wave": "sawtooth",
"freq": 140,
"freqEnd": 35,
"duration": 0.2,
"volume": 0.6
},
"hurt": {
"kind": "synth",
"wave": "sawtooth",
"freq": 320,
"freqEnd": 120,
"duration": 0.16,
"volume": 0.45
},
"block": {
"kind": "synth",
"wave": "triangle",
"freq": 1100,
"freqEnd": 800,
"duration": 0.07,
"volume": 0.4
},
"ko": {
"kind": "synth",
"wave": "square",
"freq": 400,
"freqEnd": 40,
"duration": 0.45,
"volume": 0.5
},
"pickup": {
"kind": "synth",
"wave": "sine",
"freq": 660,
"freqEnd": 1320,
"duration": 0.14,
"volume": 0.45
},
"clear": {
"kind": "synth",
"wave": "triangle",
"freq": 523,
"freqEnd": 1046,
"duration": 0.6,
"volume": 0.5
}
}
36 changes: 36 additions & 0 deletions src/audio/audio.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, it } from 'vitest'
import { noteFreq, parseNotes, patternSteps, stepSeconds } from './notes'
import { DEFAULT_VOLUMES, parseVolumes } from './volume'

describe('music notes', () => {
it('names notes by pitch', () => {
expect(noteFreq('A4')).toBe(440)
expect(noteFreq('A3')).toBe(220)
expect(noteFreq('C4')).toBeCloseTo(261.63, 2)
expect(noteFreq('C#4')).toBeCloseTo(noteFreq('Db4')!, 6)
expect(noteFreq('H2')).toBeNull()
expect(noteFreq('.')).toBeNull()
})

it('reads rests and holds', () => {
const { notes, steps } = parseNotes('A4 - - . C5 . - E5')
expect(steps).toBe(8)
expect(notes.map((n) => [n.step, n.steps])).toEqual([
[0, 3],
[4, 1],
[7, 1],
])
})

it('times steps as sixteenth notes and loops on the longest track', () => {
expect(stepSeconds(120)).toBe(0.125)
expect(patternSteps([{ wave: 'sine', volume: 1, notes: 'A4 .' }, { wave: 'square', volume: 1, notes: 'A2 . . .' }])).toBe(4)
})
})

describe('volume settings', () => {
it('fills in and clamps stored values', () => {
expect(parseVolumes(null)).toEqual(DEFAULT_VOLUMES)
expect(parseVolumes({ master: 2, music: -1, sfx: 'loud' })).toEqual({ master: 1, music: 0, sfx: DEFAULT_VOLUMES.sfx })
})
})
Loading
Loading