Skip to content

Commit 52aa5a6

Browse files
committed
Use correct data type for slice key properties
1 parent 2cd9414 commit 52aa5a6

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

source/AsepriteDotNet/Aseprite/Document/AsepriteSliceKeyProperties.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ namespace AsepriteDotNet.Aseprite.Document;
1010
internal struct AsepriteSliceKeyProperties
1111
{
1212
internal const int StructSize = sizeof(uint) + // FrameNumber
13-
sizeof(long) + // X
14-
sizeof(long) + // Y
13+
sizeof(int) + // X
14+
sizeof(int) + // Y
1515
sizeof(uint) + // Width
1616
sizeof(uint); // Height
1717

1818
[FieldOffset(0)]
1919
internal uint FrameNumber;
2020

2121
[FieldOffset(4)]
22-
internal long X;
22+
internal int X;
2323

24-
[FieldOffset(12)]
25-
internal long Y;
24+
[FieldOffset(8)]
25+
internal int Y;
2626

27-
[FieldOffset(20)]
27+
[FieldOffset(12)]
2828
internal uint Width;
2929

30-
[FieldOffset(24)]
30+
[FieldOffset(16)]
3131
internal uint Height;
3232
}

tests/AsepriteDotNet.Tests/AsepriteDotNet.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<None Update="Files\rgba-pixel-test.aseprite">
2323
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2424
</None>
25+
<None Update="Files\slice-test.aseprite">
26+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27+
</None>
2528
<None Update="Files\sprite-userdata-test.aseprite">
2629
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2730
</None>
634 Bytes
Binary file not shown.

tests/AsepriteDotNet.Tests/IO/AsepriteFileLoaderTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file in the project root for full license information.
44

55
using AsepriteDotNet.Aseprite;
6+
using AsepriteDotNet.Aseprite.Document;
67
using AsepriteDotNet.Aseprite.Types;
78
using AsepriteDotNet.Common;
89
using AsepriteDotNet.IO;
@@ -415,6 +416,33 @@ public void AsepriteFileReader_ReadTagsTest()
415416
Assert.Equal(new Rgba32(11, 255, 230, 255), tags[2].UserData.Color);
416417
Assert.Equal("tag-4-user-data", tags[2].UserData.Text);
417418

419+
}
420+
421+
// There was an issue where slice data was read incorrectly. This test was put in place to ensure that
422+
// doesn't happen again....
423+
[Fact]
424+
public void AsepriteFileReader_SliceTest()
425+
{
426+
AsepriteSliceKeyProperties sliceKeyProperties = new AsepriteSliceKeyProperties()
427+
{
428+
FrameNumber = 0,
429+
X = 2,
430+
Y = 2,
431+
Width = 28,
432+
Height = 27
433+
};
434+
435+
AsepriteSliceKey expected = new AsepriteSliceKey(sliceKeyProperties, null, null);
436+
437+
string path = GetPath("slice-test.aseprite");
438+
AsepriteFile aseFile = AsepriteFileLoader.FromFile(path);
439+
440+
AsepriteSliceKey actual = aseFile.Slices[0].Keys[0];
441+
442+
Assert.Equal(expected.Bounds.X, actual.Bounds.X);
443+
Assert.Equal(expected.Bounds.Y, actual.Bounds.Y);
444+
Assert.Equal(expected.Bounds.Width, actual.Bounds.Width);
445+
Assert.Equal(expected.Bounds.Height, actual.Bounds.Height);
418446
}
419447
}
420448
}

0 commit comments

Comments
 (0)