Added AnimationExtensions.cs and moved java animation conversion to AnimationExtensions

This commit is contained in:
miku-666
2023-08-02 13:31:09 +02:00
parent 896e2f6671
commit 7f1c459c1d
4 changed files with 37 additions and 20 deletions

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using PckStudio.Internal;
namespace PckStudio.Extensions
{
internal static class AnimationExtensions
{
internal static JObject ConvertToJavaAnimation(this Animation animation)
{
JObject janimation = new JObject();
JObject mcmeta = new JObject();
mcmeta["comment"] = $"Animation converted with {Application.ProductName}";
mcmeta["animation"] = janimation;
JArray jframes = new JArray();
foreach (var frame in animation.GetFrames())
{
JObject jframe = new JObject();
jframe["index"] = animation.GetTextureIndex(frame.Texture);
jframe["time"] = frame.Ticks;
jframes.Add(jframe);
};
janimation["interpolation"] = animation.Interpolate;
janimation["frames"] = jframes;
return mcmeta;
}
}
}

View File

@@ -404,7 +404,7 @@ namespace PckStudio.Forms.Editor
fileDialog.Filter = "Animation Scripts (*.mcmeta)|*.png.mcmeta";
if (fileDialog.ShowDialog(this) == DialogResult.OK)
{
JObject mcmeta = AnimationResources.ConvertAnimationToJson(currentAnimation);
JObject mcmeta = currentAnimation.ConvertToJavaAnimation();
string jsondata = JsonConvert.SerializeObject(mcmeta, Formatting.Indented);
string filename = fileDialog.FileName;
File.WriteAllText(filename, jsondata);

View File

@@ -80,24 +80,5 @@ namespace PckStudio.Forms.Utilities
return _blockImageList;
}
}
internal static JObject ConvertAnimationToJson(Animation animation)
{
JObject janimation = new JObject();
JObject mcmeta = new JObject();
mcmeta["comment"] = $"Animation converted by {Application.ProductName}";
mcmeta["animation"] = janimation;
JArray jframes = new JArray();
foreach (var frame in animation.GetFrames())
{
JObject jframe = new JObject();
jframe["index"] = animation.GetTextureIndex(frame.Texture);
jframe["time"] = frame.Ticks;
jframes.Add(jframe);
};
janimation["interpolation"] = animation.Interpolate;
janimation["frames"] = jframes;
return mcmeta;
}
}
}

View File

@@ -178,6 +178,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Classes\Utils\BinkaConverter.cs" />
<Compile Include="Extensions\AnimationExtensions.cs" />
<Compile Include="Extensions\ImageLayoutDirection.cs" />
<Compile Include="Extensions\ImageSection.cs" />
<Compile Include="Extensions\ListExtensions.cs" />