Skip to content

Commit 7469b3b

Browse files
Develop (#103)
* Feature/cake frosting (#92) * Added games list Add list of games made with MonoGame.Aseprite * Always specify generate documentation file * Switch to Cake Frosting * Update workflow script * Issue/try get slice 92 (#94) * Added MonoGame.Aseprite to Test .sln This is so intellesense would pickup correct * Added test for issue #92 * Use `_slices` and not `_tags` The `AsepriteSlice.TryGetSlice(string, out AsepriteSlice?)` method incorrectly searched the `_tags` array and not the `_slices` array. This resolves issue #92 * Bump version number * Update release notes * Feature/index one (#98) * Added games list Add list of games made with MonoGame.Aseprite * Develop (#95) * Feature/cake frosting (#92) * Added games list Add list of games made with MonoGame.Aseprite * Always specify generate documentation file * Switch to Cake Frosting * Update workflow script * Issue/try get slice 92 (#94) * Added MonoGame.Aseprite to Test .sln This is so intellesense would pickup correct * Added test for issue #92 * Use `_slices` and not `_tags` The `AsepriteSlice.TryGetSlice(string, out AsepriteSlice?)` method incorrectly searched the `_tags` array and not the `_slices` array. This resolves issue #92 * Bump version number * Update release notes * Fix broken links (Closes #96) * Fix links for NuGet readme * Added ZeroFrameIndex configuration * Removed Global Configuration - Removed `MonoGame.Aserpite.Configuration` - Moved `ZeroIndexedFrames` to be property of `AsepriteFile` - Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality * Fix/tile rotation (#99) * `rotationBitmask` renamed to `dFlipBitmask` * `rotationBitmask` renamed to `dFlipBitmask` * `rotation` renamed to `dFlip` * `Rotation` renamed to `DFlip` * Removed `<remarks>` about flips not being implemented * Update for new tile rotation in Aseprite 1.3 * Cleanup * 5.1.3-beta-3 release candidate * Fix tests * Added Update(TimeSpan) methods to the AnimatedSprite & AnimatedTilemap classes, this removed the requirement to create a fake GameTime every Update when calling the Update(double deltaTime) overload. (#102) * Read Old Palette Chunk per Aseprite 1.3.5 file spec update * Bump Version to 5.1.3 --------- Co-authored-by: Serge Roy <[email protected]>
1 parent 9a8eac9 commit 7469b3b

31 files changed

+2127
-1959
lines changed

.build/Build.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net7.0</TargetFramework>
5-
<Nullable>enable</Nullable>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
66
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
77
</PropertyGroup>
88
<ItemGroup>

.github/release-notes.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,24 @@
5151
## 5.1.2
5252
- Resolves issue where AsepriteFile.TryGetSlice always returned false even when slice exists
5353

54+
## 5.1.3-beta-1
55+
- Added `MonoGame.Aseprite.Configuration`
56+
- When set to `false` this will assume frame index gets from the `AsepriteFile` start at index 1 and not 0.
57+
58+
## 5.1.3-beta-2
59+
- Removed `MonoGame.Aserpite.Configuration`
60+
- Moved `ZeroIndexedFrames` to be property of `AsepriteFile`
61+
- Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality
62+
63+
## 5.1.3-beta-3
64+
- Added proper support for new tile rotation introduced in Aseprite 1.3
65+
66+
## 5.1.3
67+
- Added `MonoGame.Aseprite.Configuration`
68+
- When set to `false` this will assume frame index gets from the `AsepriteFile` start at index 1 and not 0.
69+
- Removed `MonoGame.Aserpite.Configuration`
70+
- Moved `ZeroIndexedFrames` to be property of `AsepriteFile`
71+
- Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality
72+
- Added proper support for new tile rotation introduced in Aseprite 1.3
73+
- Read Old Palette Chunk for Indexed mode due to Aseprite 1.3.5 file spec change
5474

.nuget/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A Cross Platform C# Library That Adds Support For Aseprite Files in MonoGame Projects.
44

55
[![build-and-test](https://github.com/AristurtleDev/monogame-aseprite/actions/workflows/buildandtest.yml/badge.svg)](https://github.com/AristurtleDev/monogame-aseprite/actions/workflows/buildandtest.yml)
6-
[![Nuget 5.1.2](https://img.shields.io/nuget/v/MonoGame.Aseprite?color=blue&style=flat-square)](https://www.nuget.org/packages/MonoGame.Aseprite/5.1.2)
6+
[![Nuget 5.1.3](https://img.shields.io/nuget/v/MonoGame.Aseprite?color=blue&style=flat-square)](https://www.nuget.org/packages/MonoGame.Aseprite/5.1.3)
77
[![License: MIT](https://img.shields.io/badge/📃%20license-MIT-blue?style=flat)](LICENSE)
88
[![Twitter](https://img.shields.io/badge/%20-Share%20On%20Twitter-555?style=flat&logo=twitter)](https://twitter.com/intent/tweet?text=MonoGame.Aseprite%20by%20%40aristurtledev%0A%0AA%20cross-platform%20C%23%20library%20that%20adds%20support%20for%20Aseprite%20files%20in%20MonoGame%20projects.%20https%3A%2F%2Fgithub.com%2FAristurtleDev%2Fmonogame-aseprite%0A%0A%23monogame%20%23aseprite%20%23dotnet%20%23csharp%20%23oss%0A)
99

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
A Cross Platform C# Library That Adds Support For Aseprite Files in MonoGame Projects.
55

66
[![build-and-test](https://github.com/AristurtleDev/monogame-aseprite/actions/workflows/buildandtest.yml/badge.svg)](https://github.com/AristurtleDev/monogame-aseprite/actions/workflows/buildandtest.yml)
7-
[![Nuget 5.1.2](https://img.shields.io/nuget/v/MonoGame.Aseprite?color=blue&style=flat-square)](https://www.nuget.org/packages/MonoGame.Aseprite/5.1.2)
7+
[![Nuget 5.1.3](https://img.shields.io/nuget/v/MonoGame.Aseprite?color=blue&style=flat-square)](https://www.nuget.org/packages/MonoGame.Aseprite/5.1.3)
88
[![License: MIT](https://img.shields.io/badge/📃%20license-MIT-blue?style=flat)](LICENSE)
99
[![Twitter](https://img.shields.io/badge/%20-Share%20On%20Twitter-555?style=flat&logo=twitter)](https://twitter.com/intent/tweet?text=MonoGame.Aseprite%20by%20%40aristurtledev%0A%0AA%20cross-platform%20C%23%20library%20that%20adds%20support%20for%20Aseprite%20files%20in%20MonoGame%20projects.%20https%3A%2F%2Fgithub.com%2FAristurtleDev%2Fmonogame-aseprite%0A%0A%23monogame%20%23aseprite%20%23dotnet%20%23csharp%20%23oss%0A)
1010

source/MonoGame.Aseprite.Content.Pipeline/MonoGame.Aseprite.Content.Pipeline.csproj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<GenerateDocumentationFile>True</GenerateDocumentationFile>
7-
<Version>5.1.2</Version>
7+
<Version>5.1.3</Version>
88
</PropertyGroup>
99

1010
<PropertyGroup>
@@ -38,9 +38,14 @@
3838
MonoGame;Aseprite;import;processes;read;write;sprite;animation;tileset;tilemap;spritesheet;pipeline;mgcb
3939
</PackageTags>
4040
<PackageReleaseNotes>
41-
Version 5.1.2
42-
The following changes were implemented:
43-
- Resolves issue where AsepriteFile.TryGetSlice always returned false even when slice exists
41+
Version 5.1.3
42+
- Added `MonoGame.Aseprite.Configuration`
43+
- When set to `false` this will assume frame index gets from the `AsepriteFile` start at index 1 and not 0.
44+
- Removed `MonoGame.Aserpite.Configuration`
45+
- Moved `ZeroIndexedFrames` to be property of `AsepriteFile`
46+
- Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality
47+
- Added proper support for new tile rotation introduced in Aseprite 1.3
48+
- Read Old Palette Chunk for Indexed mode due to Aseprite 1.3.5 file spec change
4449
</PackageReleaseNotes>
4550
<Description>
4651
MonoGame.Aseprite.Content.Pipeline is a cross-platform C# library that adds an extension to the MonoGame

source/MonoGame.Aseprite.Content.Pipeline/Processors/SpriteContentProcessor.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace MonoGame.Aseprite.Content.Pipeline.Processors;
3434
[ContentProcessor(DisplayName = "Aseprite Sprite Processor - MonoGame.Aseprite")]
3535
internal sealed class SpriteContentProcessor : ContentProcessor<AsepriteFileImportResult, SpriteContent>
3636
{
37+
[DisplayName("Zero Indexed Frames")]
38+
public bool ZeroIndexedFrames {get; set;} = true;
39+
3740
[DisplayName("Frame Index")]
3841
public int FrameIndex { get; set; } = 0;
3942

@@ -51,9 +54,21 @@ internal sealed class SpriteContentProcessor : ContentProcessor<AsepriteFileImpo
5154

5255
public override SpriteContent Process(AsepriteFileImportResult content, ContentProcessorContext context)
5356
{
57+
FrameIndex = ZeroIndexedFrames ? FrameIndex : FrameIndex - 1;
58+
5459
if (FrameIndex < 0 || FrameIndex >= content.AsepriteFile.FrameCount)
5560
{
56-
throw new ProcessorParameterException($"The 'Frame Index' parameter cannot be less than zero or greater than or equal to the total number of frames in the Aseprite file", nameof(SpriteContentProcessor), nameof(FrameIndex));
61+
ProcessorParameterException ex;
62+
if(ZeroIndexedFrames)
63+
{
64+
ex = new ($"The 'Frame Index' parameter cannot be less than zero or greater than or equal to the total number of frames in the Aseprite file", nameof(SpriteContentProcessor), nameof(FrameIndex));
65+
}
66+
else
67+
{
68+
ex = new ($"The 'Frame Index' parameter cannot be less than one or greater than the total number of frames in the Aseprite file when {nameof(ZeroIndexedFrames)} is 'false'.", nameof(SpriteContentProcessor), nameof(FrameIndex));
69+
}
70+
71+
throw ex;
5772
}
5873

5974
AsepriteFrame aseFrame = content.AsepriteFile.Frames[FrameIndex];

source/MonoGame.Aseprite.Content.Pipeline/Processors/TilemapContentProcessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace MonoGame.Aseprite.Content.Pipeline.Processors;
3434
[ContentProcessor(DisplayName = "Aseprite Tilemap Processor - MonoGame.Aseprite")]
3535
internal sealed class TilemapContentProcessor : ContentProcessor<AsepriteFileImportResult, TilemapContent>
3636
{
37+
[DisplayName("Zero Indexed Frames")]
38+
public bool ZeroIndexedFrames { get; set; } = true;
39+
3740
[DisplayName("Frame Index")]
3841
public int FrameIndex { get; set; } = 0;
3942

@@ -45,6 +48,7 @@ internal sealed class TilemapContentProcessor : ContentProcessor<AsepriteFileImp
4548

4649
public override TilemapContent Process(AsepriteFileImportResult content, ContentProcessorContext context)
4750
{
51+
content.AsepriteFile.ZeroIndexedFrames = ZeroIndexedFrames;
4852
RawTilemap rawTilemap = TilemapProcessor.ProcessRaw(content.AsepriteFile, FrameIndex, OnlyVisibleLayer);
4953
Texture2DContent[] texture2DContents = ProcessTilesetTexture(rawTilemap.RawTilesets);
5054
return new(rawTilemap, texture2DContents);

source/MonoGame.Aseprite.Shared/AsepriteFile.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,18 @@ public sealed class AsepriteFile
4141
private AsepriteSlice[] _slices;
4242
private AsepriteTileset[] _tilesets;
4343

44+
/// <summary>
45+
/// <see langword="true"/> if, when referencing frames by index, the first frame is index 0; otherwise
46+
/// <see langword="false"/> if the first frame is index 1.
47+
/// </summary>
48+
public bool ZeroIndexedFrames = true;
49+
4450
/// <summary>
4551
/// Gets a read-only span of all <see cref="AsepriteFrame"/> elements in this <see cref="AsepriteFile"/>.
4652
/// </summary>
53+
/// <remarks>
54+
/// The ordering of elements is not affected by <see cref="MonoGame.Aseprite.Configuration.ZeroIndexedFrames"/>.
55+
/// </remarks>
4756
public ReadOnlySpan<AsepriteFrame> Frames => _frames;
4857

4958
/// <summary>
@@ -142,6 +151,10 @@ internal AsepriteFile(string name, int width, int height, Color[] palette, Asepr
142151
/// <param name="frameIndex">
143152
/// The index of the <see cref="AsepriteFrame"/> to locate.
144153
/// </param>
154+
/// <remarks>
155+
/// You can specify non-zero indexed frames using
156+
/// <see cref="MonoGame.Aseprite.Configuration.ZeroIndexedFrames"/>
157+
/// </remarks>
145158
/// <returns>
146159
/// The <see cref="AsepriteFrame"/> located.
147160
/// </returns>
@@ -151,14 +164,25 @@ internal AsepriteFile(string name, int width, int height, Color[] palette, Asepr
151164
/// </exception>
152165
public AsepriteFrame GetFrame(int frameIndex)
153166
{
154-
if (frameIndex < 0 || frameIndex >= _frames.Length)
167+
int index = ZeroIndexedFrames ? frameIndex : frameIndex - 1;
168+
169+
if (index < 0 || index >= _frames.Length)
155170
{
156-
ArgumentOutOfRangeException ex = new(nameof(frameIndex), $"{nameof(frameIndex)} cannot be less than zero or greater than or equal to the total number of frames in this aseprite file.");
171+
ArgumentOutOfRangeException ex;
172+
if (ZeroIndexedFrames)
173+
{
174+
ex = new(nameof(frameIndex), $"{nameof(frameIndex)} cannot be less than zero or greater than or equal to the total number of frames in this aseprite file.");
175+
}
176+
else
177+
{
178+
ex = new(nameof(frameIndex), $"{nameof(frameIndex)} cannot be less than one or greater than the total number of frames in this aseprite file when '{nameof(ZeroIndexedFrames)}' is 'false'.");
179+
}
157180
ex.Data.Add("TotalFrames", _frames.Length);
181+
ex.Data.Add("ZeroIndexed", ZeroIndexedFrames);
158182
throw ex;
159183
}
160184

161-
return _frames[frameIndex];
185+
return _frames[index];
162186
}
163187

164188
/// <summary>
@@ -179,14 +203,15 @@ public AsepriteFrame GetFrame(int frameIndex)
179203
/// </returns>
180204
public bool TryGetFrame(int frameIndex, [NotNullWhen(true)] out AsepriteFrame? located)
181205
{
206+
int index = ZeroIndexedFrames ? frameIndex : frameIndex - 1;
182207
located = default;
183208

184-
if (frameIndex < 0 || frameIndex >= _frames.Length)
209+
if (index < 0 || index >= _frames.Length)
185210
{
186211
return false;
187212
}
188213

189-
located = _frames[frameIndex];
214+
located = _frames[index];
190215
return located is not null;
191216
}
192217

0 commit comments

Comments
 (0)