Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
phases, EntityStore world model, ~all GC/CG headers. char create/delete,
private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
token), system-option + game-option + ESC system menu, private-shop 39-grid,
party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.
Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.
Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).
ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
67 lines
2.1 KiB
GDScript
67 lines
2.1 KiB
GDScript
# Locale —— EterLocale 字符串表(`locale/locale/<lang>/*.txt`,KEY\tVALUE,UTF-8)。
|
||
# Godot 原生处理 UTF-8 + 拉丁/西里尔/希腊/阿拉伯;CJK 需外挂字体(apply_font)。
|
||
# 用 preload("res://locale.gd").new();setup() 后 t("KEY", [args]).
|
||
extends RefCounted
|
||
|
||
var _lang := "en"
|
||
var _tab := {} # KEY -> value
|
||
var _base := ""
|
||
|
||
func setup(assets_root: String, lang := "en") -> void:
|
||
_base = assets_root.path_join("locale/locale")
|
||
set_lang(lang)
|
||
|
||
func set_lang(lang: String) -> void:
|
||
_lang = lang
|
||
_tab.clear()
|
||
var dir := _base.path_join(lang)
|
||
if not DirAccess.dir_exists_absolute(dir):
|
||
push_warning("[locale] no such lang: " + dir)
|
||
return
|
||
for f in ["locale_interface.txt", "locale_game.txt", "itemdesc.txt", "skilldesc.txt"]:
|
||
_load_table(dir.path_join(f))
|
||
|
||
func _load_table(path: String) -> void:
|
||
if not FileAccess.file_exists(path):
|
||
return
|
||
var fa := FileAccess.open(path, FileAccess.READ)
|
||
if fa == null:
|
||
return
|
||
while not fa.eof_reached():
|
||
var line := fa.get_line()
|
||
if line.is_empty() or line.begins_with("#"):
|
||
continue
|
||
var tab := line.find("\t")
|
||
if tab < 0:
|
||
continue
|
||
var key := line.substr(0, tab).strip_edges()
|
||
var val := line.substr(tab + 1).strip_edges()
|
||
if not key.is_empty():
|
||
_tab[key] = val
|
||
|
||
func lang() -> String:
|
||
return _lang
|
||
|
||
func has(key: String) -> bool:
|
||
return _tab.has(key)
|
||
|
||
# t("SELECT_LEVEL") -> "Level";t("AFF_LOVE_POINT", [42]) -> "Love points: 42%"
|
||
# 缺失时返回 "<KEY>"(开发期一眼可见)。
|
||
func t(key: String, args: Array = []) -> String:
|
||
if not _tab.has(key):
|
||
return "<" + key + ">"
|
||
var s: String = _tab[key]
|
||
if args.is_empty():
|
||
return s
|
||
return s % args if args.size() > 1 else (s % args[0])
|
||
|
||
# 给一个 Control / Window 挂 CJK(或其它)字体。ttf_path 为空则不动。
|
||
func apply_font(node: Control, ttf_path: String, size := 0) -> void:
|
||
if ttf_path.is_empty() or not FileAccess.file_exists(ttf_path):
|
||
return
|
||
var f := FontFile.new()
|
||
f.load_dynamic_font(ttf_path)
|
||
node.add_theme_font_override("font", f)
|
||
if size > 0:
|
||
node.add_theme_font_size_override("font_size", size)
|