Skip to content

Commit 87df2bb

Browse files
Allow specification of layers when flattening frame (#35)
* Update to use TileSize property Size property is marked obsolete * Add method to specify layers to process * Cleanup build warnings * Bump version number
1 parent 155ea70 commit 87df2bb

30 files changed

+1160
-705
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<NeutralLanguage>en</NeutralLanguage>
2121
<ImplicitUsings>enable</ImplicitUsings>
2222
<Nullable>enable</Nullable>
23-
<Version>1.8.3</Version>
23+
<Version>1.9.0</Version>
2424
</PropertyGroup>
2525

2626
<!-- Setup Code Analysis using the .editorconfig file -->

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
A Cross Platform C# Library for Reading Aseprite Files
55

66
[![main](https://github.com/AristurtleDev/AsepriteDotNet/actions/workflows/main.yml/badge.svg)](https://github.com/AristurtleDev/AsepriteDotNet/actions/workflows/main.yml)
7-
[![Nuget 1.8.3](https://img.shields.io/nuget/v/AsepriteDotNet?color=blue&style=flat-square)](https://www.nuget.org/packages/AsepriteDotNet/1.8.3)
7+
[![Nuget 1.9.0](https://img.shields.io/nuget/v/AsepriteDotNet?color=blue&style=flat-square)](https://www.nuget.org/packages/AsepriteDotNet/1.9.0)
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=AsepriteDotNet%20by%20%40aristurtledev%0A%0AA%20new%20cross-platform%20library%20in%20C%23%20for%20reading%20Aseprite%20.ase%2F.aseprite%20files.%20https%3A%2F%2Fgithub.com%2FAristurtleDev%2FAsepriteDotNet%0A%0A%23aseprite%20%23dotnet%20%23csharp%20%23oss%0A)
1010
</h1>
@@ -27,7 +27,7 @@ A Cross Platform C# Library for Reading Aseprite Files
2727
# Installation
2828
Install via NuGet
2929
```
30-
dotnet add package AsepriteDotNet --version 1.8.3
30+
dotnet add package AsepriteDotNet --version 1.9.0
3131
```
3232

3333
# Usage

examples/ProcessorExample/Program.cs

+68-48
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,70 @@
1-
// Copyright (c) Christopher Whitley. All rights reserved.
2-
// Licensed under the MIT license.
1+
// Copyright (c) Christopher Whitley. All rights reserved.
2+
// Licensed under the MIT license.
33
// See LICENSE file in the project root for full license information.
44

5-
using AsepriteDotNet;
6-
using AsepriteDotNet.Aseprite;
7-
using AsepriteDotNet.IO;
8-
using AsepriteDotNet.Processors;
9-
10-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11-
///
12-
/// Load the file using the AsepriteFileLoader. In this example, we are passing the path to the file. There is also
13-
/// an overload where you can pass a stream instead if you needed.
14-
///
15-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16-
AsepriteFile aseFile = AsepriteFileLoader.FromFile("adventurer.aseprite");
17-
18-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19-
///
20-
/// Create the process options to use with the processors. Here we use the default options, however you an customize
21-
/// them. See the README documentation for available properties and what each does for the processor options.
22-
///
23-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24-
ProcessorOptions options = ProcessorOptions.Default;
25-
26-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27-
///
28-
/// The SpriteProcesor is used to process a Sprite from a single frame
29-
///
30-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31-
Sprite sprite = SpriteProcessor.Process(aseFile, 0, options);
32-
33-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34-
///
35-
/// The TextureAtlas processor will process a TextureAtlas from the aseprite file. A TextureAtlas contains single
36-
/// image representation of all frames in the Aseprite file that have been box packed into the pixel data. Additional
37-
/// TextureRegion properties are provided that define the source rectangle for each frame within the base texture
38-
/// representation.
39-
///
40-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41-
TextureAtlas atals = TextureAtlasProcessor.Process(aseFile, options);
42-
43-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44-
///
45-
/// The SpriteSheet processor will process a SpriteSheet from the aseprite file. A SpriteSheet uses a TextureAtlas as
46-
/// its source for the image and provides additional properties that define animations as defined by the tags in
47-
/// Aseprite.
48-
///
49-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50-
SpriteSheet spriteSheet = SpriteSheetProcessor.Process(aseFile, options);
5+
using AsepriteDotNet;
6+
using AsepriteDotNet.Aseprite;
7+
using AsepriteDotNet.IO;
8+
using AsepriteDotNet.Processors;
9+
10+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11+
///
12+
/// Load the file using the AsepriteFileLoader. In this example, we are passing the path to the file. There is also
13+
/// an overload where you can pass a stream instead if you needed.
14+
///
15+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16+
AsepriteFile aseFile = AsepriteFileLoader.FromFile("adventurer.aseprite");
17+
18+
19+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20+
///
21+
/// The SpriteProcessor is used to process a Sprite from a single frame
22+
///
23+
/// The onlyVisibleLayers, includeBackgroundLayer, and includeTilemapLayers parameters are optional. Below shows their
24+
/// default values if not specified.
25+
///
26+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27+
Sprite sprite = SpriteProcessor.Process(aseFile,
28+
0,
29+
onlyVisibleLayers: true,
30+
includeBackgroundLayer: false,
31+
includeTilemapLayers: false);
32+
33+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34+
///
35+
/// The TextureAtlas processor will process a TextureAtlas from the aseprite file. A TextureAtlas contains single
36+
/// image representation of all frames in the Aseprite file that have been box packed into the pixel data. Additional
37+
/// TextureRegion properties are provided that define the source rectangle for each frame within the base texture
38+
/// representation.
39+
///
40+
/// The onlyVisibleLayers, includeBackgroundLayer, includeTileMapLayers, mergeDuplicateFrames, borderPadding, spacing,
41+
/// and innerPadding parameters are optional. Below shows their default values when not specified.
42+
///
43+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44+
TextureAtlas atlas = TextureAtlasProcessor.Process(aseFile,
45+
onlyVisibleLayers: true,
46+
includeBackgroundLayer: false,
47+
includeTilemapLayers: false,
48+
mergeDuplicateFrames: true,
49+
borderPadding: 0,
50+
spacing: 0,
51+
innerPadding: 0);
52+
53+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54+
///
55+
/// The SpriteSheet processor will process a SpriteSheet from the aseprite file. A SpriteSheet uses a TextureAtlas as
56+
/// its source for the image and provides additional properties that define animations as defined by the tags in
57+
/// Aseprite.
58+
///
59+
/// The onlyVisibleLayers, includeBackgroundLayer, includeTileMapLayers, mergeDuplicateFrames, borderPadding, spacing,
60+
/// and innerPadding parameters are optional. Below shows their default values when not specified.
61+
///
62+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63+
SpriteSheet spriteSheet = SpriteSheetProcessor.Process(aseFile,
64+
onlyVisibleLayers: true,
65+
includeBackgroundLayer: false,
66+
includeTilemapLayers: false,
67+
mergeDuplicateFrames: true,
68+
borderPadding: 0,
69+
spacing: 0,
70+
innerPadding: 0);

source/AsepriteDotNet/AnimatedTilemap.cs

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace AsepriteDotNet;
1212
/// </summary>
1313
public sealed class AnimatedTilemap : IEquatable<AnimatedTilemap>
1414
{
15+
/// <summary>
16+
/// An empty animated tilemap with no name, an empty collection of tilesets, and an empty collection of tilemap
17+
/// frames.
18+
/// </summary>
19+
public static readonly AnimatedTilemap Empty = new AnimatedTilemap(string.Empty, Array.Empty<Tileset>(), Array.Empty<TilemapFrame>());
20+
1521
private readonly Tileset[] _tilests;
1622
private readonly TilemapFrame[] _frames;
1723

source/AsepriteDotNet/Aseprite/AsepriteFile.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public bool TryGetFrame(int index, [NotNullWhen(true)] out AsepriteFrame? frame)
152152
/// </summary>
153153
/// <param name="name">The name of <see cref="AsepriteLayer"/>.</param>
154154
/// <returns>The <see cref="AsepriteLayer"/> with the specified name.</returns>
155-
/// <exception cref="ArgumentException">
155+
/// <exception cref="ArgumentNullException">
156156
/// If <paramref name="name"/> is <see langword="null"/> or an empty string.
157157
/// </exception>
158158
/// <exception cref="InvalidOperationException">
@@ -163,10 +163,10 @@ public AsepriteLayer GetLayer(string name)
163163
#if NET6_0
164164
if(string.IsNullOrEmpty(name))
165165
{
166-
throw new ArgumentException(nameof(name));
166+
throw new ArgumentNullException(nameof(name), $"{nameof(name)} cannot be null or an empty string.");
167167
}
168168
#elif NET8_0_OR_GREATER
169-
ArgumentException.ThrowIfNullOrEmpty(name);
169+
ArgumentNullException.ThrowIfNullOrEmpty(name);
170170
#endif
171171

172172
return _layers.AsParallel()
@@ -231,7 +231,7 @@ public bool TryGetLayer(string name, [NotNullWhen(true)] out AsepriteLayer? laye
231231
/// </summary>
232232
/// <param name="name">The name of <see cref="AsepriteTag"/>.</param>
233233
/// <returns>The <see cref="AsepriteTag"/> with the specified name.</returns>
234-
/// <exception cref="ArgumentException">
234+
/// <exception cref="ArgumentNullException">
235235
/// If <paramref name="name"/> is <see langword="null"/> or an empty string.
236236
/// </exception>
237237
/// <exception cref="InvalidOperationException">
@@ -242,10 +242,10 @@ public AsepriteTag GetTag(string name)
242242
#if NET6_0
243243
if(string.IsNullOrEmpty(name))
244244
{
245-
throw new ArgumentException(nameof(name));
245+
throw new ArgumentNullException(nameof(name), $"{nameof(name)} cannot be null or an empty string");
246246
}
247247
#elif NET8_0_OR_GREATER
248-
ArgumentException.ThrowIfNullOrEmpty(name);
248+
ArgumentNullException.ThrowIfNullOrEmpty(name);
249249
#endif
250250

251251
return _tags.AsParallel()
@@ -310,7 +310,7 @@ public bool TryGetTag(string name, [NotNullWhen(true)] out AsepriteTag? tag)
310310
/// </summary>
311311
/// <param name="name">The name of <see cref="AsepriteSlice"/>.</param>
312312
/// <returns>The <see cref="AsepriteSlice"/> with the specified name.</returns>
313-
/// <exception cref="ArgumentException">
313+
/// <exception cref="ArgumentNullException">
314314
/// If <paramref name="name"/> is <see langword="null"/> or an empty string.
315315
/// </exception>
316316
/// <exception cref="InvalidOperationException">
@@ -321,10 +321,10 @@ public AsepriteSlice GetSlice(string name)
321321
#if NET6_0
322322
if(string.IsNullOrEmpty(name))
323323
{
324-
throw new ArgumentException(nameof(name));
324+
throw new ArgumentNullException(nameof(name), $"{nameof(name)} cannot be null or an empty string");
325325
}
326326
#elif NET8_0_OR_GREATER
327-
ArgumentException.ThrowIfNullOrEmpty(name);
327+
ArgumentNullException.ThrowIfNullOrEmpty(name);
328328
#endif
329329

330330
return _slices.AsParallel()
@@ -389,7 +389,7 @@ public bool TryGetSlice(string name, [NotNullWhen(true)] out AsepriteSlice? slic
389389
/// </summary>
390390
/// <param name="name">The name of <see cref="AsepriteTileset"/>.</param>
391391
/// <returns>The <see cref="AsepriteTileset"/> with the specified name.</returns>
392-
/// <exception cref="ArgumentException">
392+
/// <exception cref="ArgumentNullException">
393393
/// If <paramref name="name"/> is <see langword="null"/> or an empty string.
394394
/// </exception>
395395
/// <exception cref="InvalidOperationException">
@@ -400,10 +400,10 @@ public AsepriteTileset GetTileset(string name)
400400
#if NET6_0
401401
if(string.IsNullOrEmpty(name))
402402
{
403-
throw new ArgumentException(nameof(name));
403+
throw new ArgumentNullException(nameof(name), $"{nameof(name)} cannot be null or an empty string");
404404
}
405405
#elif NET8_0_OR_GREATER
406-
ArgumentException.ThrowIfNullOrEmpty(name);
406+
ArgumentNullException.ThrowIfNullOrEmpty(name);
407407
#endif
408408

409409
return _tilesets.AsParallel()

0 commit comments

Comments
 (0)