From 1c0227b1d4290070379370e3b4f68549431ec562 Mon Sep 17 00:00:00 2001 From: SirTobyB Date: Sun, 12 Jan 2025 08:14:51 +0100 Subject: [PATCH 1/4] adds some refactoring of NewGameManager; adds resource files Resource files are for localization. Also increased version number of assembly. --- Conspiratio.Lib/Allgemein/NewGameManager.cs | 39 +++++++---- Conspiratio.Lib/Conspiratio.Lib.csproj | 24 +++++-- Conspiratio.Lib/Resources.Designer.cs | 71 +++++++++++++++++++++ Conspiratio.Lib/Resources.en.resx | 17 +++++ Conspiratio.Lib/Resources.resx | 24 +++++++ 5 files changed, 158 insertions(+), 17 deletions(-) create mode 100644 Conspiratio.Lib/Resources.Designer.cs create mode 100644 Conspiratio.Lib/Resources.en.resx create mode 100644 Conspiratio.Lib/Resources.resx diff --git a/Conspiratio.Lib/Allgemein/NewGameManager.cs b/Conspiratio.Lib/Allgemein/NewGameManager.cs index 99ed7bc..795f43b 100644 --- a/Conspiratio.Lib/Allgemein/NewGameManager.cs +++ b/Conspiratio.Lib/Allgemein/NewGameManager.cs @@ -2,17 +2,35 @@ using Conspiratio.Lib.Gameplay.Spielwelt; +using JetBrains.Annotations; + namespace Conspiratio.Lib.Allgemein { public class NewGameManager { - private string _savegamePath; + private readonly string _savegamePath; public NewGameManager(string savegamePath) { _savegamePath = savegamePath; } + [PublicAPI] + public int MaxLengthOfGameName + { + get + { + string savegamePathWithFilename = Path.Combine(_savegamePath, "_1600.dat"); + int savegamePathLength = savegamePathWithFilename.Length; + int maxlength = 256 - savegamePathLength; + + if (maxlength < 0) // fallback from settings (standard: 12), if savegame path is longer then 256 chars + maxlength = SW.Statisch.GetMaxNameLength(); + + return maxlength; + } + } + public bool CreateNewGame(string name, int playerCount, bool cheating, bool showDeaths, bool testmode, out string error) { if (!ValidateName(name, out error)) @@ -27,9 +45,10 @@ public bool CreateNewGame(string name, int playerCount, bool cheating, bool show return true; } + [PublicAPI] public bool ValidateName(string name, out string error) { - error = "Der Spielname muss aus mindestens drei Zeichen bestehen"; + error = Resources.The_game_name_must_consist_of_at_least_three_characters; if (string.IsNullOrEmpty(name)) return false; @@ -40,25 +59,19 @@ public bool ValidateName(string name, out string error) error = ""; return true; } - + + [PublicAPI] public string SanitizeName(string name) { - string savegamePathWithFilename = Path.Combine(_savegamePath, "_1600.dat"); - int savegamePathLength = savegamePathWithFilename.Length; - int maxlength = 256 - savegamePathLength; - - if (maxlength < 0) // fallback from settings (standard: 12), if savegame path is longer then 256 chars - maxlength = SW.Statisch.GetMaxNameLength(); - name = RemoveInvalidChars(name); - if (name.Length > maxlength) - return name.Substring(0, maxlength); + if (name.Length > MaxLengthOfGameName) + return name.Substring(0, MaxLengthOfGameName); return name; } - private string RemoveInvalidChars(string filename) + private static string RemoveInvalidChars(string filename) { return string.Concat(filename.Split(Path.GetInvalidFileNameChars())); } diff --git a/Conspiratio.Lib/Conspiratio.Lib.csproj b/Conspiratio.Lib/Conspiratio.Lib.csproj index 9c85d27..ec29b61 100644 --- a/Conspiratio.Lib/Conspiratio.Lib.csproj +++ b/Conspiratio.Lib/Conspiratio.Lib.csproj @@ -13,15 +13,31 @@ \ + + + ResXFileCodeGenerator + Resources.de.Designer.cs + + + + + True + True + Resources.resx + + + + + - 3.0.0 - 3.0.0 + 3.1.0 + 3.1.0 A library with gameplay logic for the free and open-source game Conspiratio True - $(AssemblyVersion) + 3.1.0 $(AssemblyName) Conspiratio - Copyright © 2011-2024 + Copyright © 2011-2025 https://www.conspiratio.net icon.png conspiratio;game;library diff --git a/Conspiratio.Lib/Resources.Designer.cs b/Conspiratio.Lib/Resources.Designer.cs new file mode 100644 index 0000000..23915aa --- /dev/null +++ b/Conspiratio.Lib/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Conspiratio.Lib { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Conspiratio.Lib.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Der Spielname muss aus mindestens drei Zeichen bestehen. + /// + internal static string The_game_name_must_consist_of_at_least_three_characters { + get { + return ResourceManager.GetString("The game name must consist of at least three characters", resourceCulture); + } + } + } +} diff --git a/Conspiratio.Lib/Resources.en.resx b/Conspiratio.Lib/Resources.en.resx new file mode 100644 index 0000000..bd01558 --- /dev/null +++ b/Conspiratio.Lib/Resources.en.resx @@ -0,0 +1,17 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The game name must consist of at least three characters + + \ No newline at end of file diff --git a/Conspiratio.Lib/Resources.resx b/Conspiratio.Lib/Resources.resx new file mode 100644 index 0000000..d87f721 --- /dev/null +++ b/Conspiratio.Lib/Resources.resx @@ -0,0 +1,24 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Der Spielname muss aus mindestens drei Zeichen bestehen + + \ No newline at end of file From b0b8ac3c939ed86c0e7c2847de2b8a592967c4d5 Mon Sep 17 00:00:00 2001 From: SirTobyB Date: Sun, 12 Jan 2025 12:38:20 +0100 Subject: [PATCH 2/4] refactoring the interface to show a messagebox for text --- Conspiratio.Lib/Allgemein/IShowText.cs | 9 +++++++++ Conspiratio.Lib/Allgemein/ITextAnzeigen.cs | 7 ------- Conspiratio.Lib/Allgemein/UIHelper.cs | 6 +++--- .../Gameplay/Spielwelt/DynamischeSpieldaten.cs | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 Conspiratio.Lib/Allgemein/IShowText.cs delete mode 100644 Conspiratio.Lib/Allgemein/ITextAnzeigen.cs diff --git a/Conspiratio.Lib/Allgemein/IShowText.cs b/Conspiratio.Lib/Allgemein/IShowText.cs new file mode 100644 index 0000000..639ffa9 --- /dev/null +++ b/Conspiratio.Lib/Allgemein/IShowText.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Conspiratio.Lib.Allgemein +{ + public interface IShowText + { + Task ShowDialog(string text); + } +} \ No newline at end of file diff --git a/Conspiratio.Lib/Allgemein/ITextAnzeigen.cs b/Conspiratio.Lib/Allgemein/ITextAnzeigen.cs deleted file mode 100644 index 3a9ac12..0000000 --- a/Conspiratio.Lib/Allgemein/ITextAnzeigen.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Conspiratio.Lib.Allgemein -{ - public interface ITextAnzeigen - { - void ShowDialog(string text); - } -} \ No newline at end of file diff --git a/Conspiratio.Lib/Allgemein/UIHelper.cs b/Conspiratio.Lib/Allgemein/UIHelper.cs index 7bf93b6..fb94a38 100644 --- a/Conspiratio.Lib/Allgemein/UIHelper.cs +++ b/Conspiratio.Lib/Allgemein/UIHelper.cs @@ -6,7 +6,7 @@ public class UIHelper { public IYesNoQuestion YesNoQuestion { get; private set; } - public ITextAnzeigen TextAnzeigen { get; private set; } + public IShowText ShowText { get; private set; } public IBeziehungPflegen BeziehungPflegen { get; private set; } @@ -22,12 +22,12 @@ public class UIHelper public IUntergebeneDialog UntergebeneDialog { get; private set; } - public void Initialisieren(IYesNoQuestion yesNoQuestion, ITextAnzeigen textAnzeigen, IBeziehungPflegen beziehungPflegen, IBauwerkStiftenDialog bauwerkStiftenDialog, + public void Initialisieren(IYesNoQuestion yesNoQuestion, IShowText showText, IBeziehungPflegen beziehungPflegen, IBauwerkStiftenDialog bauwerkStiftenDialog, IFestGebenDialog festGebenDialog, IPolitischeWeltkarteDialog politischeWeltkarteDialog, ITestamentAnzeigenDialog testamentAnzeigenDialog, IProzentwertFestlegenDialog prozentwertFestlegenDialog, IUntergebeneDialog untergebeneDialog) { YesNoQuestion = yesNoQuestion; - TextAnzeigen = textAnzeigen; + ShowText = showText; BeziehungPflegen = beziehungPflegen; BauwerkStiftenDialog = bauwerkStiftenDialog; FestGebenDialog = festGebenDialog; diff --git a/Conspiratio.Lib/Gameplay/Spielwelt/DynamischeSpieldaten.cs b/Conspiratio.Lib/Gameplay/Spielwelt/DynamischeSpieldaten.cs index 7997ac8..3597f30 100644 --- a/Conspiratio.Lib/Gameplay/Spielwelt/DynamischeSpieldaten.cs +++ b/Conspiratio.Lib/Gameplay/Spielwelt/DynamischeSpieldaten.cs @@ -2791,7 +2791,7 @@ private void SpielerKlagtXAn(int iAngeklagter) #region BelTextAnzeigen public void BelTextAnzeigen(string text) { - SW.UI.TextAnzeigen.ShowDialog(text); + SW.UI.ShowText.ShowDialog(text); } #endregion From e575ada8d7966289c703ecfb33a94e6e9fd8d63e Mon Sep 17 00:00:00 2001 From: SirTobyB Date: Sun, 12 Jan 2025 12:39:43 +0100 Subject: [PATCH 3/4] marks the package reference as private assets Because it's only neede to development time and not runtime. See https://github.com/NuGet/Home/wiki/DevelopmentDependency-support-for-PackageReference and https://stackoverflow.com/q/46401170 --- Conspiratio.Lib/Conspiratio.Lib.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conspiratio.Lib/Conspiratio.Lib.csproj b/Conspiratio.Lib/Conspiratio.Lib.csproj index ec29b61..d17fb76 100644 --- a/Conspiratio.Lib/Conspiratio.Lib.csproj +++ b/Conspiratio.Lib/Conspiratio.Lib.csproj @@ -27,7 +27,7 @@ - + 3.1.0 From 81888dd65630d84c5bee3dafec1ed5dc5ae0fba4 Mon Sep 17 00:00:00 2001 From: SirTobyB Date: Thu, 1 Jan 2026 10:39:41 +0100 Subject: [PATCH 4/4] adds new changelog entry for version 3.1.0 --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8966e7..3d05ec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog Conspiratio.Lib +## 3.1.0 + +_01.01.2026_ + +**[DE]** +- Kleinere Refaktorisierungen des `NewGameManagers` +- Refaktorisierung: Benenne `ITextAnzeigen` um in `IShowText` +- Füge Resource Datei für statische, übersetzbare Texte hinzu (bisher mit deutsch und englisch als Sprache) + +**[EN]** +- Small refactorings of `NewGameManagers` +- Refactoring: Rename `ITextAnzeigen` to `IShowText` +- Added a resource file for static localizable text (until now with german and english as languages) + ## 3.0.0 _23.12.2024_