Committed to this self-hosted private repo so a clone builds on any machine without a separate asset sync. Copyrighted Ymir art — do not publish or redistribute. 54198 files, ~2.2 GB. asset_index.txt / assets.zip stay gitignored (derived: bake_asset_index.gd / pack-assets.sh). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
"""
|
|
Generic UI Locale Refresh System
|
|
Provides RefreshByMapping and RebuildDictionary for hot-reload support.
|
|
"""
|
|
|
|
import dbg
|
|
|
|
def RefreshByMapping(elementMap):
|
|
"""
|
|
Refresh UI elements using a mapping dictionary.
|
|
|
|
Args:
|
|
elementMap: Dict of {element_instance: "LOCALE_KEY_NAME"}
|
|
|
|
Returns:
|
|
Number of elements successfully refreshed
|
|
"""
|
|
import uiScriptLocale
|
|
import localeInfo
|
|
|
|
refreshCount = 0
|
|
for element, localeKey in list(elementMap.items()):
|
|
try:
|
|
# Try uiScriptLocale first, then localeInfo
|
|
if hasattr(uiScriptLocale, localeKey):
|
|
text = getattr(uiScriptLocale, localeKey)
|
|
elif hasattr(localeInfo, localeKey):
|
|
text = getattr(localeInfo, localeKey)
|
|
else:
|
|
dbg.TraceError("LocaleRefresh: key not found: %s" % localeKey)
|
|
continue
|
|
|
|
if hasattr(element, 'SetText'):
|
|
element.SetText(text)
|
|
refreshCount += 1
|
|
except Exception as e:
|
|
dbg.TraceError("LocaleRefresh: failed for key %s: %s" % (localeKey, str(e)))
|
|
|
|
return refreshCount
|
|
|
|
def RebuildDictionary(template, localeModule="localeInfo"):
|
|
"""
|
|
Rebuild a dictionary with fresh locale strings.
|
|
|
|
Args:
|
|
template: Dict of {key: "LOCALE_CONSTANT_NAME"}
|
|
localeModule: "localeInfo" or "uiScriptLocale"
|
|
|
|
Returns:
|
|
New dictionary with resolved locale values
|
|
"""
|
|
import localeInfo
|
|
import uiScriptLocale
|
|
|
|
module = localeInfo if localeModule == "localeInfo" else uiScriptLocale
|
|
newDict = {}
|
|
|
|
for key, localeKey in list(template.items()):
|
|
if hasattr(module, localeKey):
|
|
newDict[key] = getattr(module, localeKey)
|
|
else:
|
|
dbg.TraceError("LocaleRefresh: key not found: %s" % localeKey)
|
|
|
|
return newDict
|