Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	TerrLauncherPackCreator/Properties/AssemblyInfo.cs
  • Loading branch information
And42 committed Aug 19, 2020
2 parents 893b293 + 494c699 commit c23753d
Show file tree
Hide file tree
Showing 22 changed files with 432 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace TerrLauncherPackCreator.Code.Converters
{
public class TextureModelToAnimateInGuiVisibility : IMultiValueConverter
{
private static readonly object VisibleObject = Visibility.Visible;
private static readonly object CollapsedObject = Visibility.Collapsed;

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Debug.Assert(targetType == typeof(Visibility));
Expand All @@ -17,8 +20,8 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
TextureFileInfo.TextureType currentTextureType = (TextureFileInfo.TextureType) values[1];

return animated && currentTextureType == TextureFileInfo.TextureType.Item
? Visibility.Visible
: Visibility.Collapsed;
? VisibleObject
: CollapsedObject;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using TerrLauncherPackCreator.Code.Json;
using static TerrLauncherPackCreator.Code.Json.TextureFileInfo;

namespace TerrLauncherPackCreator.Code.Converters
{
public class TextureModelToFrameTimeVisibility : IMultiValueConverter
{
private static readonly IList<TextureType> FrameVisibleTypes = new List<TextureType> {
TextureType.Item,
TextureType.Npc,
TextureType.Buff,
TextureType.Extra
};
private static readonly object VisibleObject = Visibility.Visible;
private static readonly object CollapsedObject = Visibility.Collapsed;

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Debug.Assert(targetType == typeof(Visibility));

bool animated = (bool) values[0];
TextureFileInfo.TextureType currentTextureType = (TextureFileInfo.TextureType) values[1];
TextureType currentTextureType = (TextureType) values[1];

return animated && (currentTextureType == TextureFileInfo.TextureType.Item ||
currentTextureType == TextureFileInfo.TextureType.Npc ||
currentTextureType == TextureFileInfo.TextureType.Buff)
? Visibility.Visible
: Visibility.Collapsed;
return animated && FrameVisibleTypes.Contains(currentTextureType) ? VisibleObject : CollapsedObject;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using TerrLauncherPackCreator.Code.Json;
using static TerrLauncherPackCreator.Code.Json.TextureFileInfo;

namespace TerrLauncherPackCreator.Code.Converters
{
public class TextureModelToVerticalFramesVisibility : IMultiValueConverter
{
private static readonly IList<TextureType> VerticalFramesVisibleTypes = new List<TextureType> {
TextureType.Item,
TextureType.Buff,
TextureType.Extra
};
private static readonly object VisibleObject = Visibility.Visible;
private static readonly object CollapsedObject = Visibility.Collapsed;

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Debug.Assert(targetType == typeof(Visibility));

bool animated = (bool) values[0];
TextureFileInfo.TextureType currentTextureType = (TextureFileInfo.TextureType) values[1];
TextureType currentTextureType = (TextureType) values[1];

return animated && (currentTextureType == TextureFileInfo.TextureType.Item ||
currentTextureType == TextureFileInfo.TextureType.Buff)
? Visibility.Visible
: Visibility.Collapsed;
return animated && VerticalFramesVisibleTypes.Contains(currentTextureType) ? VisibleObject : CollapsedObject;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
TextureFileInfo.TextureType.Item => StringResources.TextureTypeItem,
TextureFileInfo.TextureType.Npc => StringResources.TextureTypeNpc,
TextureFileInfo.TextureType.Buff => StringResources.TextureTypeBuff,
TextureFileInfo.TextureType.Extra => StringResources.TextureTypeExtra,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null)
};
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is string casted))
if (!(value is string cast))
return null;

if (casted == StringResources.TextureTypeGeneral)
if (cast == StringResources.TextureTypeGeneral)
return TextureFileInfo.TextureType.General;
if (casted == StringResources.TextureTypeItem)
if (cast == StringResources.TextureTypeItem)
return TextureFileInfo.TextureType.Item;
if (casted == StringResources.TextureTypeNpc)
if (cast == StringResources.TextureTypeNpc)
return TextureFileInfo.TextureType.Npc;
if (casted == StringResources.TextureTypeBuff)
if (cast == StringResources.TextureTypeBuff)
return TextureFileInfo.TextureType.Buff;
if (cast == StringResources.TextureTypeExtra)
return TextureFileInfo.TextureType.Extra;
return null;
}
}
Expand Down
9 changes: 4 additions & 5 deletions TerrLauncherPackCreator/Code/Enums/FileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ public enum FileType
Map,
Character,
Gui,
Translation
// todo: add
// Audio,
// Font,
Translation,
Font,
Audio
}
}

namespace TerrLauncherPackCreator.Code.Utils
{
public static partial class PackUtils
{
public const int TotalFileTypes = 5;
public const int TotalFileTypes = 7;
}
}
8 changes: 6 additions & 2 deletions TerrLauncherPackCreator/Code/Implementations/FileConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FileConverter : IFileConverter
throw new FileNotFoundException("File not found", targetFile);

