diff --git a/client/public/version.js b/client/public/version.js index eac818b..568b7ea 100644 --- a/client/public/version.js +++ b/client/public/version.js @@ -1,5 +1,5 @@ // Maintainer-controlled web client version. // Format: YYYY.MM.DD Rn (example: 2026.02.20 R2) -window.CHGRID_WEB_VERSION = "2026.02.21 R128"; +window.CHGRID_WEB_VERSION = "2026.02.21 R129"; // Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid. window.CHGRID_TIME_ZONE = "America/Detroit"; diff --git a/client/src/audio/itemEmitRuntime.ts b/client/src/audio/itemEmitRuntime.ts index 94360c2..dfc02f7 100644 --- a/client/src/audio/itemEmitRuntime.ts +++ b/client/src/audio/itemEmitRuntime.ts @@ -24,6 +24,15 @@ type EmitSpatialConfig = { const ITEM_EMIT_BASE_GAIN = 0.3; +function resolveEmitPlaybackRate(raw: unknown): number { + const speed = Number(raw); + const clamped = Number.isFinite(speed) ? Math.max(0, Math.min(100, speed)) : 50; + if (clamped <= 50) { + return 0.5 + (clamped / 50) * 0.5; + } + return 1 + ((clamped - 50) / 50) * 1; +} + export class ItemEmitRuntime { private readonly outputs = new Map(); private layerEnabled = true; @@ -101,6 +110,7 @@ export class ItemEmitRuntime { const effect = normalizeRadioEffect(item.params.emitEffect); const effectValue = normalizeRadioEffectValue(item.params.emitEffectValue); const effectRuntime = connectEffectChain(audioCtx, effectInput, gain, effect, effectValue); + element.playbackRate = resolveEmitPlaybackRate(item.params.emitSpeed); if (this.audio.supportsStereoPanner()) { panner = audioCtx.createStereoPanner(); gain.connect(panner).connect(audioCtx.destination); @@ -138,6 +148,10 @@ export class ItemEmitRuntime { output.effect = effect; output.effectValue = effectValue; } + const nextPlaybackRate = resolveEmitPlaybackRate(item.params.emitSpeed); + if (Math.abs(output.element.playbackRate - nextPlaybackRate) > 0.001) { + output.element.playbackRate = nextPlaybackRate; + } const spatialConfig = this.getSpatialConfig(item); const mix = resolveSpatialMix({ dx: item.x - playerPosition.x, diff --git a/client/src/items/itemRegistry.ts b/client/src/items/itemRegistry.ts index 208244c..f3880f9 100644 --- a/client/src/items/itemRegistry.ts +++ b/client/src/items/itemRegistry.ts @@ -52,7 +52,7 @@ const DEFAULT_ITEM_TYPE_EDITABLE_PROPERTIES: Record = { dice: ['title', 'sides', 'number'], wheel: ['title', 'spaces'], clock: ['title', 'timeZone', 'use24Hour'], - widget: ['title', 'enabled', 'directional', 'facing', 'emitRange', 'emitVolume', 'emitEffect', 'emitEffectValue', 'useSound', 'emitSound'], + widget: ['title', 'enabled', 'directional', 'facing', 'emitRange', 'emitVolume', 'emitSpeed', 'emitEffect', 'emitEffectValue', 'useSound', 'emitSound'], }; const DEFAULT_ITEM_TYPE_GLOBAL_PROPERTIES: Record> = { @@ -196,6 +196,7 @@ export function itemPropertyLabel(key: string): string { if (key === 'emitRange') return 'emit range'; if (key === 'mediaVolume') return 'media volume'; if (key === 'emitVolume') return 'emit volume'; + if (key === 'emitSpeed') return 'emit speed'; if (key === 'mediaChannel') return 'media channel'; if (key === 'mediaEffect') return 'media effect'; if (key === 'mediaEffectValue') return 'media effect value'; diff --git a/client/src/main.ts b/client/src/main.ts index 528af7f..4c2fa53 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -753,6 +753,7 @@ function inferItemPropertyValueType(item: WorldItem, key: string): string | unde key === 'version' || key === 'mediaVolume' || key === 'emitVolume' || + key === 'emitSpeed' || key === 'mediaEffectValue' || key === 'emitEffectValue' || key === 'facing' || @@ -2158,6 +2159,14 @@ function handleItemPropertyEditModeInput(code: string, key: string, ctrlKey: boo return; } signaling.send({ type: 'item_update', itemId, params: { emitVolume: parsed.value } }); + } else if (propertyKey === 'emitSpeed') { + const parsed = validateNumericItemPropertyInput(item, propertyKey, value, true); + if (!parsed.ok) { + updateStatus(parsed.message); + audio.sfxUiCancel(); + return; + } + signaling.send({ type: 'item_update', itemId, params: { emitSpeed: parsed.value } }); } else if (propertyKey === 'mediaEffect' || propertyKey === 'emitEffect') { const normalized = value.trim().toLowerCase() as EffectId; if (!EFFECT_IDS.has(normalized)) { diff --git a/docs/item-schema.md b/docs/item-schema.md index 7a02557..4d68bb4 100644 --- a/docs/item-schema.md +++ b/docs/item-schema.md @@ -137,6 +137,7 @@ "facing": 0, "emitRange": 15, "emitVolume": 100, + "emitSpeed": 50, "emitEffect": "off", "emitEffectValue": 50, "useSound": "", @@ -149,6 +150,7 @@ - `facing`: number, range `0-360`, precision `0.1`. - `emitRange`: integer, range `1-20`, default `15`. - `emitVolume`: integer, range `0-100`, default `100`. +- `emitSpeed`: integer, range `0-100`, default `50`; maps to playback rate (`0=0.5x`, `50=1.0x`, `100=2.0x`). - `emitEffect`: one of `reverb | echo | flanger | high_pass | low_pass | off`, default `off`. - `emitEffectValue`: number, range `0-100`, precision `0.1`, default `50`. - `useSound`: empty, filename (assumed under `sounds/`), or full URL. diff --git a/docs/item-types.md b/docs/item-types.md index b2e9edb..e74b7c2 100644 --- a/docs/item-types.md +++ b/docs/item-types.md @@ -120,6 +120,7 @@ This is behavior-focused documentation for item types and their defaults. - `facing=0` - `emitRange=15` - `emitVolume=100` + - `emitSpeed=50` - `emitEffect="off"` - `emitEffectValue=50` - `useSound=""` @@ -140,6 +141,7 @@ This is behavior-focused documentation for item types and their defaults. - `facing`: number `0..360` with `0.1` precision - `emitRange`: integer `1..20` - `emitVolume`: integer `0..100` +- `emitSpeed`: integer `0..100` (`0=0.5x`, `50=1.0x`, `100=2.0x`) - `emitEffect`: `reverb | echo | flanger | high_pass | low_pass | off` - `emitEffectValue`: number `0..100` with `0.1` precision - `useSound`: empty, filename (assumed under `sounds/`), or full URL diff --git a/server/app/items/widget.py b/server/app/items/widget.py index 4cfa5f0..0734869 100644 --- a/server/app/items/widget.py +++ b/server/app/items/widget.py @@ -17,6 +17,7 @@ EDITABLE_PROPERTIES: tuple[str, ...] = ( "facing", "emitRange", "emitVolume", + "emitSpeed", "emitEffect", "emitEffectValue", "useSound", @@ -35,6 +36,7 @@ DEFAULT_PARAMS: dict = { "facing": 0, "emitRange": 15, "emitVolume": 100, + "emitSpeed": 50, "emitEffect": "off", "emitEffectValue": 50, "useSound": "", @@ -61,6 +63,11 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = { "tooltip": "Emitted sound volume percent.", "range": {"min": 0, "max": 100, "step": 1}, }, + "emitSpeed": { + "valueType": "number", + "tooltip": "Playback speed/pitch percent for emitted sound. 50 is normal, 0 is half, 100 is double.", + "range": {"min": 0, "max": 100, "step": 1}, + }, "emitEffect": {"valueType": "list", "tooltip": "Effect applied to emitted sound."}, "emitEffectValue": { "valueType": "number", @@ -124,6 +131,14 @@ def validate_update(item: WorldItem, next_params: dict) -> dict: raise ValueError("emitVolume must be between 0 and 100.") next_params["emitVolume"] = emit_volume + try: + emit_speed = int(next_params.get("emitSpeed", item.params.get("emitSpeed", 50))) + except (TypeError, ValueError) as exc: + raise ValueError("emitSpeed must be an integer between 0 and 100.") from exc + if not (0 <= emit_speed <= 100): + raise ValueError("emitSpeed must be between 0 and 100.") + next_params["emitSpeed"] = emit_speed + emit_effect = str(next_params.get("emitEffect", item.params.get("emitEffect", "off"))).strip().lower() if emit_effect not in EFFECT_OPTIONS: raise ValueError("emitEffect must be one of reverb, echo, flanger, high_pass, low_pass, off.") diff --git a/server/tests/test_item_use_cooldown.py b/server/tests/test_item_use_cooldown.py index 3e6c2e6..65e2e7e 100644 --- a/server/tests/test_item_use_cooldown.py +++ b/server/tests/test_item_use_cooldown.py @@ -292,6 +292,7 @@ async def test_widget_update_and_use(monkeypatch: pytest.MonkeyPatch) -> None: "facing": 123.4, "emitRange": 7, "emitVolume": 42, + "emitSpeed": 25, "emitEffect": "reverb", "emitEffectValue": 63.2, "useSound": "ping.ogg", @@ -305,6 +306,7 @@ async def test_widget_update_and_use(monkeypatch: pytest.MonkeyPatch) -> None: assert item.params.get("facing") == 123.4 assert item.params.get("emitRange") == 7 assert item.params.get("emitVolume") == 42 + assert item.params.get("emitSpeed") == 25 assert item.params.get("emitEffect") == "reverb" assert item.params.get("emitEffectValue") == 63.2 assert item.params.get("useSound") == "sounds/ping.ogg" @@ -321,3 +323,10 @@ async def test_widget_update_and_use(monkeypatch: pytest.MonkeyPatch) -> None: ) assert send_payloads[-1].ok is False assert "emitrange must be between 1 and 20" in send_payloads[-1].message.lower() + + await server._handle_message( + client, + json.dumps({"type": "item_update", "itemId": item.id, "params": {"emitSpeed": 101}}), + ) + assert send_payloads[-1].ok is False + assert "emitspeed must be between 0 and 100" in send_payloads[-1].message.lower()