123 lines
5.0 KiB
GDScript
123 lines
5.0 KiB
GDScript
# private_shop_ui_test —— 개인상점 개설창 headless 자체 검사(真 uiscript + 假 client)。
|
|
# godot --headless --path project --script private_shop_ui_test.gd
|
|
# 校验 privateshopbuilder.py 装载、itemStock 模型(拿起 / 落位 / 价格 / 排序 + display_pos /
|
|
# 撤下)、개설 → open_private_shop 封包字段。缺 uiscript 资产时优雅跳过。
|
|
extends SceneTree
|
|
|
|
const PrivateShopUI = preload("res://ui/private_shop_ui.gd")
|
|
|
|
class FakeClient extends Node:
|
|
signal inventory_changed(window: int, cell: int)
|
|
var inventory: Array = []
|
|
var calls: Array = []
|
|
func get_inventory() -> Array: return inventory
|
|
func open_private_shop(sign, items) -> bool:
|
|
calls.append(["open_shop", sign, items]); return true
|
|
func close_private_shop() -> bool:
|
|
calls.append(["close_shop"]); return true
|
|
|
|
class FakeProto extends Node:
|
|
func item(vnum: int) -> Dictionary:
|
|
return {"vnum": vnum, "name": "I%d" % vnum, "locale_name": "물품%d" % vnum, "type": 1}
|
|
|
|
var _fail := 0
|
|
func _ck(c: bool, m: String) -> void:
|
|
if not c:
|
|
_fail += 1
|
|
printerr("FAIL: " + m)
|
|
|
|
func _has_call(fc, name: String, pred: Callable) -> bool:
|
|
for c in fc.calls:
|
|
if c[0] == name and pred.call(c):
|
|
return true
|
|
return false
|
|
|
|
func _init() -> void:
|
|
_run()
|
|
if _fail == 0:
|
|
print("PASS: private_shop_ui_test (privateshopbuilder.py + itemStock model + CG_MYSHOP)")
|
|
quit(0)
|
|
else:
|
|
printerr("%d check(s) failed" % _fail)
|
|
quit(1)
|
|
|
|
func _run() -> void:
|
|
var assets := AssetRoot.path()
|
|
if not FileAccess.file_exists(assets.path_join("uiscript/uiscript/privateshopbuilder.py")):
|
|
print(" (skip: no privateshopbuilder.py — assets checkout missing)")
|
|
return
|
|
|
|
var UiManager = load("res://ui/ui_manager.gd")
|
|
var ui: CanvasLayer = UiManager.new()
|
|
get_root().add_child(ui)
|
|
ui._ready()
|
|
var fc := FakeClient.new()
|
|
var fp := FakeProto.new()
|
|
get_root().add_child(fc)
|
|
get_root().add_child(fp)
|
|
fc.inventory = [{"cell": 4, "vnum": 11901, "count": 1},
|
|
{"cell": 5, "vnum": 27993, "count": 3}, {"cell": 6, "vnum": 30001, "count": 2}]
|
|
|
|
var pu: Node = PrivateShopUI.new()
|
|
get_root().add_child(pu)
|
|
pu.setup(fc, ui, fp, assets)
|
|
pu.open()
|
|
_ck(pu.is_open(), "builder window opened")
|
|
if not pu.is_open():
|
|
return
|
|
_ck(pu._cells.size() == 40, "ItemSlot = 40-slot grid (5x8, shop.SHOP_SLOT_COUNT)")
|
|
_ck(is_instance_valid(pu._sign), "NameLine overlaid with a LineEdit")
|
|
_ck(pu._inv_list.get_child_count() == 3, "3 inventory candidates")
|
|
_ck((pu._inv_list.get_child(0) as Button).has_method("_get_drag_data"),
|
|
"inventory candidate supports drag data")
|
|
_ck(not pu._drop_mouse_item({"window": 1, "cell": 99, "vnum": 300, "count": 1,
|
|
"anti_flags": (1 << 13)}, 2), "ANTIFLAG_GIVE item cannot enter private shop")
|
|
_ck(not pu._drop_mouse_item({"window": 1, "cell": 99, "vnum": 301, "count": 1,
|
|
"anti_flags": (1 << 16)}, 2), "ANTIFLAG_MYSHOP item cannot enter private shop")
|
|
|
|
# 未上货 → 개설 무동작
|
|
pu._ok()
|
|
_ck(not _has_call(fc, "open_shop", func(_c): return true), "empty stock → no send")
|
|
|
|
# 拿起第 1 件(cell 4)→ 落到格 3,价 250000
|
|
(pu._inv_list.get_child(0) as Button).pressed.emit()
|
|
_ck(pu._picked != null and int(pu._picked["cell"]) == 4, "picked inv cell 4")
|
|
pu._on_slot_clicked(3)
|
|
_ck(is_instance_valid(pu._price_dialog), "price dialog opens on empty slot")
|
|
pu._place(3, 250000)
|
|
_ck(pu._stock.has(3) and int(pu._stock[3]["price"]) == 250000, "stock[3] placed")
|
|
_ck(pu._picked == null, "pick cleared after place")
|
|
_ck(pu._inv_list.get_child_count() == 2, "placed item leaves candidate list")
|
|
# 标准 Godot 拖放入口与点击选取共用同一个落位逻辑。
|
|
pu._drop_slot(Vector2.ZERO, {"private_shop_entry": {"cell": 5, "vnum": 27993, "count": 3}}, 6)
|
|
_ck(is_instance_valid(pu._price_dialog), "dragging candidate onto empty slot opens price dialog")
|
|
pu._place(6, 100)
|
|
_ck(pu._stock.has(6), "dragged item is retained in stock")
|
|
|
|
# 拿起第 3 件(cell 6)→ 落到格 0(更小格号 → 排前)
|
|
(pu._inv_list.get_child(0) as Button).pressed.emit()
|
|
pu._place(0, 99)
|
|
pu._sign.text = "Cheap swords"
|
|
pu._ok()
|
|
_ck(_has_call(fc, "open_shop", func(c):
|
|
if String(c[1]) != "Cheap swords": return false
|
|
var items: Array = c[2]
|
|
if items.size() != 3: return false
|
|
return int(items[0]["vnum"]) == 30001 and int(items[0]["display_pos"]) == 0 \
|
|
and int(items[1]["vnum"]) == 11901 and int(items[1]["price"]) == 250000 \
|
|
and int(items[1]["inv_cell"]) == 4 and int(items[1]["display_pos"]) == 3 \
|
|
and int(items[2]["vnum"]) == 27993 and int(items[2]["display_pos"]) == 6),
|
|
"개설 → open_private_shop(sign, stock 按格号排序 + display_pos)")
|
|
_ck(not pu.is_open(), "closes after 개설")
|
|
|
|
# 撤下:재개 → 점유 격 클릭 제거
|
|
pu.open()
|
|
(pu._inv_list.get_child(0) as Button).pressed.emit()
|
|
pu._place(7, 500)
|
|
_ck(pu._stock.has(7), "re-placed for remove test")
|
|
pu._on_slot_clicked(7)
|
|
_ck(not pu._stock.has(7), "click occupied slot removes it (DelPrivateShopItemStock)")
|
|
pu._close_shop()
|
|
_ck(_has_call(fc, "close_shop", func(_c): return true), "철수 → close_private_shop")
|
|
pu.close()
|