grunk/src/equipment/mp3_player/mp3_player.gd

47 lines
1.1 KiB
GDScript3
Raw Normal View History

2025-06-20 12:42:04 -06:00
extends Tool
## Pump up the jamz!
2025-06-26 23:34:01 -06:00
@onready var mp3_controller: MP3Controller = %MP3Controller
2025-06-27 12:18:47 -06:00
@onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer
func _ready() -> void:
World.instance.manager.mp3_collected.connect(_on_mp3_collected)
2025-06-26 23:34:01 -06:00
2025-06-20 12:42:04 -06:00
func unlocked() -> bool:
return World.instance.manager.mp3_player_unlocked
2025-06-26 23:34:01 -06:00
func fire() -> void:
if not firing:
firing = true
mp3_controller.select()
func switch_mode() -> void:
mp3_controller.cancel()
2025-06-27 12:18:47 -06:00
func _on_mp3_collected(_track: MP3Track) -> void:
# TODO we may want to dynamically build the player tracklist
# rather than rebuilding the whole thing each time a track is collected
var mp3_list: Array[String] = []
mp3_list.assign(
World.instance.manager.mp3_collection.map(func(mp3: MP3Track) -> String: return mp3.title)
)
mp3_controller.set_track_list(mp3_list)
func pause_playback() -> void:
audio_stream_player.stream_paused = true
func resume_playback() -> void:
audio_stream_player.stream_paused = false
func select_track(idx: int) -> void:
audio_stream_player.stream = World.instance.manager.mp3_collection[idx].track
audio_stream_player.play()