feat(locale): add Locale fallback for monster names in net_play._entity_name
This commit is contained in:
+13
-1
@@ -663,12 +663,24 @@ func _entity_kind(e: Dictionary) -> int:
|
|||||||
return explicit_kind
|
return explicit_kind
|
||||||
return 0
|
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:
|
func _entity_name(e: Dictionary) -> String:
|
||||||
var nm := String(e.get("name", ""))
|
var nm := String(e.get("name", ""))
|
||||||
if nm != "":
|
if nm != "":
|
||||||
return nm
|
return nm
|
||||||
var race := int(e.get("race", 0))
|
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"):
|
if race >= 1 and proto and proto.has_method("mob"):
|
||||||
var m: Dictionary = proto.mob(race)
|
var m: Dictionary = proto.mob(race)
|
||||||
if not m.is_empty():
|
if not m.is_empty():
|
||||||
|
|||||||
Reference in New Issue
Block a user