Add emit sound tempo and global emit speed/tempo defaults

This commit is contained in:
Jage9
2026-02-21 23:17:18 -05:00
parent d3a98ef1ea
commit 9571a3c14d
9 changed files with 88 additions and 11 deletions

View File

@@ -91,6 +91,16 @@ GLOBAL_ITEM_PROPERTY_METADATA: dict[str, dict[str, object]] = {
"useCooldownMs": {"valueType": "number", "tooltip": "Global cooldown in milliseconds between uses for this item type."},
"emitRange": {"valueType": "number", "tooltip": "Maximum distance in squares where emitted audio can be heard."},
"directional": {"valueType": "boolean", "tooltip": "Whether emitted audio favors the item's facing direction."},
"emitSoundSpeed": {
"valueType": "number",
"tooltip": "Global emitted sound speed/pitch percent. 50 is normal.",
"range": {"min": 0, "max": 100, "step": 1},
},
"emitSoundTempo": {
"valueType": "number",
"tooltip": "Global emitted sound tempo percent. 50 is normal.",
"range": {"min": 0, "max": 100, "step": 1},
},
}
ITEM_TYPE_PROPERTY_METADATA: dict[ItemType, dict[str, dict[str, object]]] = {
@@ -124,4 +134,6 @@ def get_item_global_properties(item_type: ItemType) -> dict[str, str | int | boo
"useCooldownMs": get_item_use_cooldown_ms(item_type),
"emitRange": definition.emit_range if isinstance(definition.emit_range, int) and definition.emit_range > 0 else 15,
"directional": bool(definition.directional),
"emitSoundSpeed": 50,
"emitSoundTempo": 50,
}

View File

@@ -18,6 +18,7 @@ EDITABLE_PROPERTIES: tuple[str, ...] = (
"emitRange",
"emitVolume",
"emitSoundSpeed",
"emitSoundTempo",
"emitEffect",
"emitEffectValue",
"useSound",
@@ -37,6 +38,7 @@ DEFAULT_PARAMS: dict = {
"emitRange": 15,
"emitVolume": 100,
"emitSoundSpeed": 50,
"emitSoundTempo": 50,
"emitEffect": "off",
"emitEffectValue": 50,
"useSound": "",
@@ -68,6 +70,11 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = {
"tooltip": "Playback speed/pitch percent for emitted sound. 50 is normal, 0 is half, 100 is double.",
"range": {"min": 0, "max": 100, "step": 1},
},
"emitSoundTempo": {
"valueType": "number",
"tooltip": "Playback tempo 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",
@@ -139,6 +146,14 @@ def validate_update(item: WorldItem, next_params: dict) -> dict:
raise ValueError("emitSoundSpeed must be between 0 and 100.")
next_params["emitSoundSpeed"] = emit_speed
try:
emit_tempo = int(next_params.get("emitSoundTempo", item.params.get("emitSoundTempo", 50)))
except (TypeError, ValueError) as exc:
raise ValueError("emitSoundTempo must be an integer between 0 and 100.") from exc
if not (0 <= emit_tempo <= 100):
raise ValueError("emitSoundTempo must be between 0 and 100.")
next_params["emitSoundTempo"] = emit_tempo
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.")