// Copyright (c) Craftwork Games. All rights reserved. // 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; using MonoGame.Extended.Content.TexturePacker; namespace MonoGame.Extended.Content.Pipeline.TextureAtlases; [ContentProcessor(DisplayName = "TexturePacker Processor - MonoGame.Extended")] public class TexturePackerProcessor : ContentProcessor, TexturePackerProcessorResult> { public override TexturePackerProcessorResult Process(ContentImporterResult input, ContentProcessorContext context) { if (input.Data.Meta.Image != null) { // Validates the texture exists and can be processed (fails build if missing) var externalRef = new ExternalReference(input.Data.Meta.Image); context.BuildAndLoadAsset(externalRef, nameof(TextureProcessor)); } else if (input.Data.Meta.DataFormat == "monogame-extended") { foreach (var texture in input.Data.Textures) { string texturePath = Path.Combine(Path.GetDirectoryName(input.FilePath), texture.FileName); var externalRef = new ExternalReference(texturePath); context.BuildAndLoadAsset(externalRef, nameof(TextureProcessor)); } } return new TexturePackerProcessorResult(input.Data); } }