Skip to content

Commit d40e5ae

Browse files
committed
feat: add ability to toggle sound via hotkey
1 parent 8fc061a commit d40e5ae

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

project.godot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ smaller={
192192
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
193193
]
194194
}
195+
sound_toggle={
196+
"deadzone": 0.5,
197+
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":77,"unicode":0,"echo":false,"script":null)
198+
]
199+
}
195200

196201
[rendering]
197202

scenes/levels.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ margin_right = 263.0
4848

4949
[node name="Label" type="Label" parent="LevelSelect/LevelsBorder"]
5050
margin_left = 20.0
51-
margin_top = 577.0
51+
margin_top = 555.0
5252
margin_right = 283.0
5353
margin_bottom = 640.0
5454
size_flags_vertical = 8
55-
text = "Use the WASD keys to adjust the size and speed of the simulation."
55+
text = "Use the WASD keys to adjust the size and speed of the simulation, and M to toggle sound."
5656
autowrap = true
5757

5858
[node name="Preview" type="VBoxContainer" parent="LevelSelect"]

views/array_sound.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ func _init():
3030
func triangle(x):
3131
"""Generate a triangle wave from the given phase."""
3232
return 2 / PI * asin(sin(PI * x))
33+
34+
func _input(event):
35+
if event.is_action_pressed("sound_toggle"):
36+
# Prevent event from propagating to ComparisonSort trigger
37+
get_tree().set_input_as_handled()
38+
var bus = AudioServer.get_bus_index("Master")
39+
AudioServer.set_bus_mute(bus, not AudioServer.is_bus_mute(bus))

0 commit comments

Comments
 (0)