Skip to content

Commit

Permalink
Develop (#103)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
AristurtleDev and vocero authored Mar 13, 2024
1 parent 9a8eac9 commit 7469b3b
Show file tree
Hide file tree
Showing 31 changed files with 2,127 additions and 1,959 deletions.
4 changes: 2 additions & 2 deletions .build/Build.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions .github/release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@
## 5.1.2
- Resolves issue where AsepriteFile.TryGetSlice always returned false even when slice exists

## 5.1.3-beta-1
- Added `MonoGame.Aseprite.Configuration`
- When set to `false` this will assume frame index gets from the `AsepriteFile` start at index 1 and not 0.

## 5.1.3-beta-2
- Removed `MonoGame.Aserpite.Configuration`
- Moved `ZeroIndexedFrames` to be property of `AsepriteFile`
- Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality

## 5.1.3-beta-3
- Added proper support for new tile rotation introduced in Aseprite 1.3

## 5.1.3
- Added `MonoGame.Aseprite.Configuration`
- When set to `false` this will assume frame index gets from the `AsepriteFile` start at index 1 and not 0.
- Removed `MonoGame.Aserpite.Configuration`
- Moved `ZeroIndexedFrames` to be property of `AsepriteFile`
- Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality
- Added proper support for new tile rotation introduced in Aseprite 1.3
- Read Old Palette Chunk for Indexed mode due to Aseprite 1.3.5 file spec change

2 changes: 1 addition & 1 deletion .nuget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A Cross Platform C# Library That Adds Support For Aseprite Files in MonoGame Projects.

[![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)
[![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)
[![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)
[![License: MIT](https://img.shields.io/badge/📃%20license-MIT-blue?style=flat)](LICENSE)
[![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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
A Cross Platform C# Library That Adds Support For Aseprite Files in MonoGame Projects.

[![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)
[![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)
[![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)
[![License: MIT](https://img.shields.io/badge/📃%20license-MIT-blue?style=flat)](LICENSE)
[![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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>5.1.2</Version>
<Version>5.1.3</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -38,9 +38,14 @@
MonoGame;Aseprite;import;processes;read;write;sprite;animation;tileset;tilemap;spritesheet;pipeline;mgcb
</PackageTags>
<PackageReleaseNotes>
Version 5.1.2
The following changes were implemented:
- Resolves issue where AsepriteFile.TryGetSlice always returned false even when slice exists
Version 5.1.3
- Added `MonoGame.Aseprite.Configuration`
- When set to `false` this will assume frame index gets from the `AsepriteFile` start at index 1 and not 0.
- Removed `MonoGame.Aserpite.Configuration`
- Moved `ZeroIndexedFrames` to be property of `AsepriteFile`
- Added unit testing for `AsepriteFile.ZeroIndexedFrames` functionality
- Added proper support for new tile rotation introduced in Aseprite 1.3
- Read Old Palette Chunk for Indexed mode due to Aseprite 1.3.5 file spec change
</PackageReleaseNotes>
<Description>
MonoGame.Aseprite.Content.Pipeline is a cross-platform C# library that adds an extension to the MonoGame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace MonoGame.Aseprite.Content.Pipeline.Processors;
[ContentProcessor(DisplayName = "Aseprite Sprite Processor - MonoGame.Aseprite")]
internal sealed class SpriteContentProcessor : ContentProcessor<AsepriteFileImportResult, SpriteContent>
{
[DisplayName("Zero Indexed Frames")]
public bool ZeroIndexedFrames {get; set;} = true;

[DisplayName("Frame Index")]
public int FrameIndex { get; set; } = 0;

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

public override SpriteContent Process(AsepriteFileImportResult content, ContentProcessorContext context)
{
FrameIndex = ZeroIndexedFrames ? FrameIndex : FrameIndex - 1;

if (FrameIndex < 0 || FrameIndex >= content.AsepriteFile.FrameCount)
{
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));
ProcessorParameterException ex;
if(ZeroIndexedFrames)
{
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));
}
else
{
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));
}

throw ex;
}

AsepriteFrame aseFrame = content.AsepriteFile.Frames[FrameIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace MonoGame.Aseprite.Content.Pipeline.Processors;
[ContentProcessor(DisplayName = "Aseprite Tilemap Processor - MonoGame.Aseprite")]
internal sealed class TilemapContentProcessor : ContentProcessor<AsepriteFileImportResult, TilemapContent>
{
[DisplayName("Zero Indexed Frames")]
public bool ZeroIndexedFrames { get; set; } = true;

[DisplayName("Frame Index")]
public int FrameIndex { get; set; } = 0;

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

public override TilemapContent Process(AsepriteFileImportResult content, ContentProcessorContext context)
{
content.AsepriteFile.ZeroIndexedFrames = ZeroIndexedFrames;
RawTilemap rawTilemap = TilemapProcessor.ProcessRaw(content.AsepriteFile, FrameIndex, OnlyVisibleLayer);
Texture2DContent[] texture2DContents = ProcessTilesetTexture(rawTilemap.RawTilesets);
return new(rawTilemap, texture2DContents);
Expand Down
35 changes: 30 additions & 5 deletions source/MonoGame.Aseprite.Shared/AsepriteFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ public sealed class AsepriteFile
private AsepriteSlice[] _slices;
private AsepriteTileset[] _tilesets;

/// <summary>
/// <see langword="true"/> if, when referencing frames by index, the first frame is index 0; otherwise
/// <see langword="false"/> if the first frame is index 1.
/// </summary>
public bool ZeroIndexedFrames = true;

/// <summary>
/// Gets a read-only span of all <see cref="AsepriteFrame"/> elements in this <see cref="AsepriteFile"/>.
/// </summary>
/// <remarks>
/// The ordering of elements is not affected by <see cref="MonoGame.Aseprite.Configuration.ZeroIndexedFrames"/>.
/// </remarks>
public ReadOnlySpan<AsepriteFrame> Frames => _frames;

/// <summary>
Expand Down Expand Up @@ -142,6 +151,10 @@ internal AsepriteFile(string name, int width, int height, Color[] palette, Asepr
/// <param name="frameIndex">
/// The index of the <see cref="AsepriteFrame"/> to locate.
/// </param>
/// <remarks>
/// You can specify non-zero indexed frames using
/// <see cref="MonoGame.Aseprite.Configuration.ZeroIndexedFrames"/>
/// </remarks>
/// <returns>
/// The <see cref="AsepriteFrame"/> located.
/// </returns>
Expand All @@ -151,14 +164,25 @@ internal AsepriteFile(string name, int width, int height, Color[] palette, Asepr
/// </exception>
public AsepriteFrame GetFrame(int frameIndex)
{
if (frameIndex < 0 || frameIndex >= _frames.Length)
int index = ZeroIndexedFrames ? frameIndex : frameIndex - 1;

if (index < 0 || index >= _frames.Length)
{
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.");
ArgumentOutOfRangeException ex;
if (ZeroIndexedFrames)
{
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.");
}
else
{
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'.");
}
ex.Data.Add("TotalFrames", _frames.Length);
ex.Data.Add("ZeroIndexed", ZeroIndexedFrames);
throw ex;
}

return _frames[frameIndex];
return _frames[index];
}

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

if (frameIndex < 0 || frameIndex >= _frames.Length)
if (index < 0 || index >= _frames.Length)
{
return false;
}

located = _frames[frameIndex];
located = _frames[index];
return located is not null;
}

Expand Down
Loading

0 comments on commit 7469b3b

Please sign in to comment.