Add extentions for ContentImporter.

This commit is contained in:
Gandifil
2023-12-21 23:15:05 +03:00
parent cedf863d7e
commit dbdb2eec18
2 changed files with 20 additions and 10 deletions
@@ -0,0 +1,15 @@
using System.IO;
using Microsoft.Xna.Framework.Content.Pipeline;
namespace MonoGame.Extended.Content.Pipeline;
public static class ContentImporterContextExtensions
{
public static string AddDependencyWithLogging(this ContentImporterContext context, string filePath, string source)
{
source = Path.Combine(Path.GetDirectoryName(filePath), source);
ContentLogger.Log($"Adding dependency '{source}'");
context.AddDependency(source);
return source;
}
}
@@ -39,23 +39,18 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
var tilesetSerializer = new XmlSerializer(typeof(TiledMapTilesetContent));
var tileset = (TiledMapTilesetContent)tilesetSerializer.Deserialize(reader);
tileset.Image.Source = Path.Combine(Path.GetDirectoryName(filePath), tileset.Image.Source);
ContentLogger.Log($"Adding dependency '{tileset.Image.Source}'");
context.AddDependency(tileset.Image.Source);
if (tileset.Image is not null)
tileset.Image.Source = context.AddDependencyWithLogging(filePath, tileset.Image.Source);
foreach (var tile in tileset.Tiles)
{
foreach (var obj in tile.Objects)
{
if (!string.IsNullOrWhiteSpace(obj.TemplateSource))
{
obj.TemplateSource = Path.Combine(Path.GetDirectoryName(filePath), obj.TemplateSource);
ContentLogger.Log($"Adding dependency '{obj.TemplateSource}'");
// We depend on the template.
context.AddDependency(obj.TemplateSource);
}
obj.TemplateSource = context.AddDependencyWithLogging(filePath, obj.TemplateSource);
}
if (tile.Image is not null)
tile.Image.Source = context.AddDependencyWithLogging(filePath, tile.Image.Source);
}
return tileset;