Files
owniverse/autoload/global.gd
T

113 lines
3.5 KiB
GDScript
Raw Normal View History

2026-03-05 20:13:45 +03:00
extends Node
const E = preload("res://world/owniverse/math/exact.gd")
2026-03-05 20:13:45 +03:00
const SPEED_LIMIT: int = 6
const SUPPORTED_LOCALES: PackedStringArray = ["en", "ru"]
2026-03-30 00:48:20 +03:00
# Write a readable diagnostic copy next to the encrypted save. Never used for loading.
var save_plaintext_copy: bool = true
2026-03-05 20:13:45 +03:00
var Settings: Dictionary = {
"filename": "save-0001",
"sound_volume": 1.0,
"music_volume": 1.0,
"sound_enabled": true,
"music_enabled": true,
2026-03-05 20:13:45 +03:00
"language": "en",
}
2026-10-03 11:06:52 +03:00
#var Locales: Dictionary = {}
var _locale: String = "en"
var Locale: String:
get:
return _locale
set(value):
set_locale(value)
2026-03-30 00:48:20 +03:00
var OwniverseEntities: Dictionary = {}
var OwniverseItems: Dictionary = {}
var Templates: Dictionary = {}
var LifeRules: Dictionary = {}
var CivilizationRules: Dictionary = {}
var ExtraParams: Dictionary = {}
var ApocalypseQueue: Dictionary = {}
var Music: Dictionary = {}
var Effects: Dictionary = {}
var batch_count: int = 40 # number of age groups per lifespan
2026-03-30 00:48:20 +03:00
func set_locale(locale: String) -> void:
_locale = locale if SUPPORTED_LOCALES.has(locale) else "en"
Settings.language = _locale
TranslationServer.set_locale(_locale)
2026-10-03 11:06:52 +03:00
#func get_localized_item_description(item_id: String, item: String) -> String:
#if Locales[Locale].has(item_id):
#return Locales[Locale][item_id][item]
#return ""
2026-03-30 00:48:20 +03:00
# Russian templates include the class; legacy English keys omit it.
func get_template(id: String, category: String, field: String) -> Dictionary:
var rows: Dictionary = Templates.get(Locale, {})
for key in [id + "." + category + "." + field, id + "." + field]:
if rows.has(key):
return rows[key]
return {}
func render_template(row: Dictionary, variables: Dictionary) -> String:
var result: String = str(row.get("text", ""))
for i in range(5):
var variable: String = str(row.get("value" + str(i), "")).strip_edges()
var value: String = str(variables.get(variable, "—")) if variable != "" else ""
result = result.replace("%value" + str(i) + "%", value)
return result.replace("<br>", "\n").replace("[p]", "\n")
func get_description(item_id: String, items: Array = []) -> String:
var row: Dictionary = Templates.get(Locale, {}).get(item_id, {})
var variables: Dictionary = {}
for i in mini(items.size(), 5):
variables[str(row.get("value" + str(i), ""))] = items[i]
return render_template(row, variables)
func format_number(value, digits: int = 0) -> String:
return E.grouped(value, digits)
func _init() -> void:
# Stage constructs its world before autoload _ready callbacks run.
ExtraParams = preload("res://data/owniverse_extra_param_loader.gd").get_data()
2026-03-05 20:13:45 +03:00
func _ready() -> void:
set_locale(str(Settings.language))
2026-10-03 11:06:52 +03:00
LifeRules = OwniverseLifeRuleLoader.get_data()
OwniverseEntities = OwniverseEntityLoader.get_data()
OwniverseItems = OwniverseItemLoader.get_data()
Templates = OwniverseTemplateLoader.get_data()
CivilizationRules = OwniverseCivilizationRuleLoader.get_data()
ApocalypseQueue = ApocalypseQueueLoader.get_data()
2026-03-05 20:13:45 +03:00
Music = OwniverseAudioLoader.get_music()
Effects = OwniverseAudioLoader.get_effects()
func _read_folder_list(folder_name: String) -> void:
var dir := DirAccess.open(folder_name)
if dir == null: printerr("Could not open folder: ", folder_name); return
dir.list_dir_begin()
for file: String in dir.get_files():
print(" → ", file)
2026-03-05 20:13:45 +03:00
func _print_dict(dict_to_print: Dictionary):
for d in dict_to_print:
print(d, " → ", dict_to_print[d])