# inventory_test — 扩展装备位和腰带背包的协议坐标 / 锁格规则。 extends SceneTree const InventoryUI = preload("res://ui/inventory_ui.gd") class FakeProto extends Node: func item(_vnum: int) -> Dictionary: return {"values": [4]} class FakeClient extends Node: var item_ops := [] func use_item_to_item(sw: int, sc: int, tw: int, tc: int) -> bool: item_ops.append([sw, sc, tw, tc]) return true var failed := 0 func _check(ok: bool, message: String) -> void: if not ok: failed += 1 printerr("FAIL: " + message) func _init() -> void: var inv := InventoryUI.new() _check(inv._to_wire(0) == [1, 0], "normal inventory uses INVENTORY cell") # 旧 11 格 wear(BODY..SHIELD)走 EQUIPMENT 窗(window=2, 零基 wear cell)。 _check(inv._to_wire(90) == [2, 0], "wear body uses EQUIPMENT window cell 0") _check(inv._to_wire(100) == [2, 10], "wear shield uses EQUIPMENT window cell 10") # ENABLE_NEW_EQUIPMENT_SYSTEM 的 costume/ring/belt 留在 INVENTORY 窗全局 cell(GameType.h)。 _check(inv._to_wire(109) == [1, 109], "costume body uses legacy global cell 109") _check(inv._to_wire(110) == [1, 110], "costume hair uses legacy global cell 110") _check(inv._to_wire(111) == [1, 111], "ring1 uses legacy global cell 111") _check(inv._to_wire(112) == [1, 112], "ring2 uses legacy global cell 112") _check(inv._to_wire(113) == [1, 113], "wear belt uses legacy global cell 113") _check(inv._to_wire(200) == [1, 152], "belt UI cell 0 uses global cell 152") _check(inv._to_wire(215) == [1, 167], "belt UI cell 15 uses global cell 167") inv.proto = FakeProto.new() inv.add_child(inv.proto) for i in 16: var cell := Panel.new() inv.add_child(cell) inv._cells[200 + i] = cell var eq := [] for _i in 24: eq.append({"vnum": 0, "count": 0}) eq[23] = {"vnum": 12345, "count": 1} inv._apply_belt_locks(eq) _check(not bool(inv._cells[200].get_meta("locked", true)), "grade 4 unlocks belt cell 0") _check(not bool(inv._cells[202].get_meta("locked", true)), "grade 4 unlocks belt cell 2") _check(bool(inv._cells[203].get_meta("locked", false)), "grade 4 locks belt cell 3 (needs 6)") _check(not bool(inv._cells[206].get_meta("locked", true)), "grade 4 unlocks belt cell 6") _check(bool(inv._cells[207].get_meta("locked", false)), "grade 4 locks belt cell 7 (needs 6)") var fake_client := FakeClient.new() inv.add_child(fake_client) inv.client = fake_client for index in [0, 1]: var item_cell := Panel.new() item_cell.set_meta("vnum", 100 + index) item_cell.set_meta("count", 2) inv.add_child(item_cell) inv._cells[index] = item_cell _check(inv._use_to_item(0, 1), "item-to-item intent accepted") _check(fake_client.item_ops == [[1, 0, 1, 1]], "item-to-item uses original inventory positions") inv._begin_combine(0) _check(inv._combine_from == 0, "shift selects combine source") inv._begin_combine(0) _check(inv._combine_from == -1, "shift same source cancels combine") inv.free() if failed == 0: print("PASS: inventory_test (extended equipment + belt mapping)") quit(0) else: quit(1)