{
const int fileTypesHandled = 5;
const int fileTypesHandled = 7;
const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) +
1 / (PackUtils.TotalFileTypes / fileTypesHandled);
}
Expand All @@ -58,12 +58,14 @@ public class FileConverter : IFileConverter
FileType.Character => JsonConvert.DeserializeObject<CharacterFileInfo>(configText),
FileType.Gui => JsonConvert.DeserializeObject<GuiFileInfo>(configText),
FileType.Translation => JsonConvert.DeserializeObject<TranslationFileInfo>(configText),
FileType.Font => JsonConvert.DeserializeObject<FontFileInfo>(configText),
FileType.Audio => JsonConvert.DeserializeObject<AudioFileInfo>(configText),
_ => throw new ArgumentOutOfRangeException()
};
}

{
const int fileTypesHandled = 5;
const int fileTypesHandled = 7;
const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) +
1 / (PackUtils.TotalFileTypes / fileTypesHandled);
}
Expand All @@ -77,6 +79,8 @@ public class FileConverter : IFileConverter
case FileType.Character:
case FileType.Gui:
case FileType.Translation:
case FileType.Font:
case FileType.Audio:
string uniqueFile = ApplicationDataUtils.GenerateNonExistentFilePath();
IOUtils.EnsureParentDirExists(uniqueFile);
File.Copy(targetFile, uniqueFile, overwrite: false);
Expand Down
18 changes: 18 additions & 0 deletions TerrLauncherPackCreator/Code/Json/AudioFileInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;
using TerrLauncherPackCreator.Code.Interfaces;

namespace TerrLauncherPackCreator.Code.Json {

public class AudioFileInfo : IPackFileInfo
{
[JsonProperty("entry_name")]
public string EntryName { get; set; }

public AudioFileInfo() {}

public AudioFileInfo(string entryName)
{
EntryName = entryName;
}
}
}
18 changes: 18 additions & 0 deletions TerrLauncherPackCreator/Code/Json/FontFileInfo.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 5 additions & 1 deletion TerrLauncherPackCreator/Code/Json/TextureFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public enum TextureType
General = 0,
Item = 1,
Npc = 2,
Buff = 3
Buff = 3,
Extra = 4
}

[JsonProperty("type")]
Expand All @@ -36,5 +37,8 @@ public enum TextureType

[JsonProperty("milliseconds_per_frame")]
public int MillisecondsPerFrame { get; set; } = 100;

[JsonProperty("apply_original_size")]
public bool ApplyOriginalSize { get; set; } = true;
}
}
39 changes: 39 additions & 0 deletions TerrLauncherPackCreator/Code/Models/ModifiedAudioModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Collections.ObjectModel;
using System.IO;
using JetBrains.Annotations;

namespace TerrLauncherPackCreator.Code.Models
{
public class ModifiedAudioModel : 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<string> CommonPrefixes { get; }

public ModifiedAudioModel([NotNull] string filePath, bool isDragDropTarget) : base(filePath, isDragDropTarget)
{
_name = Path.GetFileNameWithoutExtension(filePath);
CommonPrefixes = new ObservableCollection<string>
{
"",
"Content/Sounds"
};
Prefix = CommonPrefixes[1];
}
}
}
39 changes: 39 additions & 0 deletions TerrLauncherPackCreator/Code/Models/ModifiedFontModel.cs
Original file line number Diff line number Diff line change
@@ -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<string> CommonPrefixes { get; }

public ModifiedFontModel([NotNull] string filePath, bool isDragDropTarget) : base(filePath, isDragDropTarget)
{
_name = Path.GetFileNameWithoutExtension(filePath);
CommonPrefixes = new ObservableCollection<string>
{
"",
"Content/Fonts"
};
_prefix = CommonPrefixes[1];
}
}
}
11 changes: 10 additions & 1 deletion TerrLauncherPackCreator/Code/Models/ModifiedTextureModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public int MillisecondsPerFrame
set => SetProperty(ref _millisecondsPerFrame, value);
}
private int _millisecondsPerFrame;

public bool ApplyOriginalSize
{
get => _applyOriginalSize;
set => SetProperty(ref _applyOriginalSize, value);
}
private bool _applyOriginalSize;

[NotNull]
public ObservableCollection<string> CommonPrefixes { get; }
Expand All @@ -87,6 +94,7 @@ public ModifiedTextureModel([NotNull] string filePath, bool isDragDropTarget) :
_millisecondsPerFrame = 100;
_numberOfHorizontalFrames = 1;
_numberOfVerticalFrames = 1;
_applyOriginalSize = true;
CommonPrefixes = new ObservableCollection<string>
{
"",
Expand All @@ -97,7 +105,8 @@ public ModifiedTextureModel([NotNull] string filePath, bool isDragDropTarget) :
TextureFileInfo.TextureType.General,
TextureFileInfo.TextureType.Item,
TextureFileInfo.TextureType.Npc,
TextureFileInfo.TextureType.Buff
TextureFileInfo.TextureType.Buff,
TextureFileInfo.TextureType.Extra
};
_prefix = CommonPrefixes[1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai
var containerUi = (FrameworkElement) container;

{
const int fileTypesHandled = 5;
const int fileTypesHandled = 7;
const int _ = 1 / (fileTypesHandled / PackUtils.TotalFileTypes) +
1 / (PackUtils.TotalFileTypes / fileTypesHandled);
}
Expand All @@ -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;
Expand All @@ -42,6 +45,9 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai
case ModifiedTranslationModel _:
resourceName = "ModifiedTranslationTemplate";
break;
case ModifiedAudioModel _:
resourceName = "ModifiedAudioTemplate";
break;
default:
resourceName = "ModifiedFileDataTemplate";
break;
Expand Down
Loading

0 comments on commit c23753d

Please sign in to comment.