Restore useSound and add looping spatial emitSound
This commit is contained in:
@@ -53,6 +53,7 @@ CLOCK_TIME_ZONE_OPTIONS: tuple[str, ...] = (
|
||||
class ItemDefinition:
|
||||
default_title: str
|
||||
capabilities: tuple[str, ...]
|
||||
use_sound: str | None
|
||||
emit_sound: str | None
|
||||
default_params: dict
|
||||
use_cooldown_ms: int = 1000
|
||||
@@ -62,25 +63,29 @@ ITEM_DEFINITIONS: dict[ItemType, ItemDefinition] = {
|
||||
"radio_station": ItemDefinition(
|
||||
default_title="radio",
|
||||
capabilities=("editable", "carryable", "deletable", "usable"),
|
||||
use_sound=None,
|
||||
emit_sound=None,
|
||||
default_params={"streamUrl": "", "enabled": True, "channel": "stereo", "volume": 50, "effect": "off", "effectValue": 50},
|
||||
),
|
||||
"dice": ItemDefinition(
|
||||
default_title="Dice",
|
||||
capabilities=("editable", "carryable", "deletable", "usable"),
|
||||
emit_sound="sounds/roll.ogg",
|
||||
use_sound="sounds/roll.ogg",
|
||||
emit_sound=None,
|
||||
default_params={"sides": 6, "number": 2},
|
||||
),
|
||||
"wheel": ItemDefinition(
|
||||
default_title="wheel",
|
||||
capabilities=("editable", "carryable", "deletable", "usable"),
|
||||
emit_sound="sounds/spin.ogg",
|
||||
use_sound="sounds/spin.ogg",
|
||||
emit_sound=None,
|
||||
default_params={"spaces": "yes, no"},
|
||||
use_cooldown_ms=4000,
|
||||
),
|
||||
"clock": ItemDefinition(
|
||||
default_title="clock",
|
||||
capabilities=("editable", "carryable", "deletable", "usable"),
|
||||
use_sound=None,
|
||||
emit_sound="sounds/clock.ogg",
|
||||
default_params={"timeZone": CLOCK_DEFAULT_TIME_ZONE, "use24Hour": False},
|
||||
),
|
||||
|
||||
@@ -39,6 +39,7 @@ class ItemService:
|
||||
updatedAt=now,
|
||||
version=1,
|
||||
capabilities=list(item_def.capabilities),
|
||||
useSound=item_def.use_sound,
|
||||
emitSound=item_def.emit_sound,
|
||||
params=deepcopy(item_def.default_params),
|
||||
carrierId=None,
|
||||
@@ -95,6 +96,7 @@ class ItemService:
|
||||
updatedAt=persisted.updatedAt,
|
||||
version=persisted.version,
|
||||
capabilities=list(item_def.capabilities),
|
||||
useSound=item_def.use_sound,
|
||||
emitSound=item_def.emit_sound,
|
||||
params=persisted.params,
|
||||
carrierId=persisted.carrierId,
|
||||
|
||||
@@ -161,6 +161,7 @@ class WorldItem(BaseModel):
|
||||
updatedAt: int
|
||||
version: int
|
||||
capabilities: list[str]
|
||||
useSound: str | None = None
|
||||
emitSound: str | None = None
|
||||
params: dict
|
||||
carrierId: str | None = None
|
||||
|
||||
@@ -548,12 +548,12 @@ class SignalingServer:
|
||||
BroadcastChatMessagePacket(type="chat_message", message=others_message, system=True),
|
||||
exclude=client.websocket,
|
||||
)
|
||||
if item.emitSound:
|
||||
if item.useSound:
|
||||
await self._broadcast(
|
||||
ItemUseSoundPacket(
|
||||
type="item_use_sound",
|
||||
itemId=item.id,
|
||||
sound=item.emitSound,
|
||||
sound=item.useSound,
|
||||
x=item.x,
|
||||
y=item.y,
|
||||
)
|
||||
|
||||
@@ -27,9 +27,11 @@ def test_item_persistence_omits_global_type_properties(tmp_path: Path) -> None:
|
||||
assert isinstance(saved, list)
|
||||
assert len(saved) == 1
|
||||
assert "capabilities" not in saved[0]
|
||||
assert "useSound" not in saved[0]
|
||||
assert "emitSound" not in saved[0]
|
||||
|
||||
reloaded = ItemService(state_file=state_file)
|
||||
loaded_item = reloaded.items[item.id]
|
||||
assert loaded_item.emitSound == "sounds/roll.ogg"
|
||||
assert loaded_item.useSound == "sounds/roll.ogg"
|
||||
assert loaded_item.emitSound is None
|
||||
assert "usable" in loaded_item.capabilities
|
||||
|
||||
@@ -120,7 +120,7 @@ async def test_radio_channel_update_validates(monkeypatch: pytest.MonkeyPatch) -
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clock_use_reports_time_and_emits_sound(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
async def test_clock_use_reports_time_without_use_sound_packet(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
server = SignalingServer("127.0.0.1", 8765, None, None)
|
||||
ws = _fake_ws()
|
||||
client = ClientConnection(websocket=ws, id="u1", nickname="tester", x=5, y=6)
|
||||
@@ -146,7 +146,7 @@ async def test_clock_use_reports_time_and_emits_sound(monkeypatch: pytest.Monkey
|
||||
|
||||
assert send_payloads[-1].ok is True
|
||||
assert send_payloads[-1].message == f"{item.title} says 2:15 PM."
|
||||
assert any(getattr(packet, "type", "") == "item_use_sound" for packet in broadcast_payloads)
|
||||
assert not any(getattr(packet, "type", "") == "item_use_sound" for packet in broadcast_payloads)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user