Split media vs emit volume for radio and widget

This commit is contained in:
Jage9
2026-02-21 22:38:48 -05:00
parent bb36a007e2
commit a2c1306b46
10 changed files with 72 additions and 24 deletions

View File

@@ -15,7 +15,7 @@ EDITABLE_PROPERTIES: tuple[str, ...] = (
"streamUrl",
"enabled",
"channel",
"volume",
"mediaVolume",
"effect",
"effectValue",
"facing",
@@ -32,7 +32,7 @@ DEFAULT_PARAMS: dict = {
"streamUrl": "",
"enabled": True,
"channel": "stereo",
"volume": 50,
"mediaVolume": 50,
"effect": "off",
"effectValue": 50,
"facing": 0,
@@ -47,9 +47,9 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = {
"streamUrl": {"valueType": "text", "tooltip": "Audio stream URL used by this radio."},
"enabled": {"valueType": "boolean", "tooltip": "Turns playback on or off for this radio."},
"channel": {"valueType": "list", "tooltip": "Select how the station audio channels are rendered."},
"volume": {
"mediaVolume": {
"valueType": "number",
"tooltip": "Playback volume percent for this radio.",
"tooltip": "Playback media volume percent for this radio.",
"range": {"min": 0, "max": 100, "step": 1},
},
"effect": {"valueType": "list", "tooltip": "Select the active radio effect."},
@@ -100,12 +100,12 @@ def validate_update(item: WorldItem, next_params: dict) -> dict:
next_params["enabled"] = enabled
try:
volume = int(next_params.get("volume", 50))
media_volume = int(next_params.get("mediaVolume", 50))
except (TypeError, ValueError) as exc:
raise ValueError("volume must be a number.") from exc
if not (0 <= volume <= 100):
raise ValueError("volume must be between 0 and 100.")
next_params["volume"] = volume
raise ValueError("mediaVolume must be a number.") from exc
if not (0 <= media_volume <= 100):
raise ValueError("mediaVolume must be between 0 and 100.")
next_params["mediaVolume"] = media_volume
effect = str(next_params.get("effect", "off")).strip().lower()
if effect not in EFFECT_OPTIONS:
@@ -153,4 +153,3 @@ def use_item(item: WorldItem, nickname: str, _clock_formatter: Callable[[dict],
others_message=f"{nickname} turns {state_text} {item.title}.",
updated_params={**item.params, "enabled": next_enabled},
)

View File

@@ -10,7 +10,16 @@ from .helpers import parse_bool_like, toggle_bool_param
LABEL = "widget"
TOOLTIP = "A basic item. Make it a beacon or whatever you want."
EDITABLE_PROPERTIES: tuple[str, ...] = ("title", "enabled", "directional", "facing", "emitRange", "useSound", "emitSound")
EDITABLE_PROPERTIES: tuple[str, ...] = (
"title",
"enabled",
"directional",
"facing",
"emitRange",
"emitVolume",
"useSound",
"emitSound",
)
CAPABILITIES: tuple[str, ...] = ("editable", "carryable", "deletable", "usable")
USE_SOUND: str | None = None
EMIT_SOUND: str | None = None
@@ -23,6 +32,7 @@ DEFAULT_PARAMS: dict = {
"directional": False,
"facing": 0,
"emitRange": 15,
"emitVolume": 100,
"useSound": "",
"emitSound": "",
}
@@ -41,6 +51,11 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = {
"tooltip": "Maximum distance in squares for emitted sound.",
"range": {"min": 1, "max": 20, "step": 1},
},
"emitVolume": {
"valueType": "number",
"tooltip": "Emitted sound volume percent.",
"range": {"min": 0, "max": 100, "step": 1},
},
"useSound": {"valueType": "sound", "tooltip": "Sound played on use. Filename assumes sounds folder, or use full URL."},
"emitSound": {"valueType": "sound", "tooltip": "Looping emitted sound. Filename assumes sounds folder, or use full URL."},
}
@@ -90,6 +105,14 @@ def validate_update(item: WorldItem, next_params: dict) -> dict:
raise ValueError("emitRange must be between 1 and 20.")
next_params["emitRange"] = emit_range
try:
emit_volume = int(next_params.get("emitVolume", item.params.get("emitVolume", 100)))
except (TypeError, ValueError) as exc:
raise ValueError("emitVolume must be an integer between 0 and 100.") from exc
if not (0 <= emit_volume <= 100):
raise ValueError("emitVolume must be between 0 and 100.")
next_params["emitVolume"] = emit_volume
next_params["useSound"] = _normalize_sound_value(next_params.get("useSound", item.params.get("useSound", "")))
next_params["emitSound"] = _normalize_sound_value(next_params.get("emitSound", item.params.get("emitSound", "")))
return next_params