mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-20 04:25:40 +00:00
EnumerableExtensions - Remove Enumerate<T> extension
This commit is contained in:
@@ -69,11 +69,12 @@ namespace PckStudio.Controls
|
||||
_imageList.Images.Clear();
|
||||
textureTreeView.Nodes.Clear();
|
||||
|
||||
foreach ((int i, NamedData<Image> item) in textures.Enumerate())
|
||||
textureTreeView.Nodes.AddRange(textures.Select((v, i) =>
|
||||
{
|
||||
_imageList.Images.Add(item.Value);
|
||||
textureTreeView.Nodes.Add(new NamedTextureTreeNode(item) { ImageIndex = i, SelectedImageIndex = i });
|
||||
}
|
||||
_imageList.Images.Add(v.Value);
|
||||
return new NamedTextureTreeNode(v) { ImageIndex = i, SelectedImageIndex = i };
|
||||
}).ToArray());
|
||||
|
||||
if (textures.Length > 0)
|
||||
{
|
||||
modelRenderer.Texture = textures[0].Value;
|
||||
|
||||
@@ -47,11 +47,10 @@ namespace PckStudio.Controls
|
||||
{
|
||||
treeView1.Nodes.AddRange(
|
||||
skins
|
||||
.Enumerate()
|
||||
.Select(a =>
|
||||
.Select((skin, i) =>
|
||||
{
|
||||
_imageList.Images.Add(a.value.GetPreviewImage(_imageList.ImageSize));
|
||||
return new TreeNode(a.value.MetaData.Name) { ImageIndex = a.index, SelectedImageIndex = a.index, Tag = a.value };
|
||||
_imageList.Images.Add(skin.GetPreviewImage(_imageList.ImageSize));
|
||||
return new TreeNode(skin.MetaData.Name) { ImageIndex = i, SelectedImageIndex = i, Tag = skin };
|
||||
})
|
||||
.ToArray()
|
||||
);
|
||||
|
||||
@@ -228,11 +228,12 @@ namespace PckStudio.Forms.Editor
|
||||
textureImageList.Images.Clear();
|
||||
namedTexturesTreeView.Nodes.Clear();
|
||||
|
||||
foreach ((int i, NamedData<Image> item) in textures.Enumerate())
|
||||
namedTexturesTreeView.Nodes.AddRange(textures.Select((item, i) =>
|
||||
{
|
||||
textureImageList.Images.Add(item.Value);
|
||||
namedTexturesTreeView.Nodes.Add(new NamedTextureTreeNode(item) { ImageIndex = i, SelectedImageIndex = i });
|
||||
}
|
||||
return new NamedTextureTreeNode(item) { ImageIndex = i, SelectedImageIndex = i };
|
||||
}).ToArray());
|
||||
|
||||
if (textures.Length != 0)
|
||||
modelViewport.Texture = textures[0].Value;
|
||||
|
||||
|
||||
@@ -83,14 +83,12 @@ namespace PckStudio.Core
|
||||
return Enumerable.Empty<NamedData<Image>>();
|
||||
|
||||
IEnumerable<NamedData<Image>> textures = armorSet.BaseTexture.Split(new Size(armorSet.BaseTexture.Width, armorSet.BaseTexture.Height / 2), ImageLayoutDirection.Horizontal)
|
||||
.Enumerate()
|
||||
.Select(e => new NamedData<Image>($"{armorSet.Name}_{e.index + 1}", e.value));
|
||||
.Select((e, i) => new NamedData<Image>($"{armorSet.Name}_{i + 1}", e));
|
||||
|
||||
if (armorSetDescription.LayerCount > 0 && armorSet.Layer is not null)
|
||||
{
|
||||
textures = textures.Concat(armorSet.Layer.Split(new Size(armorSet.Layer.Width, armorSet.Layer.Height / 2), ImageLayoutDirection.Horizontal)
|
||||
.Enumerate()
|
||||
.Select(e => new NamedData<Image>($"{armorSet.Name}_{e.index + 1}_{Convert.ToChar('b')}", e.value)));
|
||||
.Select((e, i) => new NamedData<Image>($"{armorSet.Name}_{i + 1}_{Convert.ToChar('b')}", e)));
|
||||
}
|
||||
|
||||
if (armorSet.Name == TURTLE)
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace PckStudio.Core
|
||||
int rows = source.Width / tileArea.Width;
|
||||
int columns = GameConstants.GetColumnCountForGameVersion(atlasResource.Type, gameVersion);
|
||||
columns = columns == 0 ? source.Height / tileArea.Height : columns;
|
||||
IEnumerable <AtlasTile> tiles = source.Split(tileArea, imageLayout).Enumerate().Select(((int index, Image img) data) => new AtlasTile(data.img, GetSelectedPoint(data.index, out int col, rows, columns, imageLayout), col, index: data.index, userData: tilesInfo.IndexInRange(data.index) ? tilesInfo[data.index] : default));
|
||||
IEnumerable <AtlasTile> tiles = source.Split(tileArea, imageLayout).Select((Image img, int index) => new AtlasTile(img, GetSelectedPoint(index, out int col, rows, columns, imageLayout), col, index: index, userData: tilesInfo.IndexInRange(index) ? tilesInfo[index] : default));
|
||||
var atlas = new Atlas(atlasResource.Path, rows, columns, tiles, tileArea, imageLayout);
|
||||
atlas.AddGroups(atlasResource.AtlasGroups);
|
||||
return atlas;
|
||||
@@ -74,7 +74,7 @@ namespace PckStudio.Core
|
||||
{
|
||||
ImageLayoutDirection layoutDirection = default;
|
||||
Image none = new Bitmap(res, res);
|
||||
IEnumerable<AtlasTile> tiles = Enumerable.Repeat(none, rows * columns).Enumerate().Select(iv => new AtlasTile(iv.value, GetSelectedPoint(iv.index, out int col, rows, columns, layoutDirection), col, iv.index, default));
|
||||
IEnumerable<AtlasTile> tiles = Enumerable.Repeat(none, rows * columns).Select((v, i) => new AtlasTile(v, GetSelectedPoint(i, out int col, rows, columns, layoutDirection), col, i, default));
|
||||
return new Atlas(atlasResource.Path, rows, columns, tiles, none.Size, layoutDirection);
|
||||
}
|
||||
|
||||
@@ -271,8 +271,9 @@ namespace PckStudio.Core
|
||||
|
||||
public bool SetGroup(AtlasGroup group, Image texture)
|
||||
{
|
||||
Image[] images = texture.Split(TileSize, _layoutDirection).ToArray();
|
||||
if (!images.All(img => img.Size == TileSize))
|
||||
Size splitSize = group.IsLargeTile() ? new Size(texture.Width / ((AtlasLargeTile)group).RowSpan, texture.Height /((AtlasLargeTile)group).ColumnSpan) : TileSize;
|
||||
Image[] images = texture.Split(splitSize, _layoutDirection).ToArray();
|
||||
if (!images.All(img => img.Size == splitSize))
|
||||
return false;
|
||||
if (images.Length != group.Count)
|
||||
return false;
|
||||
|
||||
@@ -131,9 +131,10 @@ namespace PckStudio.Core.DLC
|
||||
}
|
||||
|
||||
{
|
||||
foreach ((int i, Animation.Frame frame) in texturePackage.GetBlockEntityBreakAnimation().GetFrames().Enumerate())
|
||||
int i = 0;
|
||||
foreach (Animation.Frame frame in texturePackage.GetBlockEntityBreakAnimation().GetFrames())
|
||||
{
|
||||
texturePck.AddTexture($"res/textures/destroy_stage_{i}.png", frame.Texture);
|
||||
texturePck.AddTexture($"res/textures/destroy_stage_{i++}.png", frame.Texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace PckStudio.Core.Extensions
|
||||
|
||||
Image[] secondTextures = second.GetTextures().ToArray();
|
||||
|
||||
Animation animation = new Animation(first.GetTextures().Enumerate().Select(ift => ift.value.Combine(secondTextures[ift.index], layoutDirection)));
|
||||
Animation animation = new Animation(first.GetTextures().Select((tex, i) => tex.Combine(secondTextures[i], layoutDirection)));
|
||||
foreach ((int texId, int frameTime) item in first.GetFrames().Select(f => (texId: first.GetTextureIndex(f.Texture), frameTime: f.Ticks)))
|
||||
{
|
||||
animation.AddFrame(item.texId, item.frameTime);
|
||||
|
||||
@@ -7,16 +7,6 @@ namespace PckStudio.Core.Extensions
|
||||
{
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static IEnumerable<(int index, T value)>Enumerate<T>(this IEnumerable<T> array)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (T item in array)
|
||||
{
|
||||
yield return (i++, item);
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
public static ImageList ToImageList(this IEnumerable<Image> images)
|
||||
{
|
||||
ImageList imageList = new ImageList
|
||||
|
||||
@@ -150,11 +150,13 @@ namespace PckStudio.Core.Extensions
|
||||
using (var graphic = Graphics.FromImage(image))
|
||||
{
|
||||
graphic.ApplyConfig(GraphicsConfig.PixelPerfect());
|
||||
foreach ((int i, Image texture) in sources.Enumerate())
|
||||
int i = 0;
|
||||
foreach (Image texture in sources)
|
||||
{
|
||||
int x = Math.DivRem(i, columns, out int y);
|
||||
if (horizontal)
|
||||
y = Math.DivRem(i, rows, out x);
|
||||
i++;
|
||||
graphic.DrawImage(texture, new Rectangle(new Point(x * texture.Width, y * texture.Height), texture.Size));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,19 +155,19 @@
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash0",
|
||||
"displayName": "Firework Flash"
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash1",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash2",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash3",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
@@ -219,19 +219,19 @@
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash4",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash5",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash6",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash7",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
@@ -284,19 +284,19 @@
|
||||
"displayName": "Damage Indicator"
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash8",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash9",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash10",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash11",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
@@ -348,19 +348,19 @@
|
||||
"displayName": "Angry Villager (Unused)"
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash12",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash13",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash14",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
"internalName": "flash",
|
||||
"internalName": "flash15",
|
||||
"displayName": ""
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user