fix(core): resolve review findings in Sprint 3-4
- Fix SaveManager reset_game to use DirAccess.remove correctly - Add null check for FileAccess.open in save_game - Fix AudioManager crossfade tween callback chain - Replace fragile absolute HUD path with relative onready - Guard character position save against empty id - Add GameState.has_character_position helper - Emit room_changed signal after tween completes - Add target_floor validation in ElevatorButton - Persist audio settings via GameState - Add class_name to RoomNavigator, AudioManager, HUD Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
## AudioManager — music playback with cross-fade, SFX playback, volume control.
|
||||
extends Node
|
||||
class_name AudioManager extends Node
|
||||
|
||||
const DEFAULT_MUSIC_VOLUME: float = 0.6
|
||||
const CROSSFADE_DURATION: float = 1.0
|
||||
@@ -31,13 +31,13 @@ func play_music(stream: AudioStream) -> void:
|
||||
next_player.stream = stream
|
||||
next_player.volume_db = linear_to_db(0.0)
|
||||
next_player.play()
|
||||
var prev_player: AudioStreamPlayer = _active_player
|
||||
_active_player = next_player
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(_active_player, "volume_db", linear_to_db(0.0), CROSSFADE_DURATION)
|
||||
tween.tween_property(prev_player, "volume_db", linear_to_db(0.0), CROSSFADE_DURATION)
|
||||
tween.tween_property(next_player, "volume_db", linear_to_db(_music_volume), CROSSFADE_DURATION)
|
||||
var prev_player: AudioStreamPlayer = _active_player
|
||||
tween.tween_callback(prev_player.stop).set_delay(CROSSFADE_DURATION)
|
||||
_active_player = next_player
|
||||
tween.chain().tween_callback(prev_player.stop)
|
||||
|
||||
|
||||
func play_sfx(stream: AudioStream) -> void:
|
||||
|
||||
@@ -7,6 +7,12 @@ signal character_moved(character_id: String, position: Vector2)
|
||||
var _character_positions: Dictionary = {}
|
||||
var _object_states: Dictionary = {}
|
||||
var current_room: String = "reception"
|
||||
var music_volume: float = 0.6
|
||||
var sfx_volume: float = 1.0
|
||||
|
||||
|
||||
func has_character_position(id: String) -> bool:
|
||||
return _character_positions.has(id)
|
||||
|
||||
|
||||
func get_character_position(id: String) -> Vector2:
|
||||
@@ -33,6 +39,8 @@ func get_save_data() -> Dictionary:
|
||||
"character_positions": _character_positions,
|
||||
"object_states": _object_states,
|
||||
"current_room": current_room,
|
||||
"music_volume": music_volume,
|
||||
"sfx_volume": sfx_volume,
|
||||
}
|
||||
|
||||
|
||||
@@ -43,3 +51,7 @@ func apply_save_data(data: Dictionary) -> void:
|
||||
_object_states = data["object_states"]
|
||||
if data.has("current_room"):
|
||||
current_room = data["current_room"]
|
||||
if data.has("music_volume"):
|
||||
music_volume = data["music_volume"]
|
||||
if data.has("sfx_volume"):
|
||||
sfx_volume = data["sfx_volume"]
|
||||
|
||||
@@ -12,6 +12,7 @@ func save_game() -> void:
|
||||
var data: Dictionary = GameState.get_save_data()
|
||||
var file: FileAccess = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
||||
if file == null:
|
||||
push_error("SaveManager: cannot open save file for writing")
|
||||
return
|
||||
file.store_string(JSON.stringify(data))
|
||||
file.close()
|
||||
@@ -32,7 +33,9 @@ func load_game() -> void:
|
||||
|
||||
func reset_game() -> void:
|
||||
if FileAccess.file_exists(SAVE_PATH):
|
||||
DirAccess.remove_absolute(SAVE_PATH)
|
||||
var dir: DirAccess = DirAccess.open("user://")
|
||||
if dir != null:
|
||||
dir.remove("savegame.json")
|
||||
GameState.apply_save_data({})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user