diff --git a/main.gd b/main.gd index f463721..2a5f8e3 100644 --- a/main.gd +++ b/main.gd @@ -17,8 +17,9 @@ var hist := UndoRedo.new() var player: Piece @onready var sound: AudioStreamPlayer = $Sound -var sounds_hit := AudioStreamRandomizer.new() - +@onready var sounds_hit := audio_stream_randomizer_from_dir("res://sfx/hit") +@onready var sounds_undo := audio_stream_randomizer_from_dir("res://sfx/undo") +@onready var sounds_redo := audio_stream_randomizer_from_dir("res://sfx/redo") func _ready() -> void: add_child(board) @@ -28,15 +29,6 @@ func _ready() -> void: $TopLeft.aabb = board.top_left_aabb() $BottomRight.aabb = board.bottom_right_aabb() camera.position = Vector3(player.position.x, camera.position.y, player.position.z) - - sounds_hit.random_pitch = 1.1 - var hit_dir := DirAccess.open("res://sfx/hit") - hit_dir.list_dir_begin() - var file_name := hit_dir.get_next() - while file_name != "": - if file_name.ends_with("ogg"): - sounds_hit.add_stream(-1, load("res://sfx/hit/"+file_name)) - file_name = hit_dir.get_next() func _process(delta: float) -> void: if $TopLeft.is_on_screen() and $BottomRight.is_on_screen(): @@ -53,9 +45,13 @@ func _input(event: InputEvent) -> void: elif event.is_action_pressed("r", true, true): step(Vector2i.RIGHT) elif event.is_action_pressed("undo", true, true): - hist.undo() + if hist.undo(): + sound.stream = sounds_undo + sound.play() elif event.is_action_pressed("redo", true, true): - hist.redo() + if hist.redo(): + sound.stream = sounds_redo + sound.play() elif event.is_action_pressed("restart", true, true): restart() @@ -81,3 +77,15 @@ func step(move: Vector2i): else: sound.stream = sounds_hit sound.play() + +func audio_stream_randomizer_from_dir(dir: String) -> AudioStreamRandomizer: + var stream := AudioStreamRandomizer.new() + stream.random_pitch = 1.1 + var hit_dir := DirAccess.open(dir) + hit_dir.list_dir_begin() + var file_name := hit_dir.get_next() + while file_name != "": + if file_name.ends_with("ogg"): + stream.add_stream(-1, load(dir+"/"+file_name)) + file_name = hit_dir.get_next() + return stream diff --git a/sfx/redo/jingles-saxophone_15.ogg b/sfx/redo/jingles-saxophone_15.ogg new file mode 100644 index 0000000..bb4aedb Binary files /dev/null and b/sfx/redo/jingles-saxophone_15.ogg differ diff --git a/sfx/redo/jingles-saxophone_15.ogg.import b/sfx/redo/jingles-saxophone_15.ogg.import new file mode 100644 index 0000000..265a753 --- /dev/null +++ b/sfx/redo/jingles-saxophone_15.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://yckyg3m66h1u" +path="res://.godot/imported/jingles-saxophone_15.ogg-75960c939c728136300eb69e1176d924.oggvorbisstr" + +[deps] + +source_file="res://sfx/redo/jingles-saxophone_15.ogg" +dest_files=["res://.godot/imported/jingles-saxophone_15.ogg-75960c939c728136300eb69e1176d924.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sfx/undo/jingles-saxophone_16.ogg b/sfx/undo/jingles-saxophone_16.ogg new file mode 100644 index 0000000..2cebcdc Binary files /dev/null and b/sfx/undo/jingles-saxophone_16.ogg differ diff --git a/sfx/undo/jingles-saxophone_16.ogg.import b/sfx/undo/jingles-saxophone_16.ogg.import new file mode 100644 index 0000000..e757218 --- /dev/null +++ b/sfx/undo/jingles-saxophone_16.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://cs2drft1a74sw" +path="res://.godot/imported/jingles-saxophone_16.ogg-2a826dd03c8724fa27e6b96d58aa50df.oggvorbisstr" + +[deps] + +source_file="res://sfx/undo/jingles-saxophone_16.ogg" +dest_files=["res://.godot/imported/jingles-saxophone_16.ogg-2a826dd03c8724fa27e6b96d58aa50df.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4