完善客户端功能并同步差距文档
This commit is contained in:
+17
-3
@@ -14,6 +14,7 @@ const ChannelStatus = preload("res://net/channel_status.gd")
|
||||
const LoadingScreen = preload("res://ui/loading_screen.gd")
|
||||
const CharSelectScreen = preload("res://ui/char_select_screen.gd")
|
||||
const GameScene = preload("res://game_scene.gd")
|
||||
const AppLifecycle = preload("res://app_lifecycle.gd")
|
||||
|
||||
enum { LOGIN, SELECT, GAME }
|
||||
|
||||
@@ -24,15 +25,16 @@ var _assets := ""
|
||||
var _ui: CanvasLayer # 登录 / 选人的临时界面层
|
||||
var _loading: CanvasLayer
|
||||
var _game: Node
|
||||
var _lifecycle: Node # 全流程唯一生命周期协调者
|
||||
var build_game_scene := true # 测试里置 false,只跑状态机不建重场景
|
||||
var _sel_server := 0
|
||||
var _sel_channel := 1
|
||||
var _id := "admin"
|
||||
var _pw := "123456789"
|
||||
var _id := OS.get_environment("MT_ACCOUNT")
|
||||
var _pw := OS.get_environment("MT_PASSWORD")
|
||||
var _chars: Array = []
|
||||
var _mark_redl_after := 0 # guild-mark re-download cooldown (ticks_msec)
|
||||
# MT_AUTOLOGIN=1:进 LOGIN 自动连接,收到角色列表自动选第一个(冒烟 / CI 用)。
|
||||
var auto_login := OS.get_environment("MT_AUTOLOGIN") == "1"
|
||||
var auto_login := OS.get_environment("MT_AUTOLOGIN") == "1" and not _id.is_empty() and not _pw.is_empty()
|
||||
|
||||
func start(assets_root: String = "", injected_client: Node = null) -> void:
|
||||
_assets = assets_root
|
||||
@@ -51,6 +53,13 @@ func start(assets_root: String = "", injected_client: Node = null) -> void:
|
||||
_loading = LoadingScreen.new()
|
||||
add_child(_loading)
|
||||
_loading.setup(client)
|
||||
# §9.3:生命周期属于 AppFlow,而不是会被切屏销毁的 GameScene。
|
||||
# 这样登录、选人、进游戏始终只有一个通知入口;Audio 在 GameScene
|
||||
# 完成装配后再绑定,客户端从 start() 起就已经绑定。
|
||||
_lifecycle = AppLifecycle.new()
|
||||
_lifecycle.name = "AppLifecycle"
|
||||
add_child(_lifecycle)
|
||||
_lifecycle.bind(client)
|
||||
_goto_login()
|
||||
if auto_login:
|
||||
call_deferred("_do_connect")
|
||||
@@ -133,6 +142,9 @@ func _clear_ui() -> void:
|
||||
|
||||
func _goto_login() -> void:
|
||||
_state = LOGIN
|
||||
if _lifecycle:
|
||||
# GameScene 即将释放,不能让生命周期协调者保留悬空 Audio 引用。
|
||||
_lifecycle.bind(client)
|
||||
if _game:
|
||||
_game.queue_free()
|
||||
_game = null
|
||||
@@ -165,6 +177,8 @@ func _goto_game() -> void:
|
||||
add_child(_game)
|
||||
if _game.has_method("setup"):
|
||||
await _game.setup(client, _assets) # 协程:分帧,不阻塞 socket
|
||||
if _lifecycle and is_instance_valid(_game) and _game.has_method("lifecycle_audio"):
|
||||
_lifecycle.bind(client, _game.lifecycle_audio())
|
||||
if _loading:
|
||||
_loading.hide_screen()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user