51 lines
1.2 KiB
GDScript
51 lines
1.2 KiB
GDScript
extends Node
|
|
|
|
# 游戏管理器 - 全局游戏状态管理
|
|
# 单例模式,管理游戏的整体状态和生命周期
|
|
|
|
signal game_state_changed(new_state: GameState)
|
|
|
|
enum GameState {
|
|
LOADING, # 加载中
|
|
AUTH, # 认证状态
|
|
MAIN_MENU, # 主菜单
|
|
IN_GAME, # 游戏中
|
|
PAUSED, # 暂停
|
|
SETTINGS # 设置
|
|
}
|
|
|
|
var current_state: GameState = GameState.LOADING
|
|
var previous_state: GameState = GameState.LOADING
|
|
var current_user: String = ""
|
|
var game_version: String = "1.0.0"
|
|
|
|
func _ready():
|
|
print("GameManager 初始化完成")
|
|
change_state(GameState.AUTH)
|
|
|
|
func change_state(new_state: GameState):
|
|
if current_state == new_state:
|
|
return
|
|
|
|
previous_state = current_state
|
|
current_state = new_state
|
|
|
|
print("游戏状态变更: ", GameState.keys()[previous_state], " -> ", GameState.keys()[current_state])
|
|
game_state_changed.emit(new_state)
|
|
|
|
func get_current_state() -> GameState:
|
|
return current_state
|
|
|
|
func get_previous_state() -> GameState:
|
|
return previous_state
|
|
|
|
func set_current_user(username: String):
|
|
current_user = username
|
|
print("当前用户设置为: ", username)
|
|
|
|
func get_current_user() -> String:
|
|
return current_user
|
|
|
|
func is_user_logged_in() -> bool:
|
|
return not current_user.is_empty()
|