125 lines
4.5 KiB
GDScript
125 lines
4.5 KiB
GDScript
# atlas_test —— Atlas 大地图窗口的无资源 headless 自检。
|
|
# godot --headless --path project --script atlas_test.gd
|
|
extends SceneTree
|
|
|
|
const AtlasUI = preload("res://ui/atlas_ui.gd")
|
|
const UiManager = preload("res://ui/ui_manager.gd")
|
|
|
|
class FakeWorld extends Node:
|
|
func get_map_size_tiles() -> Vector2i: return Vector2i(2, 2)
|
|
func chunk_dir(_x: int, _y: int) -> String: return "/no-such-chunk"
|
|
func load_dds(_path: String): return null
|
|
|
|
class FakeClient extends Node:
|
|
var entities := {9: {"vid": 9, "pos": Vector3(2, 0, -2)}}
|
|
func get_party() -> Array: return [{"vid": 9, "leader": true}]
|
|
func get_entity(vid: int) -> Dictionary: return entities.get(vid, {})
|
|
func get_land_areas() -> Array:
|
|
return [{"x": 0, "y": 0, "width": 5000, "height": 5000, "guild_id": 7}]
|
|
func get_observers() -> Array:
|
|
return [{"vid": 9, "pos": Vector3(2, 0, -2)}]
|
|
func get_world_markers() -> Array:
|
|
return [{"pos": Vector3(-2, 0, 2)}]
|
|
|
|
var _fail := 0
|
|
func _ck(ok: bool, msg: String) -> void:
|
|
if not ok:
|
|
_fail += 1
|
|
printerr("FAIL: " + msg)
|
|
|
|
func _init() -> void:
|
|
await _run()
|
|
if _fail == 0:
|
|
print("PASS: atlas_test (window + drag + coordinate query)")
|
|
quit(0)
|
|
else:
|
|
printerr("%d check(s) failed" % _fail)
|
|
quit(1)
|
|
|
|
func _run() -> void:
|
|
var world := FakeWorld.new()
|
|
get_root().add_child(world)
|
|
var ui: CanvasLayer = UiManager.new()
|
|
get_root().add_child(ui)
|
|
await process_frame
|
|
var player := Node3D.new()
|
|
player.position = Vector3(128, 0, 256)
|
|
get_root().add_child(player)
|
|
var client := FakeClient.new()
|
|
get_root().add_child(client)
|
|
var atlas: Node = AtlasUI.new()
|
|
get_root().add_child(atlas)
|
|
atlas.setup(world, ui, func() -> Node3D: return player, "test_map", client)
|
|
atlas.open()
|
|
_ck(atlas.is_open(), "atlas opens")
|
|
_ck(atlas._map != null and atlas._map.size == Vector2(256, 256), "atlas builds map texture")
|
|
_ck(String(atlas._coord.text).contains("X 12800") and String(atlas._coord.text).contains("Y 25600"),
|
|
"atlas reports player server-centimetre coordinates")
|
|
atlas._overlay.queue_redraw()
|
|
_ck(atlas._overlay.is_inside_tree(), "atlas world marker overlay is live")
|
|
var old_pos: Vector2 = atlas._map.position
|
|
var down := InputEventMouseButton.new()
|
|
down.button_index = MOUSE_BUTTON_LEFT
|
|
down.pressed = true
|
|
down.position = Vector2(100, 100)
|
|
atlas._on_map_input(down)
|
|
var drag := InputEventMouseMotion.new()
|
|
drag.position = Vector2(140, 120)
|
|
atlas._on_map_input(drag)
|
|
_ck(atlas._map.position != old_pos, "atlas left drag moves map")
|
|
# 移动端地图用单指平移;第二根手指出现后,当前拖动必须被冻结,不能
|
|
# 把双指手势继续解释成地图移动或世界点地。
|
|
atlas._recenter_map()
|
|
var single_down := InputEventScreenTouch.new()
|
|
single_down.index = 4
|
|
single_down.pressed = true
|
|
single_down.position = Vector2(120, 120)
|
|
atlas._on_map_input(single_down)
|
|
var single_drag := InputEventScreenDrag.new()
|
|
single_drag.index = 4
|
|
single_drag.position = Vector2(160, 145)
|
|
single_drag.relative = Vector2(40, 25)
|
|
atlas._on_map_input(single_drag)
|
|
_ck(atlas._map.position != atlas._map_origin, "atlas single-finger touch drag moves map")
|
|
var single_up := InputEventScreenTouch.new()
|
|
single_up.index = 4
|
|
single_up.pressed = false
|
|
single_up.position = single_drag.position
|
|
atlas._on_map_input(single_up)
|
|
atlas._recenter_map()
|
|
var first_down := InputEventScreenTouch.new()
|
|
first_down.index = 5
|
|
first_down.pressed = true
|
|
first_down.position = Vector2(120, 120)
|
|
atlas._on_map_input(first_down)
|
|
var second_down := InputEventScreenTouch.new()
|
|
second_down.index = 6
|
|
second_down.pressed = true
|
|
second_down.position = Vector2(300, 120)
|
|
atlas._on_map_input(second_down)
|
|
var before_two_finger_drag: Vector2 = atlas._map.position
|
|
var two_finger_drag := InputEventScreenDrag.new()
|
|
two_finger_drag.index = 5
|
|
two_finger_drag.position = Vector2(220, 220)
|
|
two_finger_drag.relative = Vector2(100, 100)
|
|
atlas._on_map_input(two_finger_drag)
|
|
_ck(atlas._map.position == before_two_finger_drag,
|
|
"two-finger map gesture does not pan from one finger")
|
|
var first_up := InputEventScreenTouch.new()
|
|
first_up.index = 5
|
|
first_up.pressed = false
|
|
first_up.position = two_finger_drag.position
|
|
atlas._on_map_input(first_up)
|
|
var second_up := InputEventScreenTouch.new()
|
|
second_up.index = 6
|
|
second_up.pressed = false
|
|
second_up.position = Vector2(300, 120)
|
|
atlas._on_map_input(second_up)
|
|
var reset := InputEventMouseButton.new()
|
|
reset.button_index = MOUSE_BUTTON_RIGHT
|
|
reset.pressed = true
|
|
atlas._on_map_input(reset)
|
|
_ck(atlas._map.position == atlas._map_origin, "atlas right click recenters map")
|
|
atlas.close()
|
|
_ck(not atlas.is_open(), "atlas closes")
|