From 7f1c459c1ddef1224648290df37408a2a9b1378a Mon Sep 17 00:00:00 2001
From: miku-666 <74728189+NessieHax@users.noreply.github.com>
Date: Wed, 2 Aug 2023 13:31:09 +0200
Subject: [PATCH] Added AnimationExtensions.cs and moved java animation
conversion to AnimationExtensions
---
PCK-Studio/Extensions/AnimationExtensions.cs | 35 +++++++++++++++++++
PCK-Studio/Forms/Editor/AnimationEditor.cs | 2 +-
.../Forms/Utilities/AnimationResources.cs | 19 ----------
PCK-Studio/PckStudio.csproj | 1 +
4 files changed, 37 insertions(+), 20 deletions(-)
create mode 100644 PCK-Studio/Extensions/AnimationExtensions.cs
diff --git a/PCK-Studio/Extensions/AnimationExtensions.cs b/PCK-Studio/Extensions/AnimationExtensions.cs
new file mode 100644
index 00000000..4c7aeb3f
--- /dev/null
+++ b/PCK-Studio/Extensions/AnimationExtensions.cs
@@ -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;
+ }
+
+ }
+}
diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.cs b/PCK-Studio/Forms/Editor/AnimationEditor.cs
index 4a064d6f..fbecaecb 100644
--- a/PCK-Studio/Forms/Editor/AnimationEditor.cs
+++ b/PCK-Studio/Forms/Editor/AnimationEditor.cs
@@ -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);
diff --git a/PCK-Studio/Forms/Utilities/AnimationResources.cs b/PCK-Studio/Forms/Utilities/AnimationResources.cs
index df887429..c803c434 100644
--- a/PCK-Studio/Forms/Utilities/AnimationResources.cs
+++ b/PCK-Studio/Forms/Utilities/AnimationResources.cs
@@ -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;
- }
}
}
diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj
index dc588039..4c746964 100644
--- a/PCK-Studio/PckStudio.csproj
+++ b/PCK-Studio/PckStudio.csproj
@@ -178,6 +178,7 @@
Component
+