Skip to content

Commit fd8eead

Browse files
Fix/textureatlas import error (#1017)
* Ensure that location of PNG is resolved relative to the JSON file directory in TexturePacker processor * Bump version to 5.0.2 * Update tests
1 parent fee16bb commit fd8eead

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<PropertyGroup>
10-
<Version>5.0.1</Version>
10+
<Version>5.0.2</Version>
1111
</PropertyGroup>
1212

1313
<PropertyGroup>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MonoGame.Extended is a set of utilities (in the form of libraries/tools) to [Mon
1111
Code is distributed as NuGet packages in the form of libraries (`.dll` files). You can easily install the NuGet packages into your existing MonoGame project using the NuGet Package Manager UI in Visual Studio or by using the command line interface (CLI) in a terminal.
1212

1313
```sh
14-
dotnet add package MonoGame.Extended --version 5.0.1
14+
dotnet add package MonoGame.Extended --version 5.0.2
1515
```
1616

1717
### Using the Content Pipeline Extensions

source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerJsonImporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace MonoGame.Extended.Content.Pipeline.TextureAtlases
99
{
1010
[ContentImporter(".json", DefaultProcessor = "TexturePackerProcessor", DisplayName = "TexturePacker JSON Importer - MonoGame.Extended")]
11-
public class TexturePackerJsonImporter : ContentImporter<TexturePackerFileContent>
11+
public class TexturePackerJsonImporter : ContentImporter<ContentImporterResult<TexturePackerFileContent>>
1212
{
13-
public override TexturePackerFileContent Import(string filename, ContentImporterContext context)
13+
public override ContentImporterResult<TexturePackerFileContent> Import(string filename, ContentImporterContext context)
1414
{
1515
var tpFile = TexturePackerFileReader.Read(filename);
1616

@@ -27,7 +27,7 @@ public override TexturePackerFileContent Import(string filename, ContentImporter
2727
}
2828
}
2929

30-
return tpFile;
30+
return new ContentImporterResult<TexturePackerFileContent>(filename, tpFile);
3131
}
3232
}
3333
}

source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerProcessor.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33
// See LICENSE file in the project root for full license information.
44

5+
using System.IO;
56
using Microsoft.Xna.Framework.Content.Pipeline;
67
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
78
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
@@ -10,25 +11,26 @@
1011
namespace MonoGame.Extended.Content.Pipeline.TextureAtlases;
1112

1213
[ContentProcessor(DisplayName = "TexturePacker Processor - MonoGame.Extended")]
13-
public class TexturePackerProcessor : ContentProcessor<TexturePackerFileContent, TexturePackerProcessorResult>
14+
public class TexturePackerProcessor : ContentProcessor<ContentImporterResult<TexturePackerFileContent>, TexturePackerProcessorResult>
1415
{
15-
public override TexturePackerProcessorResult Process(TexturePackerFileContent input, ContentProcessorContext context)
16+
public override TexturePackerProcessorResult Process(ContentImporterResult<TexturePackerFileContent> input, ContentProcessorContext context)
1617
{
17-
if (input.Meta.Image != null)
18+
if (input.Data.Meta.Image != null)
1819
{
1920
// Validates the texture exists and can be processed (fails build if missing)
20-
var externalRef = new ExternalReference<Texture2DContent>(input.Meta.Image);
21+
var externalRef = new ExternalReference<Texture2DContent>(input.Data.Meta.Image);
2122
context.BuildAndLoadAsset<Texture2DContent, Texture2DContent>(externalRef, nameof(TextureProcessor));
2223

2324
}
24-
else if (input.Meta.DataFormat == "monogame-extended")
25+
else if (input.Data.Meta.DataFormat == "monogame-extended")
2526
{
26-
foreach (var texture in input.Textures)
27+
foreach (var texture in input.Data.Textures)
2728
{
28-
var externalRef = new ExternalReference<Texture2DContent>(texture.FileName);
29+
string texturePath = Path.Combine(Path.GetDirectoryName(input.FilePath), texture.FileName);
30+
var externalRef = new ExternalReference<Texture2DContent>(texturePath);
2931
context.BuildAndLoadAsset<Texture2DContent, Texture2DContent>(externalRef, nameof(TextureProcessor));
3032
}
3133
}
32-
return new TexturePackerProcessorResult(input);
34+
return new TexturePackerProcessorResult(input.Data);
3335
}
3436
}

tests/MonoGame.Extended.Content.Pipeline.Tests/TexturePackerJsonImporterProcessorTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ public void TexturePackerJsonImporter_Import_Test()
1212
{
1313
var filePath = PathExtensions.GetApplicationFullPath(@"TestData/test-tileset.json");
1414
var importer = new TexturePackerJsonImporter();
15-
var data = importer.Import(filePath, Substitute.For<ContentImporterContext>());
15+
var importResult = importer.Import(filePath, Substitute.For<ContentImporterContext>());
1616

17-
Assert.NotNull(data);
17+
Assert.NotNull(importResult);
1818

1919
// Check meta.image contains image name
20-
Assert.Equal("test-tileset.png", data.Meta.Image);
20+
Assert.Equal("test-tileset.png", importResult.Data.Meta.Image);
2121

2222
// Check regions count and textures
23-
Assert.Equal(9, data.Regions.Count);
24-
Assert.Null(data.Textures); // only used by new MonoGame.Extended JSON format
23+
Assert.Equal(9, importResult.Data.Regions.Count);
24+
Assert.Null(importResult.Data.Textures); // only used by new MonoGame.Extended JSON format
2525

2626
// Check first region
27-
var firstRegion = data.Regions[0];
27+
var firstRegion = importResult.Data.Regions[0];
2828
Assert.Equal("1.png", firstRegion.FileName);
2929
Assert.Equal(2, firstRegion.Frame.X);
3030
Assert.Equal(2, firstRegion.Frame.Y);
@@ -54,16 +54,16 @@ public void TexturePackerJsonImporter_Import_NewFormat_Test()
5454
{
5555
var filePath = PathExtensions.GetApplicationFullPath(@"TestData/test-atlas.json");
5656
var importer = new TexturePackerJsonImporter();
57-
var data = importer.Import(filePath, Substitute.For<ContentImporterContext>());
57+
var importResult = importer.Import(filePath, Substitute.For<ContentImporterContext>());
5858

5959
// Regions must be null (only used by old generic json format)
60-
Assert.Null(data.Regions);
60+
Assert.Null(importResult.Data.Regions);
6161

6262
// Textures contains 1 texture
63-
Assert.NotNull(data.Textures);
64-
Assert.Single(data.Textures);
63+
Assert.NotNull(importResult.Data.Textures);
64+
Assert.Single(importResult.Data.Textures);
6565

66-
var texture = data.Textures[0];
66+
var texture = importResult.Data.Textures[0];
6767
Assert.Equal("test-atlas-texture.png", texture.FileName);
6868

6969
// The first texture contains frames

0 commit comments

Comments
 (0)