feat(poc): implement Sprint 1 proof of concept
- project.godot with autoload configuration - Reception room with placeholder visuals - Draggable Character with DragDropComponent - Interactive flower object with bounce animation - GameState, SaveManager, AudioManager, InputManager autoloads - HUD with back button and music toggle Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
40
scripts/autoload/SaveManager.gd
Normal file
40
scripts/autoload/SaveManager.gd
Normal file
@@ -0,0 +1,40 @@
|
||||
## SaveManager — persists game state as JSON to user://savegame.json, auto-saves on state_changed.
|
||||
extends Node
|
||||
|
||||
const SAVE_PATH: String = "user://savegame.json"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
GameState.state_changed.connect(_on_state_changed)
|
||||
|
||||
|
||||
func save_game() -> void:
|
||||
var data: Dictionary = GameState.get_save_data()
|
||||
var file: FileAccess = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
||||
if file == null:
|
||||
return
|
||||
file.store_string(JSON.stringify(data))
|
||||
file.close()
|
||||
|
||||
|
||||
func load_game() -> void:
|
||||
if not FileAccess.file_exists(SAVE_PATH):
|
||||
return
|
||||
var file: FileAccess = FileAccess.open(SAVE_PATH, FileAccess.READ)
|
||||
if file == null:
|
||||
return
|
||||
var raw: String = file.get_as_text()
|
||||
file.close()
|
||||
var parsed = JSON.parse_string(raw)
|
||||
if parsed is Dictionary:
|
||||
GameState.apply_save_data(parsed)
|
||||
|
||||
|
||||
func reset_game() -> void:
|
||||
if FileAccess.file_exists(SAVE_PATH):
|
||||
DirAccess.remove_absolute(SAVE_PATH)
|
||||
GameState.apply_save_data({})
|
||||
|
||||
|
||||
func _on_state_changed() -> void:
|
||||
save_game()
|
||||
Reference in New Issue
Block a user