- 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>
58 lines
1.5 KiB
GDScript
58 lines
1.5 KiB
GDScript
## GameState — global game state: character positions, object states, current room.
|
|
extends Node
|
|
|
|
signal state_changed
|
|
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:
|
|
return _character_positions.get(id, Vector2.ZERO)
|
|
|
|
|
|
func set_character_position(id: String, pos: Vector2) -> void:
|
|
_character_positions[id] = pos
|
|
character_moved.emit(id, pos)
|
|
state_changed.emit()
|
|
|
|
|
|
func get_object_state(id: String) -> String:
|
|
return _object_states.get(id, "idle")
|
|
|
|
|
|
func set_object_state(id: String, state: String) -> void:
|
|
_object_states[id] = state
|
|
state_changed.emit()
|
|
|
|
|
|
func get_save_data() -> Dictionary:
|
|
return {
|
|
"character_positions": _character_positions,
|
|
"object_states": _object_states,
|
|
"current_room": current_room,
|
|
"music_volume": music_volume,
|
|
"sfx_volume": sfx_volume,
|
|
}
|
|
|
|
|
|
func apply_save_data(data: Dictionary) -> void:
|
|
if data.has("character_positions"):
|
|
_character_positions = data["character_positions"]
|
|
if data.has("object_states"):
|
|
_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"]
|