mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 20:12:23 +00:00
* mostly restored the tiled importer unit tests * code cleanup * code cleanup * almost got tiled maps serialization independent of the content pipeline * refactored the tiled map content importer so that tiled maps can be loaded at runtime * code cleanup * removed nuspec files * experimenting with an XML based GUI markup parser * a few more markup parser features * finally got a working open file dialog * experimenting with markup bindings * attached properties * working on the gui stuff again * working on a better textbox * multiline textboxing * new text box is really coming along * removed the content explorer experiment * restored the old gui demo back to the way it was before (for now)
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using Microsoft.Xna.Framework.Content.Pipeline;
|
|
using System;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using MonoGame.Extended.Tiled.Serialization;
|
|
|
|
namespace MonoGame.Extended.Content.Pipeline.Tiled
|
|
{
|
|
[ContentImporter(".tx", DefaultProcessor = "TiledMapObjectTemplateProcessor", DisplayName = "Tiled Map Object Template Importer - MonoGame.Extended")]
|
|
public class TiledMapObjectTemplateImporter : ContentImporter<TiledMapObjectTemplateContent>
|
|
{
|
|
public override TiledMapObjectTemplateContent Import(string filePath, ContentImporterContext context)
|
|
{
|
|
try
|
|
{
|
|
if (filePath == null)
|
|
throw new ArgumentNullException(nameof(filePath));
|
|
|
|
ContentLogger.Logger = context.Logger;
|
|
ContentLogger.Log($"Importing '{filePath}'");
|
|
|
|
var template = DeserializeTileMapObjectTemplateContent(filePath, context);
|
|
|
|
ContentLogger.Log($"Imported '{filePath}'");
|
|
|
|
return template;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
context.Logger.LogImportantMessage(e.StackTrace);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static TiledMapObjectTemplateContent DeserializeTileMapObjectTemplateContent(string filePath, ContentImporterContext context)
|
|
{
|
|
using (var reader = new StreamReader(filePath))
|
|
{
|
|
var templateSerializer = new XmlSerializer(typeof(TiledMapObjectTemplateContent));
|
|
var template = (TiledMapObjectTemplateContent)templateSerializer.Deserialize(reader);
|
|
|
|
if (!string.IsNullOrWhiteSpace(template.Tileset?.Source))
|
|
{
|
|
template.Tileset.Source = $"{Path.GetDirectoryName(filePath)}/{template.Tileset.Source}";
|
|
ContentLogger.Log($"Adding dependency '{template.Tileset.Source}'");
|
|
// We depend on this tileset.
|
|
context.AddDependency(template.Tileset.Source);
|
|
}
|
|
|
|
return template;
|
|
}
|
|
}
|
|
}
|
|
}
|