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
This commit is contained in:
Christopher Whitley
2025-08-24 03:20:29 -04:00
committed by GitHub
parent fee16bbd91
commit fd8eead241
5 changed files with 26 additions and 24 deletions
@@ -8,9 +8,9 @@ using MonoGame.Extended.Content.TexturePacker;
namespace MonoGame.Extended.Content.Pipeline.TextureAtlases
{
[ContentImporter(".json", DefaultProcessor = "TexturePackerProcessor", DisplayName = "TexturePacker JSON Importer - MonoGame.Extended")]
public class TexturePackerJsonImporter : ContentImporter<TexturePackerFileContent>
public class TexturePackerJsonImporter : ContentImporter<ContentImporterResult<TexturePackerFileContent>>
{
public override TexturePackerFileContent Import(string filename, ContentImporterContext context)
public override ContentImporterResult<TexturePackerFileContent> Import(string filename, ContentImporterContext context)
{
var tpFile = TexturePackerFileReader.Read(filename);
@@ -27,7 +27,7 @@ namespace MonoGame.Extended.Content.Pipeline.TextureAtlases
}
}
return tpFile;
return new ContentImporterResult<TexturePackerFileContent>(filename, tpFile);
}
}
}
@@ -2,6 +2,7 @@
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
using System.IO;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
@@ -10,25 +11,26 @@ using MonoGame.Extended.Content.TexturePacker;
namespace MonoGame.Extended.Content.Pipeline.TextureAtlases;
[ContentProcessor(DisplayName = "TexturePacker Processor - MonoGame.Extended")]
public class TexturePackerProcessor : ContentProcessor<TexturePackerFileContent, TexturePackerProcessorResult>
public class TexturePackerProcessor : ContentProcessor<ContentImporterResult<TexturePackerFileContent>, TexturePackerProcessorResult>
{
public override TexturePackerProcessorResult Process(TexturePackerFileContent input, ContentProcessorContext context)
public override TexturePackerProcessorResult Process(ContentImporterResult<TexturePackerFileContent> input, ContentProcessorContext context)
{
if (input.Meta.Image != null)
if (input.Data.Meta.Image != null)
{
// Validates the texture exists and can be processed (fails build if missing)
var externalRef = new ExternalReference<Texture2DContent>(input.Meta.Image);
var externalRef = new ExternalReference<Texture2DContent>(input.Data.Meta.Image);
context.BuildAndLoadAsset<Texture2DContent, Texture2DContent>(externalRef, nameof(TextureProcessor));
}
else if (input.Meta.DataFormat == "monogame-extended")
else if (input.Data.Meta.DataFormat == "monogame-extended")
{
foreach (var texture in input.Textures)
foreach (var texture in input.Data.Textures)
{
var externalRef = new ExternalReference<Texture2DContent>(texture.FileName);
string texturePath = Path.Combine(Path.GetDirectoryName(input.FilePath), texture.FileName);
var externalRef = new ExternalReference<Texture2DContent>(texturePath);
context.BuildAndLoadAsset<Texture2DContent, Texture2DContent>(externalRef, nameof(TextureProcessor));
}
}
return new TexturePackerProcessorResult(input);
return new TexturePackerProcessorResult(input.Data);
}
}