mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
Add extentions for ContentImporter.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user