Files
MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerJsonImporter.cs
T
Christopher Whitley fd8eead241 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
2025-08-24 03:20:29 -04:00

34 lines
1.3 KiB
C#

// Copyright (c) Craftwork Games. All rights reserved.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
using Microsoft.Xna.Framework.Content.Pipeline;
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<ContentImporterResult<TexturePackerFileContent>>
{
public override ContentImporterResult<TexturePackerFileContent> Import(string filename, ContentImporterContext context)
{
var tpFile = TexturePackerFileReader.Read(filename);
if (tpFile.Meta.Image != null)
{
context.AddDependency(tpFile.Meta.Image);
}
else if (tpFile.Meta.DataFormat == "monogame-extended")
{
// new format: textures are in the textures array
foreach (var texture in tpFile.Textures)
{
context.AddDependency(texture.FileName);
}
}
return new ContentImporterResult<TexturePackerFileContent>(filename, tpFile);
}
}
}