Files
mtgodot-poc/project/inventory_ui_test.gd
T
shenandClaude Sonnet 5 47baf6c0c6 Metin2 game client (P0–P11) + mobile asset pipeline
Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
  phases, EntityStore world model, ~all GC/CG headers. char create/delete,
  private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
  quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
  char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
  token), system-option + game-option + ESC system menu, private-shop 39-grid,
  party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
  dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.

Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.

Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).

ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
2026-08-31 20:02:12 +09:00

95 lines
3.2 KiB
GDScript

# inventory_ui_test —— P2 背包/装备窗 headless 自检(假 client + 假 proto + 真 uiscript)。
# godot --headless --path project --script inventory_ui_test.gd
extends SceneTree
const UiManager = preload("res://ui/ui_manager.gd")
const InventoryUI = preload("res://ui/inventory_ui.gd")
class FakeClient extends Node:
signal inventory_changed(window: int, cell: int)
var inv := {} # cell -> {vnum,count}
var equip := [] # 11 x {vnum,count}
var used := []
var moved := []
func _init():
for i in 11: equip.append({"vnum": 0, "count": 0, "wear": i})
func get_inventory() -> Array:
var out := []
for c in inv: out.append({"cell": c, "vnum": inv[c].vnum, "count": inv[c].count})
return out
func get_equipment() -> Array: return equip
func use_item(w, c) -> bool: used.append([w, c]); return true
func move_item(fw, fc, tw, tc, n) -> bool: moved.append([fw, fc, tw, tc, n]); return true
func set_inv(cell, vnum, count):
inv[cell] = {"vnum": vnum, "count": count}
inventory_changed.emit(1, cell)
class FakeProto extends Node:
func item(vnum: int) -> Dictionary:
return {"vnum": vnum, "name": "Item%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 _init() -> void:
_run()
if _fail == 0:
print("PASS: inventory_ui_test (window + fill + refresh + use + move)")
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/inventorywindow.py")):
print(" (skip: no inventorywindow.py — assets checkout missing)")
return
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.inv[5] = {"vnum": 19, "count": 1}
fc.inv[6] = {"vnum": 27, "count": 3}
fc.equip[1] = {"vnum": 11209, "count": 1, "wear": 1}
var iv: Node = InventoryUI.new()
get_root().add_child(iv)
iv.setup(ui, fc, fp, assets)
iv.open()
_ck(iv.is_open(), "inventory window opened")
# 45 背包格 + 12 装备格(equipment 元组)
_ck(iv._cells.size() >= 45, "at least 45 inventory cells indexed (%d)" % iv._cells.size())
_ck(iv._cells.has(90), "equipment cell 90 present")
# 填充
var c5: Panel = iv._cells[5]
_ck(int(c5.get_meta("vnum", 0)) == 19, "cell 5 filled vnum 19")
_ck(c5.tooltip_text.contains("物品19"), "cell 5 tooltip has locale name")
var c6: Panel = iv._cells[6]
_ck(c6.has_node("count") and (c6.get_node("count") as Label).text == "3", "cell 6 shows count 3")
_ck(int(iv._cells[91].get_meta("vnum", 0)) == 11209, "equip wear1 -> ui cell 91 filled")
# inventory_changed 刷新
fc.set_inv(8, 100, 1)
await process_frame
_ck(int(iv._cells[8].get_meta("vnum", 0)) == 100, "cell 8 filled after inventory_changed")
# 右键用
iv.use(5)
_ck(fc.used.size() == 1 and fc.used[0] == [1, 5], "use(5) -> use_item(1,5)")
# 拖 5 -> 91(背包 -> 装备)
iv.move_to(5, 91, 1)
_ck(fc.moved.size() == 1 and fc.moved[0] == [1, 5, 2, 1, 1], "move_to(5,91) -> move_item(1,5,2,1,1)")
iv.close()
_ck(not iv.is_open(), "window closed")
ui.queue_free()