From 845c8aea6d992717f076fee11e5765e9b5562612 Mon Sep 17 00:00:00 2001 From: mah_boi <61310813+MahBoiDeveloper@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:55:44 +0300 Subject: [PATCH] Improve GameFileX keys reading for translations (#476) * Fix logic for using any number and letters after GameFile keys * Fix typo * Fix syntax error and add info to the docs * Apply suggestions from code review --------- Co-authored-by: Kerbiter --- ClientCore/ClientConfiguration.cs | 14 +++++++++----- Docs/Translation.md | 8 ++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ClientCore/ClientConfiguration.cs b/ClientCore/ClientConfiguration.cs index 98d24ee9c..4a17090d5 100644 --- a/ClientCore/ClientConfiguration.cs +++ b/ClientCore/ClientConfiguration.cs @@ -278,23 +278,27 @@ private List ParseTranslationGameFiles() { List gameFiles = new(); - for (int i = 0; clientDefinitionsIni.KeyExists(TRANSLATIONS, $"GameFile{i}"); i++) + foreach (string key in clientDefinitionsIni.GetSectionKeys(TRANSLATIONS)) { // the syntax is GameFileX=path/to/source.file,path/to/destination.file[,checked] - string value = clientDefinitionsIni.GetStringValue(TRANSLATIONS, $"GameFile{i}", string.Empty); - string[] parts = value.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); + // where X can be any text or number + if (!key.StartsWith("GameFile")) + continue; + + string value = clientDefinitionsIni.GetStringValue(TRANSLATIONS, key, string.Empty); + string[] parts = value.Split(','); // fail explicitly if the syntax is wrong if (parts.Length is < 2 or > 3 || (parts.Length == 3 && parts[2].ToUpperInvariant() != "CHECKED")) { - throw new IniParseException($"Invalid syntax for value of GameFile{i}! " + + throw new IniParseException($"Invalid syntax for value of {key}! " + $"Expected path/to/source.file,path/to/destination.file[,checked], read {value}."); } bool isChecked = parts.Length == 3 && parts[2].ToUpperInvariant() == "CHECKED"; - gameFiles.Add(new(Source: parts[0], Target: parts[1], isChecked)); + gameFiles.Add(new(Source: parts[0].Trim(), Target: parts[1].Trim(), isChecked)); } return gameFiles; diff --git a/Docs/Translation.md b/Docs/Translation.md index 52042f729..041c6df4c 100644 --- a/Docs/Translation.md +++ b/Docs/Translation.md @@ -113,7 +113,7 @@ Each key in the `[Values]` section is composed of a few elements, joined using ` ## Ingame translation setup -The translation system's ingame translation support requires the mod/game author(s) to specify the files which translators can provide in order to translate the game. The files are specified in the the syntax is `GameFileX=path/to/source.file,path/to/destination.file[,checked]` INI key in the `[Translations]` section of `ClientDefinitions.ini` (X is an index starting from 0 and going up), with comma-separated parts of the value meaning the following: +The translation system's ingame translation support requires the mod/game author(s) to specify the files which translators can provide in order to translate the game. The files are specified in the the syntax is `GameFileX=path/to/source.file,path/to/destination.file[,checked]` INI key in the `[Translations]` section of `ClientDefinitions.ini` (X is any text you want to add to the key to help sort files), with comma-separated parts of the value meaning the following: 1) the path to the source file relative to currently selected translation directory; 2) the destination to copy to, relative to the game root folder; 3) (optional) `checked` for the file to be checked by file integrity checks (should be on if this file can be used to cheat), if not specified - this file is not checked. @@ -124,7 +124,11 @@ The translation system's ingame translation support requires the mod/game author Example configuration in `ClientDefinitions.ini`: ```ini [Translations] -GameFile0=translation.mix,expandmo98.mix +GameFileTranslationMix=translation.mix,expandmo98.mix +GameFile_GDI01=Missions/g0.map,Maps/Missions/g0.map +GameFile_NOD01=Missions/n0.map,Maps/Missions/n0.map +GameFile_DLL_SD=Resources/language_800x600.dll, Resources/language_800x600.dll +GameFile_DLL_HD=Resources/language_1024x720.dll,Resources/language_1024x720.dll ``` This will make the `translation.mix` file from current translation folder (say, `Resources/Translations/ru`) copied to game root as `expandmo98.mix` on game start.