From 6e09a9c42786c3ccc96557741eb74b5132d80427 Mon Sep 17 00:00:00 2001
From: miku-666 <74728189+NessieHax@users.noreply.github.com>
Date: Sun, 13 Aug 2023 15:30:18 +0200
Subject: [PATCH] ImageExtensions - Renamed 'CreateImageList' to 'Split' and
'SplitHorizontal' respectively
---
PCK-Studio/Extensions/ImageExtensions.cs | 28 ++++++++-----------
PCK-Studio/Forms/Editor/AnimationEditor.cs | 6 ++--
PCK-Studio/Forms/Editor/TextureAtlasEditor.cs | 4 +--
PCK-Studio/Helper/AnimationResources.cs | 4 +--
PCK-Studio/Internal/Animation.cs | 2 +-
PCK-Studio/Internal/ApplicationScope.cs | 2 +-
6 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/PCK-Studio/Extensions/ImageExtensions.cs b/PCK-Studio/Extensions/ImageExtensions.cs
index 496fb0b6..994b0588 100644
--- a/PCK-Studio/Extensions/ImageExtensions.cs
+++ b/PCK-Studio/Extensions/ImageExtensions.cs
@@ -45,30 +45,26 @@ namespace PckStudio.Extensions
}
///
- /// Creates an image array by reading in horizontal order
+ /// Creates an IEnumerable by reading in horizontal order
///
- ///
- /// Size of individual image inside of
- internal static IEnumerable CreateImageList(this Image source, Size size)
+ /// this image
+ /// Indecates width and height of image sub section
+ /// of type
+ internal static IEnumerable SplitHorizontal(this Image source, int scalar)
{
- return source.CreateImageList(size, ImageLayoutDirection.Horizontal);
+ return source.Split(scalar, ImageLayoutDirection.Horizontal);
}
- internal static IEnumerable CreateImageList(this Image source, int scalar)
+ internal static IEnumerable Split(this Image source, int scalar, ImageLayoutDirection layoutDirection)
{
- return source.CreateImageList(scalar, ImageLayoutDirection.Horizontal);
+ return Split(source, new Size(scalar, scalar), layoutDirection);
}
- internal static IEnumerable CreateImageList(this Image source, int scalar, ImageLayoutDirection layoutDirection)
- {
- return CreateImageList(source, new Size(scalar, scalar), layoutDirection);
- }
-
- internal static IEnumerable CreateImageList(this Image source, Size size, ImageLayoutDirection imageLayout)
+ internal static IEnumerable Split(this Image source, Size size, ImageLayoutDirection imageLayout)
{
int rowCount = source.Width / size.Width;
int columnCount = source.Height / size.Height;
- Debug.WriteLine($"{nameof(source.Size)}={source.Size}, {nameof(size)}={size}, {columnCount} {rowCount}");
+ Debug.WriteLine($"Image size: {source.Size}, Area size: {size}, col num: {columnCount}, row num: {rowCount}");
for (int i = 0; i < columnCount * rowCount; i++)
{
int row = Math.DivRem(i, rowCount, out int column);
@@ -80,7 +76,7 @@ namespace PckStudio.Extensions
yield break;
}
- internal static IEnumerable CreateImageList(this Image source, ImageLayoutDirection layoutDirection)
+ internal static IEnumerable Split(this Image source, ImageLayoutDirection layoutDirection)
{
for (int i = 0; i < source.Height / source.Width; i++)
{
@@ -90,7 +86,7 @@ namespace PckStudio.Extensions
yield break;
}
- internal static Image CombineImages(this IList sources, ImageLayoutDirection layoutDirection)
+ internal static Image Combine(this IList sources, ImageLayoutDirection layoutDirection)
{
Size imageSize = CalculateImageSize(sources, layoutDirection);
var image = new Bitmap(imageSize.Width, imageSize.Height);
diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.cs b/PCK-Studio/Forms/Editor/AnimationEditor.cs
index a8585abd..417637e8 100644
--- a/PCK-Studio/Forms/Editor/AnimationEditor.cs
+++ b/PCK-Studio/Forms/Editor/AnimationEditor.cs
@@ -82,7 +82,7 @@ namespace PckStudio.Forms.Editor
{
using MemoryStream textureMem = new MemoryStream(animationFile.Data);
var texture = new Bitmap(textureMem);
- var frameTextures = texture.CreateImageList(ImageLayoutDirection.Vertical);
+ var frameTextures = texture.Split(ImageLayoutDirection.Vertical);
currentAnimation = animationFile.Properties.HasProperty("ANIM")
? new Animation(frameTextures, animationFile.Properties.GetPropertyValue("ANIM"))
: new Animation(frameTextures, string.Empty);
@@ -329,7 +329,7 @@ namespace PckStudio.Forms.Editor
MessageBox.Show(textureFile + " was not found", "Texture not found");
return;
}
- var textures = Image.FromFile(textureFile).CreateImageList(ImageLayoutDirection.Vertical);
+ var textures = Image.FromFile(textureFile).Split(ImageLayoutDirection.Vertical);
var new_animation = new Animation(textures);
new_animation.Category = currentAnimation.Category;
try
@@ -527,7 +527,7 @@ namespace PckStudio.Forms.Editor
if (ofd.ShowDialog() != DialogResult.OK)
return;
Image img = Image.FromFile(ofd.FileName);
- var textures = img.CreateImageList(ImageLayoutDirection.Vertical);
+ var textures = img.Split(ImageLayoutDirection.Vertical);
currentAnimation = new Animation(textures, string.Empty);
LoadAnimationTreeView();
}
diff --git a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs
index ce5db919..acaecc62 100644
--- a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs
+++ b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs
@@ -95,7 +95,7 @@ namespace PckStudio.Forms.Editor
_ => (null, null),
};
originalPictureBox.Image = atlas;
- var images = atlas.CreateImageList(_areaSize, _imageLayout);
+ var images = atlas.Split(_areaSize, _imageLayout);
var tiles = images.enumerate().Select(
p => new AtlasTile(p.index, GetAtlasArea(p.index, _rowCount, _columnCount, _areaSize, _imageLayout), tileInfos.IndexInRange(p.index) ? tileInfos[p.index] : null, p.value)
@@ -158,7 +158,7 @@ namespace PckStudio.Forms.Editor
{
using var ms = new MemoryStream(animationFile.Data);
var img = Image.FromStream(ms);
- var textures = img.CreateImageList(ImageLayoutDirection.Vertical);
+ var textures = img.Split(ImageLayoutDirection.Vertical);
var animation = new Internal.Animation(textures, animationFile.Properties.GetPropertyValue("ANIM"));
selectTilePictureBox.Start(animation);
return;
diff --git a/PCK-Studio/Helper/AnimationResources.cs b/PCK-Studio/Helper/AnimationResources.cs
index 730d5ec6..8e6a5c81 100644
--- a/PCK-Studio/Helper/AnimationResources.cs
+++ b/PCK-Studio/Helper/AnimationResources.cs
@@ -23,10 +23,10 @@ namespace PckStudio.Helper
internal static List BlockTileInfos => JsonTileData.Blocks;
private static Image[] _itemImages;
- public static Image[] ItemImages => _itemImages ??= Resources.items_sheet.CreateImageList(16).ToArray();
+ public static Image[] ItemImages => _itemImages ??= Resources.items_sheet.SplitHorizontal(16).ToArray();
private static Image[] _blockImages;
- public static Image[] BlockImages => _blockImages ??= Resources.terrain_sheet.CreateImageList(16).ToArray();
+ public static Image[] BlockImages => _blockImages ??= Resources.terrain_sheet.SplitHorizontal(16).ToArray();
private static ImageList _itemImageList;
public static ImageList ItemImageList
diff --git a/PCK-Studio/Internal/Animation.cs b/PCK-Studio/Internal/Animation.cs
index 16c133f2..4d9c972b 100644
--- a/PCK-Studio/Internal/Animation.cs
+++ b/PCK-Studio/Internal/Animation.cs
@@ -189,7 +189,7 @@ namespace PckStudio.Internal
if (textures[0].Width != textures[0].Height)
throw new Exception("Invalid size");
- return textures.CombineImages(ImageLayoutDirection.Vertical);
+ return textures.Combine(ImageLayoutDirection.Vertical);
}
}
}
diff --git a/PCK-Studio/Internal/ApplicationScope.cs b/PCK-Studio/Internal/ApplicationScope.cs
index 2b151044..379f0967 100644
--- a/PCK-Studio/Internal/ApplicationScope.cs
+++ b/PCK-Studio/Internal/ApplicationScope.cs
@@ -22,7 +22,7 @@ namespace PckStudio.Internal
Profiler.Configure(Debug.Listeners[0]);
Profiler.Start();
{
- _entityImages ??= Resources.entities_sheet.CreateImageList(32).ToArray();
+ _entityImages ??= Resources.entities_sheet.SplitHorizontal(32).ToArray();
DataCacher ??= new FileCacher(Program.AppDataCache);
_ = AnimationResources.JsonTileData;
_ = AnimationResources.ItemImageList;