diff --git a/PCK-Studio/Controls/ModelsPanel.cs b/PCK-Studio/Controls/ModelsPanel.cs index 1b532a06..3dc5ecf9 100644 --- a/PCK-Studio/Controls/ModelsPanel.cs +++ b/PCK-Studio/Controls/ModelsPanel.cs @@ -69,11 +69,12 @@ namespace PckStudio.Controls _imageList.Images.Clear(); textureTreeView.Nodes.Clear(); - foreach ((int i, NamedData 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; diff --git a/PCK-Studio/Controls/SkinsPanel.cs b/PCK-Studio/Controls/SkinsPanel.cs index 80490824..87fac9c5 100644 --- a/PCK-Studio/Controls/SkinsPanel.cs +++ b/PCK-Studio/Controls/SkinsPanel.cs @@ -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() ); diff --git a/PCK-Studio/Forms/Editor/ModelEditor.cs b/PCK-Studio/Forms/Editor/ModelEditor.cs index 7e5538ab..cb257ea9 100644 --- a/PCK-Studio/Forms/Editor/ModelEditor.cs +++ b/PCK-Studio/Forms/Editor/ModelEditor.cs @@ -228,11 +228,12 @@ namespace PckStudio.Forms.Editor textureImageList.Images.Clear(); namedTexturesTreeView.Nodes.Clear(); - foreach ((int i, NamedData 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; diff --git a/PckStudio.Core/ArmorSetDescription.cs b/PckStudio.Core/ArmorSetDescription.cs index 19969df9..a9f7f406 100644 --- a/PckStudio.Core/ArmorSetDescription.cs +++ b/PckStudio.Core/ArmorSetDescription.cs @@ -83,14 +83,12 @@ namespace PckStudio.Core return Enumerable.Empty>(); IEnumerable> textures = armorSet.BaseTexture.Split(new Size(armorSet.BaseTexture.Width, armorSet.BaseTexture.Height / 2), ImageLayoutDirection.Horizontal) - .Enumerate() - .Select(e => new NamedData($"{armorSet.Name}_{e.index + 1}", e.value)); + .Select((e, i) => new NamedData($"{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($"{armorSet.Name}_{e.index + 1}_{Convert.ToChar('b')}", e.value))); + .Select((e, i) => new NamedData($"{armorSet.Name}_{i + 1}_{Convert.ToChar('b')}", e))); } if (armorSet.Name == TURTLE) diff --git a/PckStudio.Core/Atlas/Atlas.cs b/PckStudio.Core/Atlas/Atlas.cs index b6951b1b..429ac6f7 100644 --- a/PckStudio.Core/Atlas/Atlas.cs +++ b/PckStudio.Core/Atlas/Atlas.cs @@ -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 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 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 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 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; diff --git a/PckStudio.Core/DLC/PckFileCompiler.cs b/PckStudio.Core/DLC/PckFileCompiler.cs index 4248fefc..175e4d3f 100644 --- a/PckStudio.Core/DLC/PckFileCompiler.cs +++ b/PckStudio.Core/DLC/PckFileCompiler.cs @@ -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); } } diff --git a/PckStudio.Core/Extensions/AnimationExtensions.cs b/PckStudio.Core/Extensions/AnimationExtensions.cs index 8b955c7a..9fed3975 100644 --- a/PckStudio.Core/Extensions/AnimationExtensions.cs +++ b/PckStudio.Core/Extensions/AnimationExtensions.cs @@ -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); diff --git a/PckStudio.Core/Extensions/EnumerableExtensions.cs b/PckStudio.Core/Extensions/EnumerableExtensions.cs index 18f341b1..0ef582ae 100644 --- a/PckStudio.Core/Extensions/EnumerableExtensions.cs +++ b/PckStudio.Core/Extensions/EnumerableExtensions.cs @@ -7,16 +7,6 @@ namespace PckStudio.Core.Extensions { public static class EnumerableExtensions { - public static IEnumerable<(int index, T value)>Enumerate(this IEnumerable array) - { - int i = 0; - foreach (T item in array) - { - yield return (i++, item); - } - yield break; - } - public static ImageList ToImageList(this IEnumerable images) { ImageList imageList = new ImageList diff --git a/PckStudio.Core/Extensions/ImageExtensions.cs b/PckStudio.Core/Extensions/ImageExtensions.cs index 524331cc..4109fdf7 100644 --- a/PckStudio.Core/Extensions/ImageExtensions.cs +++ b/PckStudio.Core/Extensions/ImageExtensions.cs @@ -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)); } } diff --git a/PckStudio.Core/Resources/atlas/particleData.json b/PckStudio.Core/Resources/atlas/particleData.json index c5549007..5dafc12a 100644 --- a/PckStudio.Core/Resources/atlas/particleData.json +++ b/PckStudio.Core/Resources/atlas/particleData.json @@ -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": "" }, {