Files
agame/tests/test_net_replication.gd
T
2026-09-22 16:56:35 +08:00

55 lines
2.0 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.
@tool
extends McpTestSuite
## 回归测试:Player 的同步配置必须真的被解析成条目。
##
## 这是一处典型的「静默失效」:如果 .tres 里的键名写错,或 replication_mode
## 落到 NEVER,远端玩家会僵在原地不动,而且不打任何错误。用测试钉住它。
const CONFIG_PATH := "res://player/player_sync.tres"
const PLAYER_SCENE_PATH := "res://player/player.tscn"
func suite_name() -> String:
return "net"
func test_config_has_expected_paths() -> void:
var config := load(CONFIG_PATH) as SceneReplicationConfig
assert_true(config != null, "player_sync.tres 未能加载为 SceneReplicationConfig")
if config == null:
return
var paths := config.get_properties()
assert_eq(paths.size(), 2, "同步字段数量不对:%s" % [paths])
assert_true(config.has_property(^".:position"), "缺少 .:position")
assert_true(config.has_property(^"Body:rotation"), "缺少 Body:rotation")
func test_config_replication_mode_is_always() -> void:
var config := load(CONFIG_PATH) as SceneReplicationConfig
assert_true(config != null, "player_sync.tres 未能加载")
if config == null:
return
var paths := config.get_properties()
assert_gt(paths.size(), 0, "同步字段为空,远端玩家不会移动")
for path in paths:
assert_eq(
config.property_get_replication_mode(path),
SceneReplicationConfig.REPLICATION_MODE_ALWAYS,
"%s 的 replication_mode 不是 ALWAYS" % path
)
func test_player_scene_wires_synchronizer() -> void:
var packed := load(PLAYER_SCENE_PATH) as PackedScene
assert_true(packed != null, "player.tscn 未能加载")
if packed == null:
return
var player := packed.instantiate()
track(player)
var sync := player.get_node_or_null("Sync") as MultiplayerSynchronizer
assert_true(sync != null, "Player 下缺少 Sync 节点")
if sync == null:
return
assert_true(sync.replication_config != null, "Sync 没有绑定 SceneReplicationConfig")
assert_eq(sync.root_path, ^"..", "Sync.root_path 应为 .. (相对 Player)")