TexturePackerJsonImporter.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using Microsoft.Xna.Framework.Content.Pipeline;
  5. using MonoGame.Extended.Content.TexturePacker;
  6. namespace MonoGame.Extended.Content.Pipeline.TextureAtlases
  7. {
  8. [ContentImporter(".json", DefaultProcessor = "TexturePackerProcessor", DisplayName = "TexturePacker JSON Importer - MonoGame.Extended")]
  9. public class TexturePackerJsonImporter : ContentImporter<ContentImporterResult<TexturePackerFileContent>>
  10. {
  11. public override ContentImporterResult<TexturePackerFileContent> Import(string filename, ContentImporterContext context)
  12. {
  13. var tpFile = TexturePackerFileReader.Read(filename);
  14. if (tpFile.Meta.Image != null)
  15. {
  16. context.AddDependency(tpFile.Meta.Image);
  17. }
  18. else if (tpFile.Meta.DataFormat == "monogame-extended")
  19. {
  20. // new format: textures are in the textures array
  21. foreach (var texture in tpFile.Textures)
  22. {
  23. context.AddDependency(texture.FileName);
  24. }
  25. }
  26. return new ContentImporterResult<TexturePackerFileContent>(filename, tpFile);
  27. }
  28. }
  29. }