Music working properly!

pull/15/head
wadeaston 2025-04-02 10:46:58 +07:00
parent 708014df00
commit 6a86bcbdc8
2 changed files with 57 additions and 1 deletions

@ -10,6 +10,7 @@ var nav_region: NavigationRegion3D # Single navigation region for all roads
# Construction manager for building residential buildings with workers
var construction_manager: BuildingConstructionManager
# Structure selection sound effect is now handled in game_manager.gd
@export var selector:Node3D # The 'cursor'
@export var selector_container:Node3D # Node that holds a preview of the structure
@ -46,6 +47,8 @@ func _ready():
construction_manager.builder = self
construction_manager.nav_region = nav_region
# Sound effects now handled in game_manager.gd
for structure in structures:
var id = mesh_library.get_last_unused_item_id()
@ -228,6 +231,8 @@ func action_build(gridmap_position):
if mission_id == "3" or (mission_id == "1" and is_residential):
use_worker_construction = true
# Sound effects are handled via game_manager.gd through the structure_placed signal
if is_road:
# For roads, we'll need to track in our data without using the GridMap
# But for now, we won't add it to the GridMap visually, just add to NavRegion3D
@ -293,6 +298,8 @@ func setup_navigation_region():
nav_mesh.agent_radius = 0.25
add_child(nav_region)
# Sound effects are now handled in game_manager.gd
# Rebake navigation mesh to update the navigation data
@ -440,6 +447,8 @@ func update_structure():
else:
# Standard positioning for other structures
_model.position.y += 0.25
# Sound effects are now handled in game_manager.gd
func update_cash():
cash_display.text = "$" + str(map.cash)

@ -2,6 +2,9 @@ extends Node
# This script handles overall game management tasks
var music_player: AudioStreamPlayer
var building_sfx: AudioStreamPlayer
func _ready():
# Reference to the controls panel and HUD
var controls_panel = $CanvasLayer/ControlsPanel
@ -16,7 +19,51 @@ func _ready():
# Connect the closed signal to handle when player closes the controls
controls_panel.closed.connect(_on_controls_panel_closed)
# Set up audio
setup_background_music()
setup_building_sfx()
# Find the builder and connect to it
var builder = get_node_or_null("/root/Main/Builder")
if builder:
builder.structure_placed.connect(_on_structure_placed)
# This function is called when the controls panel is closed
func _on_controls_panel_closed():
print("Controls panel closed by player")
print("Controls panel closed by player")
# Setup background music player
func setup_background_music():
music_player = AudioStreamPlayer.new()
add_child(music_player)
var music = load("res://sounds/jazz_new_orleans.mp3")
if music:
music_player.stream = music
music_player.volume_db = -12 # 25% volume (approx)
music_player.play()
print("Playing background music: jazz_new_orleans.mp3")
else:
print("ERROR: Could not load background music")
# Setup building sound effects
func setup_building_sfx():
building_sfx = AudioStreamPlayer.new()
add_child(building_sfx)
var sfx = load("res://sounds/building_placing.wav")
if sfx:
building_sfx.stream = sfx
building_sfx.volume_db = -5
print("Building placement SFX loaded successfully")
else:
print("ERROR: Could not load building placement SFX")
# Play the building sound effect when a structure is placed
func _on_structure_placed(structure_index, position):
if building_sfx and building_sfx.stream:
if building_sfx.playing:
building_sfx.stop()
building_sfx.play()
print("Playing building placement SFX")