Replaced txt by Loaders
This commit is contained in:
+10
-70
@@ -14,7 +14,7 @@ var Settings: Dictionary = {
|
||||
|
||||
# TODO getter setter for locale
|
||||
|
||||
var Locales: Dictionary = {}
|
||||
#var Locales: Dictionary = {}
|
||||
var Locale = "en"
|
||||
|
||||
var OwniverseEntities: Dictionary = {}
|
||||
@@ -26,10 +26,10 @@ 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 ""
|
||||
#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.
|
||||
@@ -63,72 +63,12 @@ func format_number(value, digits: int = 0) -> String:
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
CivilizationRules.clear()
|
||||
for row: Dictionary in _read_from_csv("res://data/civilization_rules.txt").values():
|
||||
if not CivilizationRules.has(row.stage):
|
||||
CivilizationRules[row.stage] = {"home": row.home, "span": E.of(row.span), "stars": E.of(row.stars), "ethics": {},
|
||||
"colonizes": row.colonizes == "1", "fights": row.fights == "1", "diplomacy": row.diplomacy == "1", "worships": row.worships == "1"}
|
||||
CivilizationRules[row.stage].ethics[row.ethic] = row
|
||||
var stages: Array = CivilizationRules.keys()
|
||||
stages.sort()
|
||||
for i in stages.size():
|
||||
CivilizationRules[stages[i]].next = stages[i + 1] if i + 1 < stages.size() else "Ct"
|
||||
CivilizationRules[stages[i]].previous = stages[i - 1] if i > 0 else "C0.1"
|
||||
CivilizationRules[stages[i]].colony = stages[maxi(0, i - 2)]
|
||||
CivilizationRules.Ct = {"home": "", "span": 0.0, "stars": 0.0, "ethics": {}, "next": "Ct", "previous": "C4.4", "colonizes": false, "fights": false, "diplomacy": false, "worships": false}
|
||||
LifeRules = _read_from_csv("res://data/life_rules.txt")
|
||||
OwniverseEntities = _read_from_csv("res://data/owniverse_entities.txt")
|
||||
OwniverseItems = _read_from_csv("res://data/owniverse_items.txt")
|
||||
|
||||
Locales["en"] = _read_from_csv("res://data/locale.en.txt")
|
||||
Locales["ru"] = _read_from_csv("res://data/locale.ru.txt")
|
||||
|
||||
|
||||
Templates = OwniverseTemplate.get_data()
|
||||
|
||||
|
||||
func _read_from_csv(file_path: String) -> Dictionary:
|
||||
if not FileAccess.file_exists(file_path):
|
||||
printerr("File not found: " + file_path)
|
||||
return {}
|
||||
|
||||
var file = FileAccess.open(file_path, FileAccess.READ)
|
||||
if file == null:
|
||||
printerr("File can not be opened:" + file_path)
|
||||
return {}
|
||||
|
||||
var headers: PackedStringArray = []
|
||||
var data: Array = []
|
||||
|
||||
if not file.eof_reached():
|
||||
headers = PackedStringArray()
|
||||
for val in file.get_csv_line("|"):
|
||||
headers.append(val.strip_edges())
|
||||
|
||||
while not file.eof_reached():
|
||||
var raw_row = file.get_csv_line("|")
|
||||
if raw_row.is_empty(): # пропускаем пустые строки
|
||||
continue
|
||||
|
||||
var trimmed_row: PackedStringArray = []
|
||||
for val in raw_row:
|
||||
trimmed_row.append(val.strip_edges())
|
||||
|
||||
data.append(trimmed_row)
|
||||
|
||||
file.close()
|
||||
|
||||
var dict_data: Dictionary = {}
|
||||
for row in data:
|
||||
if row.size() < 2: continue
|
||||
|
||||
if row.size() == headers.size():
|
||||
var dict: Dictionary = {}
|
||||
for i in headers.size():
|
||||
dict[headers[i]] = row[i]
|
||||
dict_data[row[0]] = dict
|
||||
|
||||
return dict_data
|
||||
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:
|
||||
|
||||
@@ -178,6 +178,30 @@ func load_data(filename: String, password: String) -> Dictionary:
|
||||
return E.decode(data)
|
||||
|
||||
|
||||
## Preserve a structurally readable but game-incompatible save, then allow the
|
||||
## already initialized fresh session to use the original filename.
|
||||
func archive_incompatible_save(filename: String) -> bool:
|
||||
flush_saves()
|
||||
var path: String = save_directory.path_join(E.add(filename, ".adventure"))
|
||||
if not FileAccess.file_exists(path):
|
||||
blocked_saves.erase(filename)
|
||||
last_error = ""
|
||||
return true
|
||||
var archive: String = E.add(path, ".incompatible.bak")
|
||||
var index: int = 0
|
||||
while FileAccess.file_exists(archive):
|
||||
index = E.add(index, 1)
|
||||
archive = E.add(E.add(path, ".incompatible.bak."), str(index))
|
||||
var error: Error = DirAccess.rename_absolute(path, archive)
|
||||
if E.ne(error, OK):
|
||||
blocked_saves[filename] = true
|
||||
return _fail(E.add("Cannot archive incompatible save: ", error_string(error)))
|
||||
blocked_saves.erase(filename)
|
||||
last_error = ""
|
||||
push_warning(E.add(E.add("Incompatible save preserved at ", archive), "; starting a new game."))
|
||||
return true
|
||||
|
||||
|
||||
static func _number(value: Variant, whole: bool = false, nonnegative: bool = true) -> bool:
|
||||
return E.numeric(value) and E.finite(value) and (not value is float or absf(value) < 1e28) and (not whole or E.eq(value, E.floor_value(value))) and (not nonnegative or E.ge(value, 0))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user