From f72df888fb2c5369f11141bc62cad2bfbb115603 Mon Sep 17 00:00:00 2001 From: And42 Date: Sun, 2 Aug 2020 13:15:57 +0300 Subject: [PATCH 01/14] Added fonts file type --- .../Code/Enums/FileType.cs | 6 +- .../Code/Implementations/FileConverter.cs | 6 +- .../Code/Json/FontFileInfo.cs | 18 ++++++ .../Code/Models/ModifiedFontModel.cs | 39 +++++++++++++ .../ModifiedFileTemplateSelector.cs | 5 +- .../Code/Utils/PackUtils.cs | 4 +- .../ViewModels/ConverterWindowViewModel.cs | 6 +- .../Code/ViewModels/PackCreationViewModel.cs | 41 +++++++++++++- .../Pages/PackCreation/PackCreationStep3.xaml | 55 +++++++++++++++++++ .../TerrLauncherPackCreator.csproj | 2 + 10 files changed, 170 insertions(+), 12 deletions(-) create mode 100644 TerrLauncherPackCreator/Code/Json/FontFileInfo.cs create mode 100644 TerrLauncherPackCreator/Code/Models/ModifiedFontModel.cs diff --git a/TerrLauncherPackCreator/Code/Enums/FileType.cs b/TerrLauncherPackCreator/Code/Enums/FileType.cs index 0e9c707..64c2f63 100644 --- a/TerrLauncherPackCreator/Code/Enums/FileType.cs +++ b/TerrLauncherPackCreator/Code/Enums/FileType.cs @@ -6,10 +6,10 @@ public enum FileType Map, Character, Gui, - Translation + Translation, + Font // todo: add // Audio, -// Font, } } @@ -17,6 +17,6 @@ namespace TerrLauncherPackCreator.Code.Utils { public static partial class PackUtils { - public const int TotalFileTypes = 5; + public const int TotalFileTypes = 6; } } \ No newline at end of file diff --git a/TerrLauncherPackCreator/Code/Implementations/FileConverter.cs b/TerrLauncherPackCreator/Code/Implementations/FileConverter.cs index f331191..6d7f9eb 100644 --- a/TerrLauncherPackCreator/Code/Implementations/FileConverter.cs +++ b/TerrLauncherPackCreator/Code/Implementations/FileConverter.cs @@ -41,7 +41,7 @@ public class FileConverter : IFileConverter throw new FileNotFoundException("File not found", targetFile); { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); } @@ -58,12 +58,13 @@ public class FileConverter : IFileConverter FileType.Character => JsonConvert.DeserializeObject(configText), FileType.Gui => JsonConvert.DeserializeObject(configText), FileType.Translation => JsonConvert.DeserializeObject(configText), + FileType.Font => JsonConvert.DeserializeObject(configText), _ => throw new ArgumentOutOfRangeException() }; } { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); } @@ -77,6 +78,7 @@ public class FileConverter : IFileConverter case FileType.Character: case FileType.Gui: case FileType.Translation: + case FileType.Font: string uniqueFile = ApplicationDataUtils.GenerateNonExistentFilePath(); IOUtils.EnsureParentDirExists(uniqueFile); File.Copy(targetFile, uniqueFile, overwrite: false); diff --git a/TerrLauncherPackCreator/Code/Json/FontFileInfo.cs b/TerrLauncherPackCreator/Code/Json/FontFileInfo.cs new file mode 100644 index 0000000..bc3b87d --- /dev/null +++ b/TerrLauncherPackCreator/Code/Json/FontFileInfo.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; +using TerrLauncherPackCreator.Code.Interfaces; + +namespace TerrLauncherPackCreator.Code.Json { + + public class FontFileInfo : IPackFileInfo + { + [JsonProperty("entry_name")] + public string EntryName { get; set; } + + public FontFileInfo() {} + + public FontFileInfo(string entryName) + { + EntryName = entryName; + } + } +} \ No newline at end of file diff --git a/TerrLauncherPackCreator/Code/Models/ModifiedFontModel.cs b/TerrLauncherPackCreator/Code/Models/ModifiedFontModel.cs new file mode 100644 index 0000000..91299b5 --- /dev/null +++ b/TerrLauncherPackCreator/Code/Models/ModifiedFontModel.cs @@ -0,0 +1,39 @@ +using System.Collections.ObjectModel; +using System.IO; +using JetBrains.Annotations; + +namespace TerrLauncherPackCreator.Code.Models +{ + public class ModifiedFontModel : ModifiedFileModel + { + [CanBeNull] + public string Prefix + { + get => _prefix; + set => SetProperty(ref _prefix, value); + } + private string _prefix; + + [CanBeNull] + public string Name + { + get => _name; + set => SetProperty(ref _name, value); + } + private string _name; + + [NotNull] + public ObservableCollection CommonPrefixes { get; } + + public ModifiedFontModel([NotNull] string filePath, bool isDragDropTarget) : base(filePath, isDragDropTarget) + { + _name = Path.GetFileNameWithoutExtension(filePath); + CommonPrefixes = new ObservableCollection + { + "", + "Content/Fonts" + }; + _prefix = CommonPrefixes[1]; + } + } +} \ No newline at end of file diff --git a/TerrLauncherPackCreator/Code/TemplateSelectors/ModifiedFileTemplateSelector.cs b/TerrLauncherPackCreator/Code/TemplateSelectors/ModifiedFileTemplateSelector.cs index 1d426cb..e995870 100644 --- a/TerrLauncherPackCreator/Code/TemplateSelectors/ModifiedFileTemplateSelector.cs +++ b/TerrLauncherPackCreator/Code/TemplateSelectors/ModifiedFileTemplateSelector.cs @@ -17,7 +17,7 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai var containerUi = (FrameworkElement) container; { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); } @@ -33,6 +33,9 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai case ModifiedGuiModel _: resourceName = "ModifiedGuiTemplate"; break; + case ModifiedFontModel _: + resourceName = "ModifiedFontTemplate"; + break; case ModifiedMapModel _: resourceName = "ModifiedMapTemplate"; break; diff --git a/TerrLauncherPackCreator/Code/Utils/PackUtils.cs b/TerrLauncherPackCreator/Code/Utils/PackUtils.cs index b41dd5a..e4825b9 100644 --- a/TerrLauncherPackCreator/Code/Utils/PackUtils.cs +++ b/TerrLauncherPackCreator/Code/Utils/PackUtils.cs @@ -22,7 +22,7 @@ public static partial class PackUtils static PackUtils() { { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; const int _ = 1 / (fileTypesHandled / TotalFileTypes) + 1 / (TotalFileTypes / fileTypesHandled); } @@ -34,9 +34,9 @@ static PackUtils() (FileType.Character, ".plr", ".character", StringResources.PackTypeCharacters), (FileType.Gui, ".png", ".gui", StringResources.PackTypeGui), (FileType.Translation, ".json", ".translation", StringResources.PackTypeTranslations), + (FileType.Font, ".png", ".font", StringResources.PackTypeFonts) // todo: add handling // (PackTypes.Audio, ".tla", ".ogg", ".audio", StringResources.PackTypeAudio), -// (PackTypes.Fonts, ".tlf", ".png", ".font", StringResources.PackTypeFonts), }; TranslationLanguages = new[] { "en-US", "de-DE", "it-IT", "fr-FR", "es-ES", "ru-RU", "pt-BR", /*"zh-Hans", "pl-PL", "ja-JP"*/ }; TranslationLanguageTitles = new[] { "English", "Deutsch", "Italiano", "Français", "Español", "Русский", "Português brasileiro" }; diff --git a/TerrLauncherPackCreator/Code/ViewModels/ConverterWindowViewModel.cs b/TerrLauncherPackCreator/Code/ViewModels/ConverterWindowViewModel.cs index 998ded1..1a275b9 100644 --- a/TerrLauncherPackCreator/Code/ViewModels/ConverterWindowViewModel.cs +++ b/TerrLauncherPackCreator/Code/ViewModels/ConverterWindowViewModel.cs @@ -111,7 +111,7 @@ private async void DropConvertedFilesCommand_Execute(string[] files) if (fileInfo != null) { { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); } @@ -138,6 +138,10 @@ private async void DropConvertedFilesCommand_Execute(string[] files) var translationInfo = (TranslationFileInfo) fileInfo; resultFileName = translationInfo.Language; break; + case FileType.Font: + var fontInfo = (FontFileInfo) fileInfo; + resultFileName = fontInfo.EntryName; + break; default: throw new ArgumentOutOfRangeException(); } diff --git a/TerrLauncherPackCreator/Code/ViewModels/PackCreationViewModel.cs b/TerrLauncherPackCreator/Code/ViewModels/PackCreationViewModel.cs index 71007f8..63be20a 100644 --- a/TerrLauncherPackCreator/Code/ViewModels/PackCreationViewModel.cs +++ b/TerrLauncherPackCreator/Code/ViewModels/PackCreationViewModel.cs @@ -428,7 +428,15 @@ private void DeleteModifiedItemCommand_Execute(ModifiedFileModel file) private bool SaveResourceCommand_CanExecute([NotNull] ModifiedFileModel file) { - return !Working && !file.IsDragDropTarget && (file is ModifiedTextureModel || file is ModifiedGuiModel); + { + const int fileTypesHandled = 6; + const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); + } + + return !Working && !file.IsDragDropTarget && ( + file is ModifiedTextureModel || file is ModifiedGuiModel || file is ModifiedFontModel + ); } private void SaveResourceCommand_Execute([NotNull] ModifiedFileModel file) @@ -436,10 +444,17 @@ private void SaveResourceCommand_Execute([NotNull] ModifiedFileModel file) if (string.IsNullOrEmpty(file.FilePath) || !File.Exists(file.FilePath)) return; + { + const int fileTypesHandled = 6; + const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); + } + string extension = file switch { ModifiedTextureModel _ => PackUtils.GetInitialFilesExt(FileType.Texture), ModifiedGuiModel _ => PackUtils.GetInitialFilesExt(FileType.Gui), + ModifiedFontModel _ => PackUtils.GetInitialFilesExt(FileType.Font), _ => throw new ArgumentOutOfRangeException(nameof(file)) }; @@ -548,7 +563,7 @@ private PackModel GeneratePackModel() .Select(it => { { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); } @@ -599,6 +614,14 @@ private PackModel GeneratePackModel() language: translationModel.CurrentLanguage ); break; + case FileType.Font: + var fontModel = (ModifiedFontModel) it.modified; + fileInfo = new FontFileInfo( + entryName: string.IsNullOrEmpty(fontModel.Prefix) + ? fontModel.Name + : $"{fontModel.Prefix}/{fontModel.Name}" + ); + break; default: throw new ArgumentOutOfRangeException(); } @@ -675,7 +698,7 @@ private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) private static ModifiedFileModel FileToModel(FileType fileType, [NotNull] string filePath, [CanBeNull] IPackFileInfo fileInfo) { { - const int fileTypesHandled = 5; + const int fileTypesHandled = 6; // ReSharper disable once UnusedVariable const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) + 1 / (PackUtils.TotalFileTypes / fileTypesHandled); @@ -747,6 +770,18 @@ private static ModifiedFileModel FileToModel(FileType fileType, [NotNull] string return model; } + case FileType.Font: + { + var model = new ModifiedFontModel(filePath, false); + if (fileInfo != null) + { + var info = (TextureFileInfo) fileInfo; + model.Prefix = null; + model.Name = info.EntryName; + } + + return model; + } default: throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null); } diff --git a/TerrLauncherPackCreator/Pages/PackCreation/PackCreationStep3.xaml b/TerrLauncherPackCreator/Pages/PackCreation/PackCreationStep3.xaml index e5bb33f..4cd6248 100644 --- a/TerrLauncherPackCreator/Pages/PackCreation/PackCreationStep3.xaml +++ b/TerrLauncherPackCreator/Pages/PackCreation/PackCreationStep3.xaml @@ -314,6 +314,61 @@ + + + + + + + + + + + + + + + + + +