mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-21 01:39:32 +00:00
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:
committed by
GitHub
parent
fee16bbd91
commit
fd8eead241
+3
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user