From 9744f635fee8114fe6335b5db7430fc3508a3186 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Mon, 30 Oct 2023 18:30:56 -0500 Subject: [PATCH] GameRelease.GetLanguageFormat moved to GameConstants --- .../Extensions/GameReleaseExt.cs | 27 ------------------- .../Mutagen.Bethesda.Core.csproj | 1 - .../Plugins/Meta/GameConstants.cs | 8 ++++++ .../Strings/StringsFolderLookupOverlay.cs | 5 ++-- .../Strings/StringsWriter.cs | 3 ++- .../Passthrough Tests/PassthroughTest.cs | 3 ++- 6 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 Mutagen.Bethesda.Core/Extensions/GameReleaseExt.cs diff --git a/Mutagen.Bethesda.Core/Extensions/GameReleaseExt.cs b/Mutagen.Bethesda.Core/Extensions/GameReleaseExt.cs deleted file mode 100644 index 979ad713eb..0000000000 --- a/Mutagen.Bethesda.Core/Extensions/GameReleaseExt.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Mutagen.Bethesda.Strings; - -namespace Mutagen.Bethesda; - -public static class GameReleaseExt -{ - public static StringsLanguageFormat GetLanguageFormat(this GameRelease release) - { - switch (release) - { - case GameRelease.Oblivion: - throw new ArgumentException($"Tried to get language format for an unsupported game: {release}", nameof(release)); - case GameRelease.SkyrimLE: - case GameRelease.SkyrimSE: - case GameRelease.SkyrimSEGog: - case GameRelease.SkyrimVR: - case GameRelease.EnderalLE: - case GameRelease.EnderalSE: - return StringsLanguageFormat.FullName; - case GameRelease.Fallout4: - case GameRelease.Starfield: - return StringsLanguageFormat.Iso; - default: - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Mutagen.Bethesda.Core/Mutagen.Bethesda.Core.csproj b/Mutagen.Bethesda.Core/Mutagen.Bethesda.Core.csproj index 1b608d37be..da0afbcb4a 100644 --- a/Mutagen.Bethesda.Core/Mutagen.Bethesda.Core.csproj +++ b/Mutagen.Bethesda.Core/Mutagen.Bethesda.Core.csproj @@ -568,7 +568,6 @@ - diff --git a/Mutagen.Bethesda.Core/Plugins/Meta/GameConstants.cs b/Mutagen.Bethesda.Core/Plugins/Meta/GameConstants.cs index 743c3bd362..4bc72e2453 100644 --- a/Mutagen.Bethesda.Core/Plugins/Meta/GameConstants.cs +++ b/Mutagen.Bethesda.Core/Plugins/Meta/GameConstants.cs @@ -54,6 +54,8 @@ public sealed record GameConstants public string IniName { get; init; } + public StringsLanguageFormat? StringsLanguageFormat { get; init; } + /// /// Constructor /// @@ -72,6 +74,7 @@ public GameConstants( MajorRecordConstants majorConstants, RecordHeaderConstants subConstants, Language[] languages, + StringsLanguageFormat? languageFormat, EncodingBundle encodings, bool hasEnabledMarkers, ushort? defaultFormVersion, @@ -89,6 +92,7 @@ public GameConstants( HasEnabledMarkers = hasEnabledMarkers; DefaultFormVersion = defaultFormVersion; MyDocumentsString = myDocumentsString; + StringsLanguageFormat = languageFormat; IniName = iniName; } @@ -145,6 +149,7 @@ public GameConstants( headerLength: 6, lengthLength: 2), languages: Array.Empty(), + languageFormat: null, hasEnabledMarkers: false, defaultFormVersion: null, myDocumentsString: "Oblivion", @@ -211,6 +216,7 @@ public GameConstants( Language.Chinese, Language.Russian, }, + languageFormat: Strings.StringsLanguageFormat.FullName, hasEnabledMarkers: false, defaultFormVersion: 43, myDocumentsString: "Skyrim", @@ -328,6 +334,7 @@ public GameConstants( Language.Russian, Language.Japanese, }, + languageFormat: Strings.StringsLanguageFormat.Iso, hasEnabledMarkers: true, defaultFormVersion: 131, myDocumentsString: "Fallout4", @@ -408,6 +415,7 @@ public GameConstants( Language.Russian, Language.Japanese, }, + languageFormat: Strings.StringsLanguageFormat.Iso, hasEnabledMarkers: true, defaultFormVersion: 555, myDocumentsString: null, diff --git a/Mutagen.Bethesda.Core/Strings/StringsFolderLookupOverlay.cs b/Mutagen.Bethesda.Core/Strings/StringsFolderLookupOverlay.cs index 00dce3c3c7..06194dbe7e 100644 --- a/Mutagen.Bethesda.Core/Strings/StringsFolderLookupOverlay.cs +++ b/Mutagen.Bethesda.Core/Strings/StringsFolderLookupOverlay.cs @@ -4,6 +4,7 @@ using Noggog; using System.Diagnostics.CodeAnalysis; using Mutagen.Bethesda.Installs.DI; +using Mutagen.Bethesda.Plugins.Meta; using Mutagen.Bethesda.Strings.DI; namespace Mutagen.Bethesda.Strings; @@ -53,7 +54,7 @@ public static StringsFolderLookupOverlay TypicalFactory( DirectoryPath dataPath, StringsReadParameters? instructions) { - var languageFormat = release.GetLanguageFormat(); + var languageFormat = GameConstants.Get(release).StringsLanguageFormat ?? throw new ArgumentException($"Tried to get language format for an unsupported game: {release}", nameof(release)); var encodings = instructions?.EncodingProvider ?? new MutagenEncodingProvider(); var stringsFolderPath = instructions?.StringsFolderOverride; if (stringsFolderPath == null) @@ -99,7 +100,7 @@ public static StringsFolderLookupOverlay TypicalFactory( foreach (var item in stringsFolder.Files) { if (!StringsUtility.TryRetrieveInfoFromString( - release.GetLanguageFormat(), + languageFormat, Path.GetFileName(item.Path), out var type, out var lang, diff --git a/Mutagen.Bethesda.Core/Strings/StringsWriter.cs b/Mutagen.Bethesda.Core/Strings/StringsWriter.cs index afdfa38cf6..ab4a1d3eb6 100644 --- a/Mutagen.Bethesda.Core/Strings/StringsWriter.cs +++ b/Mutagen.Bethesda.Core/Strings/StringsWriter.cs @@ -3,6 +3,7 @@ using Mutagen.Bethesda.Plugins.Binary.Translations; using Noggog; using System.IO.Abstractions; +using Mutagen.Bethesda.Plugins.Meta; using Mutagen.Bethesda.Strings.DI; namespace Mutagen.Bethesda.Strings; @@ -34,7 +35,7 @@ public StringsWriter( ModKey = modKey; EncodingProvider = encodingProvider; FileSystem = fileSystem.GetOrDefault(); - LanguageFormat = release.GetLanguageFormat(); + LanguageFormat = GameConstants.Get(release).StringsLanguageFormat ?? throw new ArgumentException($"Tried to get language format for an unsupported game: {release}", nameof(release)); WriteDir = writeDirectory; } diff --git a/Mutagen.Bethesda.Tests/Passthrough Tests/PassthroughTest.cs b/Mutagen.Bethesda.Tests/Passthrough Tests/PassthroughTest.cs index b372b8b110..7d3b069fdb 100644 --- a/Mutagen.Bethesda.Tests/Passthrough Tests/PassthroughTest.cs +++ b/Mutagen.Bethesda.Tests/Passthrough Tests/PassthroughTest.cs @@ -552,9 +552,10 @@ public IEnumerable AssertStringsEqual( DirectoryPath processedDir, DirectoryPath writeDir) { + var languageFormat = GameConstants.Get(GameRelease).StringsLanguageFormat!.Value; foreach (var source in Enums.Values) { - var stringsFileName = StringsUtility.GetFileName(GameRelease.GetLanguageFormat(), ModKey, Language.English, source); + var stringsFileName = StringsUtility.GetFileName(languageFormat, ModKey, Language.English, source); var sourcePath = Path.Combine(processedDir.Path, stringsFileName); var pathToTest = Path.Combine(writeDir.Path, stringsFileName); bool sourceExists = File.Exists(sourcePath);