Make radio emit range editable (5-20)
This commit is contained in:
@@ -16,7 +16,7 @@ ITEM_TYPE_LABELS: dict[ItemType, str] = {
|
||||
RADIO_EFFECT_OPTIONS: tuple[str, ...] = ("reverb", "echo", "flanger", "high_pass", "low_pass", "off")
|
||||
RADIO_CHANNEL_OPTIONS: tuple[str, ...] = ("stereo", "mono", "left", "right")
|
||||
ITEM_TYPE_EDITABLE_PROPERTIES: dict[ItemType, tuple[str, ...]] = {
|
||||
"radio_station": ("title", "streamUrl", "enabled", "channel", "volume", "effect", "effectValue", "facing"),
|
||||
"radio_station": ("title", "streamUrl", "enabled", "channel", "volume", "effect", "effectValue", "facing", "emitRange"),
|
||||
"dice": ("title", "sides", "number"),
|
||||
"wheel": ("title", "spaces"),
|
||||
"clock": ("title", "timeZone", "use24Hour"),
|
||||
@@ -86,7 +86,16 @@ ITEM_DEFINITIONS: dict[ItemType, ItemDefinition] = {
|
||||
capabilities=("editable", "carryable", "deletable", "usable"),
|
||||
use_sound=None,
|
||||
emit_sound=None,
|
||||
default_params={"streamUrl": "", "enabled": True, "channel": "stereo", "volume": 50, "effect": "off", "effectValue": 50, "facing": 0},
|
||||
default_params={
|
||||
"streamUrl": "",
|
||||
"enabled": True,
|
||||
"channel": "stereo",
|
||||
"volume": 50,
|
||||
"effect": "off",
|
||||
"effectValue": 50,
|
||||
"facing": 0,
|
||||
"emitRange": 20,
|
||||
},
|
||||
emit_range=20,
|
||||
directional=True,
|
||||
),
|
||||
|
||||
@@ -112,6 +112,14 @@ def _validate_radio_update(item: WorldItem, next_params: dict) -> dict:
|
||||
if not (0 <= facing <= 360):
|
||||
raise ValueError("facing must be between 0 and 360.")
|
||||
next_params["facing"] = round(facing, 1)
|
||||
|
||||
try:
|
||||
emit_range = int(next_params.get("emitRange", item.params.get("emitRange", 20)))
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValueError("emitRange must be an integer between 5 and 20.") from exc
|
||||
if not (5 <= emit_range <= 20):
|
||||
raise ValueError("emitRange must be between 5 and 20.")
|
||||
next_params["emitRange"] = emit_range
|
||||
return next_params
|
||||
|
||||
|
||||
|
||||
@@ -132,6 +132,20 @@ async def test_radio_channel_update_validates(monkeypatch: pytest.MonkeyPatch) -
|
||||
assert send_payloads[-1].ok is False
|
||||
assert "facing must be between 0 and 360" in send_payloads[-1].message.lower()
|
||||
|
||||
await server._handle_message(
|
||||
client,
|
||||
json.dumps({"type": "item_update", "itemId": item.id, "params": {"emitRange": 12}}),
|
||||
)
|
||||
assert send_payloads[-1].ok is True
|
||||
assert item.params.get("emitRange") == 12
|
||||
|
||||
await server._handle_message(
|
||||
client,
|
||||
json.dumps({"type": "item_update", "itemId": item.id, "params": {"emitRange": 4}}),
|
||||
)
|
||||
assert send_payloads[-1].ok is False
|
||||
assert "emitrange must be between 5 and 20" in send_payloads[-1].message.lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clock_use_reports_time_without_use_sound_packet(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
Reference in New Issue
Block a user