Skip to content

Commit

Permalink
Proper names with extensions for extracted Bar items
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed May 21, 2020
1 parent e013e4b commit d12fae2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
37 changes: 37 additions & 0 deletions OpenKh.Tools.BarEditor/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using OpenKh.Kh2;
using static OpenKh.Kh2.Bar;
using System.Collections.Generic;

namespace OpenKh.Tools.BarEditor
{
public class Helpers
{
private static readonly string DefaultExtension = "bin";

private static readonly Dictionary<EntryType, string> SuggestedExtensions =
new Dictionary<Bar.EntryType, string>
{
[EntryType.Binary] = "bin",
[EntryType.Ai] = "ai",
[EntryType.Tim2] = "tm2",
[EntryType.SpawnPoint] = "pspwn",
[EntryType.SpawnScript] = "sspwn",
[EntryType.Bar] = "bar",
[EntryType.Pax] = "pax",
[EntryType.AnimationLoader] = "al",
[EntryType.Imgd] = "imd",
[EntryType.Seqd] = "2dd",
[EntryType.Layout] = "2ld",
[EntryType.Imgz] = "imz",
[EntryType.Seb] = "seb",
[EntryType.Wd] = "wd",
[EntryType.RawBitmap] = "rgb",
[EntryType.Vibration] = "vibration",
[EntryType.Vag] = "vag",

};

public static string GetSuggestedExtension(Bar.EntryType type) =>
SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension;
}
}
9 changes: 6 additions & 3 deletions OpenKh.Tools.BarEditor/ViewModels/BarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public BarViewModel(IEnumerable<BarEntryModel> list) :

ExportCommand = new RelayCommand(x =>
{
var defaultFileName = $"{SelectedItem.Entry.Name}.bin";
var defaultFileName = GetSuggestedFileName(SelectedItem.Entry);
FileDialog.OnSave(fileName =>
{
Expand All @@ -126,7 +126,7 @@ public BarViewModel(IEnumerable<BarEntryModel> list) :
{
foreach (var item in Items.Select(item => item.Entry))
{
var fileName = $"{item.Name}.bin";
var fileName = GetSuggestedFileName(item);
using (var fStream = File.OpenWrite(Path.Combine(folder, fileName)))
{
item.Stream.Position = 0;
Expand All @@ -153,7 +153,10 @@ public BarViewModel(IEnumerable<BarEntryModel> list) :
SearchCommand = new RelayCommand(x => { }, x => false);
}

private Window Window => Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);
private static string GetSuggestedFileName(Bar.Entry item) =>
$"{item.Name}_{item.Index}.{Helpers.GetSuggestedExtension(item.Type)}";

private Window Window => Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);

private string FileName { get; set; }

Expand Down

0 comments on commit d12fae2

Please sign in to comment.