Add emit reverse option and retune echo/dice output
This commit is contained in:
@@ -101,6 +101,10 @@ GLOBAL_ITEM_PROPERTY_METADATA: dict[str, dict[str, object]] = {
|
||||
"tooltip": "Global emitted sound tempo percent. 50 is normal.",
|
||||
"range": {"min": 0, "max": 100, "step": 1},
|
||||
},
|
||||
"emitSoundReverse": {
|
||||
"valueType": "boolean",
|
||||
"tooltip": "Global emitted sound reverse flag.",
|
||||
},
|
||||
}
|
||||
|
||||
ITEM_TYPE_PROPERTY_METADATA: dict[ItemType, dict[str, dict[str, object]]] = {
|
||||
@@ -136,4 +140,5 @@ def get_item_global_properties(item_type: ItemType) -> dict[str, str | int | boo
|
||||
"directional": bool(definition.directional),
|
||||
"emitSoundSpeed": 50,
|
||||
"emitSoundTempo": 50,
|
||||
"emitSoundReverse": False,
|
||||
}
|
||||
|
||||
@@ -62,8 +62,12 @@ def use_item(item: WorldItem, nickname: str, _clock_formatter: Callable[[dict],
|
||||
rolls = [random.randint(1, sides) for _ in range(number)]
|
||||
total = sum(rolls)
|
||||
rolls_text = ", ".join(str(value) for value in rolls)
|
||||
if number == 1:
|
||||
return ItemUseResult(
|
||||
self_message=f"You rolled {item.title}: {rolls_text}.",
|
||||
others_message=f"{nickname} rolled {item.title}: {rolls_text}.",
|
||||
)
|
||||
return ItemUseResult(
|
||||
self_message=f"You rolled {item.title}: {rolls_text} (total {total}).",
|
||||
others_message=f"{nickname} rolled {item.title}: {rolls_text} (total {total}).",
|
||||
)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ EDITABLE_PROPERTIES: tuple[str, ...] = (
|
||||
"emitVolume",
|
||||
"emitSoundSpeed",
|
||||
"emitSoundTempo",
|
||||
"emitSoundReverse",
|
||||
"emitEffect",
|
||||
"emitEffectValue",
|
||||
"useSound",
|
||||
@@ -39,6 +40,7 @@ DEFAULT_PARAMS: dict = {
|
||||
"emitVolume": 100,
|
||||
"emitSoundSpeed": 50,
|
||||
"emitSoundTempo": 50,
|
||||
"emitSoundReverse": False,
|
||||
"emitEffect": "off",
|
||||
"emitEffectValue": 50,
|
||||
"useSound": "",
|
||||
@@ -75,6 +77,10 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = {
|
||||
"tooltip": "Playback tempo percent for emitted sound. 50 is normal, 0 is half, 100 is double. Using speed and tempo together may sound weird.",
|
||||
"range": {"min": 0, "max": 100, "step": 1},
|
||||
},
|
||||
"emitSoundReverse": {
|
||||
"valueType": "boolean",
|
||||
"tooltip": "Play emitted sound in reverse.",
|
||||
},
|
||||
"emitEffect": {"valueType": "list", "tooltip": "Effect applied to emitted sound."},
|
||||
"emitEffectValue": {
|
||||
"valueType": "number",
|
||||
@@ -154,6 +160,12 @@ def validate_update(item: WorldItem, next_params: dict) -> dict:
|
||||
raise ValueError("emitSoundTempo must be between 0 and 100.")
|
||||
next_params["emitSoundTempo"] = emit_tempo
|
||||
|
||||
emit_reverse = parse_bool_like(
|
||||
next_params.get("emitSoundReverse", item.params.get("emitSoundReverse", False)),
|
||||
default=False,
|
||||
)
|
||||
next_params["emitSoundReverse"] = emit_reverse
|
||||
|
||||
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.")
|
||||
|
||||
@@ -294,6 +294,7 @@ async def test_widget_update_and_use(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"emitVolume": 42,
|
||||
"emitSoundSpeed": 25,
|
||||
"emitSoundTempo": 60,
|
||||
"emitSoundReverse": True,
|
||||
"emitEffect": "reverb",
|
||||
"emitEffectValue": 63.2,
|
||||
"useSound": "ping.ogg",
|
||||
@@ -309,6 +310,7 @@ async def test_widget_update_and_use(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
assert item.params.get("emitVolume") == 42
|
||||
assert item.params.get("emitSoundSpeed") == 25
|
||||
assert item.params.get("emitSoundTempo") == 60
|
||||
assert item.params.get("emitSoundReverse") is True
|
||||
assert item.params.get("emitEffect") == "reverb"
|
||||
assert item.params.get("emitEffectValue") == 63.2
|
||||
assert item.params.get("useSound") == "sounds/ping.ogg"
|
||||
@@ -339,3 +341,10 @@ async def test_widget_update_and_use(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
)
|
||||
assert send_payloads[-1].ok is False
|
||||
assert "emitsoundtempo must be between 0 and 100" in send_payloads[-1].message.lower()
|
||||
|
||||
await server._handle_message(
|
||||
client,
|
||||
json.dumps({"type": "item_update", "itemId": item.id, "params": {"emitSoundReverse": "off"}}),
|
||||
)
|
||||
assert send_payloads[-1].ok is True
|
||||
assert item.params.get("emitSoundReverse") is False
|
||||
|
||||
Reference in New Issue
Block a user