feat(locale): add Locale fallback for monster names in net_play._entity_name

This commit is contained in:
shen
2026-09-19 18:58:10 -07:00
parent 41772471d6
commit 7cbda7b3dd
+13 -1
View File
@@ -663,12 +663,24 @@ func _entity_kind(e: Dictionary) -> int:
return explicit_kind
return 0
# 实体显示名:玩家 / NPC 走 GC_CHAR_ADD_INFO 的 name;怪没有名字包 -> 查 mob_proto。
var _locale_ref: RefCounted = null
# 实体显示名:玩家 / NPC 走 GC_CHAR_ADD_INFO 的 name;怪没有名字包 -> 查 mob_proto / Locale。
func _entity_name(e: Dictionary) -> String:
var nm := String(e.get("name", ""))
if nm != "":
return nm
var race := int(e.get("race", 0))
if race >= 1:
if _locale_ref == null and ResourceLoader.exists("res://locale.gd"):
var LocaleScript = load("res://locale.gd")
if LocaleScript:
_locale_ref = LocaleScript.new()
_locale_ref.setup(AssetRoot.path() if ResourceLoader.exists("res://asset_root.gd") else "")
if _locale_ref and _locale_ref.has_method("mob_name"):
var zh_name: String = _locale_ref.mob_name(race)
if not zh_name.begins_with("怪物 #") and not zh_name.is_empty():
return zh_name
if race >= 1 and proto and proto.has_method("mob"):
var m: Dictionary = proto.mob(race)
if not m.is_empty():