Files
ImmortalSect/src/Core/GameState.gd
T

53 lines
1.5 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 全局游戏状态(Autoload 单例)。
## 负责场景间参数传递与会话状态管理,不持有游戏内数据。
extends Node
## 进入游戏的方式。
enum GameMode { NEW_GAME, LOAD_GAME }
## 当前进入游戏的方式。
var mode: GameMode = GameMode.NEW_GAME
## 当前存档组 ID(两级存档第一级,SaveSystem 分配)。
var profile_id: int = 0
## 要加载的槽位文件名(仅 LOAD_GAME 时有效,如 "auto"/"slot_1754734800")。
var save_slot: String = ""
# 游戏内时间(12 月 × 30 天 = 360 天/年),实际推进由 TimeSystem 负责
var year: int = 1 # 年
var month: int = 1 # 月(1-12
func _ready() -> void:
SaveSystem.register_saver(_to_save_dict)
## 提供存档数据:key 为 "game_time",值是游戏时间字段
func _to_save_dict() -> Dictionary:
return {
"game_time": {
"year": year,
"month": month,
},
}
## 读档恢复(MainGame 在 load 后调用 GameState.load_from_dict(data)
func load_from_dict(d: Dictionary) -> void:
var t: Dictionary = d.get("game_time", {})
year = int(t.get("year", 1))
month = int(t.get("month", 1))
## 请求开始新游戏。
## @param pid: 新存档组 ID(主菜单创建)
func request_new_game(pid: int) -> void:
mode = GameMode.NEW_GAME
profile_id = pid
save_slot = ""
year = 1
month = 1
## 请求加载指定存档。
## @param pid: 存档组 ID
## @param slot_name: 槽位文件名(不含 .json
func request_load_game(pid: int, slot_name: String) -> void:
mode = GameMode.LOAD_GAME
profile_id = pid
save_slot = slot_name