Files
mtgodot-poc/project/item_tooltip_test.gd

70 lines
3.3 KiB
GDScript
Raw Permalink 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.
# item_tooltip_test —— item_proto 固定字段 + itemdesc + 实例 socket/attribute 的回归。
extends SceneTree
const ItemTooltip = preload("res://ui/item_tooltip.gd")
class FakeMobProto extends RefCounted:
func mob(vnum: int) -> Dictionary:
return {"vnum": vnum, "name": "Wolf", "locale_name": "Wolf"}
var _fail := 0
func _ck(condition: bool, message: String) -> void:
if not condition:
_fail += 1
printerr("FAIL: " + message)
func _init() -> void:
var tooltip := ItemTooltip.new()
var assets := AssetRoot.path()
_ck(tooltip.setup(assets, "en"), "itemdesc en loaded")
var proto := {
"vnum": 71114,
"name": "Wild Boar Seal",
"locale_name": "Wild Boar Seal",
"type": 2,
"values": [12, 30, 0, 0, 0, 2],
"limits": [{"type": 1, "value": 15}, {"type": 0, "value": 0}],
"applies": [{"type": 1, "value": 100}, {"type": 0, "value": 0}, {"type": 0, "value": 0}],
"refined_vnum": 71115,
"refine_set": 42,
}
var instance := {
"count": 3,
"sockets": [28030, 0, -1],
"attrs": [{"type": 5, "value": 7}],
}
var text := tooltip.format(71114, 3, proto, instance)
_ck(text.begins_with("Wild Boar Seal\n数量:3"), "title and stack count")
_ck(text.contains("This seal's magic"), "itemdesc description included")
_ck(text.contains("等级要求:15"), "limit included")
_ck(text.contains("防御力:34"), "armor value formula included")
_ck(text.contains("最大生命:+100"), "proto apply included")
_ck(text.contains("附加力量:+7"), "instance attribute included")
_ck(text.contains("孔 1#28030") and text.contains("孔 3:损坏"), "instance sockets included")
_ck(text.contains("精炼后:#71115") and text.contains("精炼套件:42"), "refine links included")
var rod_proto := {"locale_name": "Fishing Rod", "type": 13, "values": [30, 0, 120]}
var rod_text := tooltip.format(20000, 1, rod_proto, {"sockets": [120, 0, 0]})
_ck(rod_text.contains("等级:3") and rod_text.contains("经验:120 / 120") and rod_text.contains("可升级"),
"rod level and experience included")
var fish_text := tooltip.format(27800, 1, {"locale_name": "Fish", "type": 12}, {"sockets": [235, 0, 0]})
_ck(fish_text.contains("长度:2.35 cm"), "fish length included")
var ds_text := tooltip.format(12345, 1, {"locale_name": "Dragon Soul", "type": 29}, {})
_ck(ds_text.contains("龙魂石阶段:4") and ds_text.contains("龙魂石强化:4"), "dragon soul stage included")
var special := ItemTooltip.new()
_ck(special.setup(assets, "en", FakeMobProto.new()), "special tooltip sources loaded")
var book_text := special.format(50300, 1, {"locale_name": "Skill Book", "type": 17}, {"sockets": [1, 0, 0]})
_ck(book_text.begins_with("Three-Way Cut Skill Book"), "skill book title includes skill name")
var poly_text := special.format(70103, 1, {"locale_name": "Polymorph Marble", "type": 19}, {"sockets": [77, 0, 0]})
_ck(poly_text.begins_with("Wolf Polymorph Marble"), "polymorph title includes monster name")
var timed := special.format(90001, 1, {"locale_name": "Timed", "type": 18,
"limits": [{"type": 7, "value": 0}, {"type": 0, "value": 0}]},
{"sockets": [int(Time.get_unix_time_from_system()) + 65, 0, 0]})
_ck(timed.contains("剩余时间:1分5秒"), "realtime limit renders remaining time")
if _fail == 0:
print("PASS: item_tooltip_test")
quit(0)
else:
printerr("%d check(s) failed" % _fail)
quit(1)