Skip to content

Commit

Permalink
Merge pull request #1365 from VladiStep/spriteExportPadded
Browse files Browse the repository at this point in the history
  • Loading branch information
Grossley authored May 5, 2023
2 parents 2e2f845 + 734a5a0 commit 9acea03
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions UndertaleModTool/Editors/UndertaleSpriteEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UndertaleModLib.Models;
using UndertaleModLib.Util;

Expand All @@ -42,10 +41,10 @@ private void ExportAllSpine(SaveFileDialog dlg, UndertaleSprite sprite)
{
try
{
string dir = System.IO.Path.GetDirectoryName(dlg.FileName);
string name = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName);
string path = System.IO.Path.Combine(dir, name);
string ext = System.IO.Path.GetExtension(dlg.FileName);
string dir = Path.GetDirectoryName(dlg.FileName);
string name = Path.GetFileNameWithoutExtension(dlg.FileName);
string path = Path.Combine(dir, name);
string ext = Path.GetExtension(dlg.FileName);

if (sprite.SpineTextures.Count > 0)
{
Expand All @@ -56,7 +55,7 @@ private void ExportAllSpine(SaveFileDialog dlg, UndertaleSprite sprite)
{
try
{
File.WriteAllBytes(System.IO.Path.Combine(path, tex.id + ext), tex.tex.TexBlob);
File.WriteAllBytes(Path.Combine(path, tex.id + ext), tex.tex.TexBlob);
}
catch (Exception ex)
{
Expand All @@ -65,8 +64,8 @@ private void ExportAllSpine(SaveFileDialog dlg, UndertaleSprite sprite)
}

// json and atlas
File.WriteAllText(System.IO.Path.Combine(path, "spine.json"), sprite.SpineJSON);
File.WriteAllText(System.IO.Path.Combine(path, "spine.atlas"), sprite.SpineAtlas);
File.WriteAllText(Path.Combine(path, "spine.json"), sprite.SpineJSON);
File.WriteAllText(Path.Combine(path, "spine.atlas"), sprite.SpineAtlas);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -98,19 +97,23 @@ private void ExportAll_Click(object sender, RoutedEventArgs e)
{
try
{
bool includePadding = false;
if (mainWindow.ShowQuestion("Include padding?") == MessageBoxResult.Yes)
includePadding = true;

if (sprite.Textures.Count > 1)
{
string dir = System.IO.Path.GetDirectoryName(dlg.FileName);
string name = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName);
string path = System.IO.Path.Combine(dir, name);
string ext = System.IO.Path.GetExtension(dlg.FileName);
string dir = Path.GetDirectoryName(dlg.FileName);
string name = Path.GetFileNameWithoutExtension(dlg.FileName);
string path = Path.Combine(dir, name);
string ext = Path.GetExtension(dlg.FileName);

Directory.CreateDirectory(path);
foreach (var tex in sprite.Textures.Select((tex, id) => new { id, tex }))
{
try
{
worker.ExportAsPNG(tex.tex.Texture, System.IO.Path.Combine(path, sprite.Name.Content + "_" + tex.id + ext));
worker.ExportAsPNG(tex.tex.Texture, Path.Combine(path, sprite.Name.Content + "_" + tex.id + ext), null, includePadding);
}
catch (Exception ex)
{
Expand All @@ -122,7 +125,7 @@ private void ExportAll_Click(object sender, RoutedEventArgs e)
{
try
{
worker.ExportAsPNG(sprite.Textures[0].Texture, dlg.FileName);
worker.ExportAsPNG(sprite.Textures[0].Texture, dlg.FileName, null, includePadding);
}
catch (Exception ex)
{
Expand Down

0 comments on commit 9acea03

Please sign in to comment.