Files
mtgodot-poc/project/name_show_test.gd
T

80 lines
4.8 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.
# name_show_test —— §8.4 / §8.6 头顶名字「是否显示」1:1:
# CPythonSystem::IsAlwaysShowName / SetAlwaysShowNameFlagflag / 配置行 == 1)、
# game.py::__IsShowNameIsAlwaysShowName or ShowNameFlag)、
# CPythonTextTail::ShowAllTextTail 的 fDistanceFromPlayer < 3500、
# ShowCharacterTextTail 的 isShow / !IsGuildWall / CanPickInstance 资格判定,
# 以及 forcedPick / target / bNameFlag)绕过 3500 但仍过资格判定。
# godot --headless --path project --script name_show_test.gd
# 退出码 0 = 全过。
extends SceneTree
const NameShow = preload("res://name_show.gd")
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: name_show_test (§8.4/§8.6 IsAlwaysShowName / __IsShowName / ShowAllTextTail 3500 1:1)")
quit(0)
else:
printerr("%d check(s) failed" % _fail)
quit(1)
func _run() -> void:
# --- 0. 常量(PythonSystem.cpp / PythonTextTail.cpp------------------------
_ck(NameShow.ALWAYS_SHOW_NAME_DEFAULT == true, "DEFAULT_VALUE_ALWAYS_SHOW_NAME == true")
_ck(is_equal_approx(NameShow.SHOW_ALL_DISTANCE, 3500.0), "ShowAllTextTail 距离阈 == 3500")
_ck(NameShow.CFG_KEY == "ALWAYS_VIEW_NAME", "配置键 == ALWAYS_VIEW_NAME")
# --- 1. SetAlwaysShowNameFlag(iFlag): bAlwaysShowName = iFlag == 1 ----------
_ck(NameShow.always_show_from_flag(1) == true, "flag 1 -> true")
_ck(NameShow.always_show_from_flag(0) == false, "flag 0 -> false")
_ck(NameShow.always_show_from_flag(2) == false, "flag 2 -> false(严格 == 1")
# --- 2. config "ALWAYS_VIEW_NAME" -> atoi(value) == 1 ---------------------
_ck(NameShow.always_show_from_cfg("1") == true, "cfg \"1\" -> true")
_ck(NameShow.always_show_from_cfg("0") == false, "cfg \"0\" -> false")
_ck(NameShow.always_show_from_cfg("2") == false, "cfg \"2\" -> false")
_ck(NameShow.always_show_from_cfg(1) == true, "cfg int 1 -> true")
# --- 3. __IsShowName() = IsAlwaysShowName() or ShowNameFlag ---------------
_ck(NameShow.is_show_name(false, false) == false, "都关 -> 不显示")
_ck(NameShow.is_show_name(true, false) == true, "总显示名字开 -> 显示")
_ck(NameShow.is_show_name(false, true) == true, "LALT 按住 -> 显示")
_ck(NameShow.is_show_name(true, true) == true, "都开 -> 显示")
# --- 4. ShowAllTextTailfDistanceFromPlayer < 3500.0f -------------------
_ck(NameShow.within_show_all(0.0) == true, "距 0 在范围内")
_ck(NameShow.within_show_all(3499.9) == true, "距 3499.9 在范围内")
_ck(NameShow.within_show_all(3500.0) == false, "距 3500.0 严格 < 不含边界")
_ck(NameShow.within_show_all(5000.0) == false, "距 5000 超范围")
# --- 5. UpdateDistance 平面距(本移植同帧)------------------------------
_ck(is_equal_approx(NameShow.planar_distance_cm(Vector2(0, 0), Vector2(3, 4)), 5.0), "(0,0)-(3,4) == 5")
_ck(is_equal_approx(NameShow.planar_distance_cm(Vector2(10, 10), Vector2(10, 10)), 0.0), "同点距 0")
_ck(is_equal_approx(NameShow.planar_distance_cm(Vector2(-100, 0), Vector2(200, 0)), 300.0), "x 轴距 300")
# --- 6. ShowCharacterTextTail 资格:isShow && !IsGuildWall && CanPickInstance
_ck(NameShow.eligible_character(true, false, true) == true, "可见 / 非墙 / 可拾取 -> 合格")
_ck(NameShow.eligible_character(false, false, true) == false, "!isShow() -> 早退")
_ck(NameShow.eligible_character(true, true, true) == false, "IsGuildWall() -> 早退")
_ck(NameShow.eligible_character(true, false, false) == false, "!CanPickInstance() -> 不入列")
# --- 7. name_visible_for 综合 ------------------------------------------
# 公会墙:无论 forced 与否都不显示
_ck(NameShow.name_visible_for(true, true, 0.0, true, true, true) == false, "公会墙即便 forced 也不显示")
# forcedPick / target / bNameFlag):绕过 3500,但资格仍要过
_ck(NameShow.name_visible_for(true, false, 9999.0, true, false, true) == true, "forced + 合格 + 超距 -> 显示(绕过 3500")
_ck(NameShow.name_visible_for(true, true, 0.0, false, false, true) == false, "forced 但 !isShow() -> 不显示")
_ck(NameShow.name_visible_for(true, true, 0.0, true, false, false) == false, "forced 但 !CanPickInstance() -> 不显示")
# 非 forced:要 __IsShowName() 且 < 3500 且 合格
_ck(NameShow.name_visible_for(false, false, 100.0, true, false, true) == false, "非 forced + __IsShowName 假 -> 不显示")
_ck(NameShow.name_visible_for(false, true, 1000.0, true, false, true) == true, "非 forced + 显示开 + 距 1000 + 合格 -> 显示")
_ck(NameShow.name_visible_for(false, true, 4000.0, true, false, true) == false, "非 forced + 显示开 但 距 4000 -> 被 3500 裁掉")
_ck(NameShow.name_visible_for(false, true, 1000.0, false, false, true) == false, "非 forced + 显示开 + 近 但 死透 -> 不显示")