Texte, Tasten und Dateien

Alle Texte stehen in einer Tabelle mit Deutsch und Englisch, die das
Spiel zur Laufzeit liest. Die Tasten werden in Code angelegt, nach
physischer Position. SaveStore verwaltet den Spielerschlüssel dieser
Installation, schreibt den Speicherstand über eine temporäre Datei,
legt unbrauchbare Stände beiseite und behält die zehn neuesten
Aufzeichnungen.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Steven Wroblewski
2026-10-01 11:26:12 +02:00
parent 2607df8a97
commit ccf9813c80
16 changed files with 313 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
class_name I18n
extends RefCounted
## Loads the game's texts from a CSV file: the first column holds the key,
## every further column one language, named in the first row.
##
## The file is read at run time. Its import setting is "keep", so Godot
## generates no translation files from it.
const TEXTS_FILE := "res://i18n/texts.csv"
static var _installed := false
## Adds the translations of TEXTS_FILE to the TranslationServer, once.
static func install() -> void:
if _installed:
return
for translation in load_translations(TEXTS_FILE):
TranslationServer.add_translation(translation)
_installed = true
## One Translation per language column of the CSV file at `path`.
static func load_translations(path: String) -> Array[Translation]:
var translations: Array[Translation] = []
var file := FileAccess.open(path, FileAccess.READ)
if file == null:
push_error("texts not found: %s" % path)
return translations
var header := file.get_csv_line()
for column in range(1, header.size()):
var translation := Translation.new()
translation.locale = header[column]
translations.append(translation)
while not file.eof_reached():
var row := file.get_csv_line()
if row.size() < header.size() or row[0].is_empty():
continue
for column in range(1, header.size()):
translations[column - 1].add_message(row[0], row[column])
return translations