Files
mtgodot-poc/project/weapon_trace_endpoint_parity_test.gd
T
shenandshen c93894313a fix: 装备属性面板避让逻辑 + 多项功能更新
- item_tooltip_view.gd: 新增 avoid_rect 属性,tooltip 与装备窗口重叠时自动推到左侧
- inventory_ui.gd: 悬停装备时传入窗口矩形作为避让区域
- 包含其他累积的功能开发和测试文件
2026-09-21 16:38:59 -07:00

53 lines
1.6 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.
# weapon_trace_endpoint_parity_test —— 40250 CWeaponTrace::SetWeaponInstance/Update。
#
# 参考端先按武器包围盒到骨骼原点的最大距离计算 m_fLengthUpdate 再沿
# 武器局部 Z 轴追加 m_fLength * __GetReachScale();不是取某个 AABB 角点
# 作为任意方向的刀尖。
extends SceneTree
const WeaponTrace = preload("res://ui/weapon_trace.gd")
var _fail := 0
func _ck(condition: bool, message: String) -> void:
if not condition:
_fail += 1
printerr("FAIL: " + message)
func _init() -> void:
call_deferred("_run")
func _run() -> void:
var host := Node3D.new()
root.add_child(host)
var weapon := MeshInstance3D.new()
var box := BoxMesh.new()
box.size = Vector3(0.2, 0.2, 1.6)
weapon.mesh = box
host.add_child(weapon)
var trace: Node = WeaponTrace.new()
host.add_child(trace)
await process_frame
_ck(trace.attach_to_weapon(weapon), "weapon geometry resolves")
var expected := sqrt(0.1 * 0.1 + 0.1 * 0.1 + 0.8 * 0.8)
_ck(is_zero_approx(float(trace._tip_local.x)),
"reference trace endpoint stays on the local Z axis")
_ck(is_zero_approx(float(trace._tip_local.y)),
"reference trace endpoint does not use an arbitrary AABB corner direction")
_ck(is_equal_approx(float(trace._tip_local.z), expected),
"reference endpoint uses max bound distance as m_fLength")
trace.set_reach_scale(1.5)
var scaled_expected := expected * 1.5
_ck(is_equal_approx(float(trace._tip_local.z), scaled_expected),
"__GetReachScale scales the local endpoint length")
if _fail == 0:
print("PASS: weapon_trace_endpoint_parity_test (bone-axis length + reach scale)")
quit(0)
else:
printerr("%d check(s) failed" % _fail)
quit(1)