85 lines
2.7 KiB
GDScript
85 lines
2.7 KiB
GDScript
extends Node
|
|
const E = preload("res://world/owniverse/math/exact.gd")
|
|
|
|
const SPEED_LIMIT: int = 6
|
|
|
|
# Write a readable diagnostic copy next to the encrypted save. Never used for loading.
|
|
var save_plaintext_copy: bool = true
|
|
|
|
var Settings: Dictionary = {
|
|
"filename": "save-0001",
|
|
"sound_volume": 1.0,
|
|
"language": "en",
|
|
}
|
|
|
|
# TODO getter setter for locale
|
|
|
|
#var Locales: Dictionary = {}
|
|
var Locale = "en"
|
|
|
|
var OwniverseEntities: Dictionary = {}
|
|
var OwniverseItems: Dictionary = {}
|
|
var Templates: Dictionary = {}
|
|
var LifeRules: Dictionary = {}
|
|
var CivilizationRules: Dictionary = {}
|
|
|
|
var batch_count: float = 40.0 # must be even not odd
|
|
|
|
|
|
#func get_localized_item_description(item_id: String, item: String) -> String:
|
|
#if Locales[Locale].has(item_id):
|
|
#return Locales[Locale][item_id][item]
|
|
#return ""
|
|
|
|
|
|
# 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 _ready() -> void:
|
|
|
|
LifeRules = OwniverseLifeRuleLoader.get_data()
|
|
OwniverseEntities = OwniverseEntityLoader.get_data()
|
|
OwniverseItems = OwniverseItemLoader.get_data()
|
|
Templates = OwniverseTemplateLoader.get_data()
|
|
CivilizationRules = OwniverseCivilizationRuleLoader.get_data()
|
|
|
|
|
|
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)
|
|
|
|
|
|
func _print_dict(dict_to_print: Dictionary):
|
|
for d in dict_to_print:
|
|
print(d, " → ", dict_to_print[d])
|