mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 01:06:35 +00:00
Format extension classes and remove unnecessary using statements
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using AnimatedGif;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PckStudio.Internal;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace PckStudio.Extensions
|
||||
public static IEnumerable<(int index, T value)>enumerate<T>(this IEnumerable<T> array)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var item in array)
|
||||
foreach (T item in array)
|
||||
{
|
||||
yield return (i++, item);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace PckStudio.Extensions
|
||||
|
||||
public static bool EqualsAny<T>(this T type, params T[] items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
foreach (T item in items)
|
||||
{
|
||||
if (item.Equals(type))
|
||||
return true;
|
||||
@@ -27,7 +27,7 @@ namespace PckStudio.Extensions
|
||||
|
||||
public static bool ContainsAny<T>(this IEnumerable<T> array, params T[] items)
|
||||
{
|
||||
foreach (var item in array)
|
||||
foreach (T item in array)
|
||||
{
|
||||
if (items.Contains(item))
|
||||
return true;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
@@ -38,7 +34,7 @@ namespace PckStudio.Extensions
|
||||
|
||||
internal static Graphics Fill(this Graphics graphics, Rectangle area, Color color)
|
||||
{
|
||||
var clip = graphics.Clip;
|
||||
Region clip = graphics.Clip;
|
||||
graphics.SetClip(area, CombineMode.Replace);
|
||||
graphics.Clear(color);
|
||||
graphics.SetClip(clip, CombineMode.Replace);
|
||||
|
||||
@@ -23,7 +23,6 @@ using System.Drawing.Drawing2D;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Linq;
|
||||
using PckStudio.Internal;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using PckStudio.Internal.App;
|
||||
@@ -106,8 +105,6 @@ namespace PckStudio.Extensions
|
||||
private static Size CalculateImageSize(IEnumerable<Image> sources, ImageLayoutDirection layoutDirection)
|
||||
{
|
||||
Size size = sources.First().Size;
|
||||
int width = size.Width;
|
||||
int height = size.Height;
|
||||
int count = sources.Count();
|
||||
|
||||
if (count < 2)
|
||||
@@ -115,15 +112,15 @@ namespace PckStudio.Extensions
|
||||
|
||||
var horizontal = layoutDirection == ImageLayoutDirection.Horizontal;
|
||||
|
||||
if (!sources.All(img => img.Width.Equals(width) && img.Height.Equals(height)))
|
||||
if (!sources.All(img => img.Size == size))
|
||||
throw new InvalidOperationException("Images must have the same width and height.");
|
||||
|
||||
if (horizontal)
|
||||
width *= count;
|
||||
size.Width *= count;
|
||||
else
|
||||
height *= count;
|
||||
size.Height *= count;
|
||||
|
||||
return new Size(width, height);
|
||||
return size;
|
||||
}
|
||||
|
||||
internal static Image Resize(this Image image, Size size, GraphicsConfig graphicsConfig)
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.Languages;
|
||||
using OMI.Formats.Languages;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
@@ -15,7 +10,7 @@ namespace PckStudio.Extensions
|
||||
public static void Initialize(this LOCFile locFile, string language, params (string, string)[] locKeyValuePairs)
|
||||
{
|
||||
locFile.AddLanguage(language);
|
||||
foreach (var locKeyValue in locKeyValuePairs)
|
||||
foreach ((string, string) locKeyValue in locKeyValuePairs)
|
||||
locFile.AddLocKey(locKeyValue.Item1, locKeyValue.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.Material;
|
||||
using OMI.Formats.Material;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
@@ -10,8 +6,10 @@ namespace PckStudio.Extensions
|
||||
{
|
||||
internal static T Clamp<T>(T value, T min, T max) where T : IComparable<T>
|
||||
{
|
||||
if (value.CompareTo(min) < 0) return min;
|
||||
if (value.CompareTo(max) > 0) return max;
|
||||
if (value.CompareTo(min) < 0)
|
||||
return min;
|
||||
if (value.CompareTo(max) > 0)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.Pck;
|
||||
using OMI.Workers;
|
||||
using PckStudio.Interfaces;
|
||||
@@ -104,7 +100,7 @@ namespace PckStudio.Extensions
|
||||
internal static string SerializePropertiesToString(this PckAsset asset)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(asset.PropertyCount * 20);
|
||||
foreach (var property in asset.GetProperties())
|
||||
foreach (KeyValuePair<string, string> property in asset.GetProperties())
|
||||
{
|
||||
builder.AppendLine(property.Key + ": " + property.Value);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.Pck;
|
||||
using OMI.Formats.Pck;
|
||||
using OMI.Workers;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
@@ -22,7 +16,7 @@ namespace PckStudio.Extensions
|
||||
|
||||
internal static PckAsset CreateNewAsset(this PckFile pck, string filename, PckAssetType filetype, IDataFormatWriter writer)
|
||||
{
|
||||
var asset = pck.CreateNewAsset(filename, filetype);
|
||||
PckAsset asset = pck.CreateNewAsset(filename, filetype);
|
||||
asset.SetData(writer);
|
||||
return asset;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
@@ -12,13 +8,13 @@ namespace PckStudio.Extensions
|
||||
{
|
||||
public static bool IsAnimating(this PictureBox pictureBox)
|
||||
{
|
||||
var fi = typeof(PictureBox).GetField("currentlyAnimating", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
FieldInfo fi = typeof(PictureBox).GetField("currentlyAnimating", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
return (bool)fi.GetValue(pictureBox);
|
||||
}
|
||||
|
||||
public static void Animate(this PictureBox pictureBox, bool animate)
|
||||
{
|
||||
var animateMethod = typeof(PictureBox).GetMethod("Animate", BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
MethodInfo animateMethod = typeof(PictureBox).GetMethod("Animate", BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null, new Type[] { typeof(bool) }, null);
|
||||
animateMethod.Invoke(pictureBox, new object[] { animate });
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
@@ -16,9 +12,9 @@ namespace PckStudio.Extensions
|
||||
|
||||
internal static bool TryGetTagData<TOut>(this TreeNode node, out TOut tagData) where TOut : class
|
||||
{
|
||||
if (node?.Tag is TOut _data)
|
||||
if (node?.Tag is TOut data)
|
||||
{
|
||||
tagData = _data;
|
||||
tagData = data;
|
||||
return true;
|
||||
}
|
||||
tagData = default;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using PckStudio.Internal.App;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
@@ -23,7 +19,7 @@ namespace PckStudio.Extensions
|
||||
string segment = path.Substring(0, path.IndexOf(treeView.PathSeparator));
|
||||
if (treeView.Nodes.ContainsKey(segment))
|
||||
{
|
||||
var res = treeView.Nodes[segment].GetChildNodes().Where(node => node.FullPath == path).ToArray();
|
||||
TreeNode[] res = treeView.Nodes[segment].GetChildNodes().Where(node => node.FullPath == path).ToArray();
|
||||
return res;
|
||||
}
|
||||
return Array.Empty<TreeNode>();
|
||||
|
||||
Reference in New Issue
Block a user