Files
Cozypaw-Hospital/scripts/autoload/SaveManager.gd
Steven Wroblewski 9a1e30d808 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>
2026-04-17 11:16:04 +02:00

41 lines
983 B
GDScript

## 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()