diff options
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json')
4 files changed, 81 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentImporter.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentImporter.cs new file mode 100644 index 0000000..437d7eb --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentImporter.cs @@ -0,0 +1,15 @@ +using System.IO; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace MonoGame.Extended.Content.Pipeline.Json +{ + [ContentImporter(".json", DefaultProcessor = nameof(JsonContentProcessor), DisplayName = "JSON Importer - MonoGame.Extended")] + public class JsonContentImporter : ContentImporter<ContentImporterResult<string>> + { + public override ContentImporterResult<string> Import(string filename, ContentImporterContext context) + { + var json = File.ReadAllText(filename); + return new ContentImporterResult<string>(filename, json); + } + } +} diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessor.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessor.cs new file mode 100644 index 0000000..6be4ac3 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessor.cs @@ -0,0 +1,31 @@ +using System; +using System.ComponentModel; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace MonoGame.Extended.Content.Pipeline.Json +{ + [ContentProcessor(DisplayName = "JSON Processor - MonoGame.Extended")] + public class JsonContentProcessor : ContentProcessor<ContentImporterResult<string>, JsonContentProcessorResult> + { + [DefaultValue(typeof(Type), "System.Object")] + public string ContentType { get; set; } + + public override JsonContentProcessorResult Process(ContentImporterResult<string> input, ContentProcessorContext context) + { + try + { + var output = new JsonContentProcessorResult + { + ContentType = ContentType, + Json = input.Data + }; + return output; + } + catch (Exception ex) + { + context.Logger.LogMessage("Error {0}", ex); + throw; + } + } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessorResult.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessorResult.cs new file mode 100644 index 0000000..eaef99e --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentProcessorResult.cs @@ -0,0 +1,8 @@ +namespace MonoGame.Extended.Content.Pipeline.Json +{ + public class JsonContentProcessorResult + { + public string ContentType { get; set; } + public string Json { get; set; } + } +}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentTypeWriter.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentTypeWriter.cs new file mode 100644 index 0000000..6efa696 --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Json/JsonContentTypeWriter.cs @@ -0,0 +1,27 @@ +using Microsoft.Xna.Framework.Content.Pipeline; +using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; + +namespace MonoGame.Extended.Content.Pipeline.Json +{ + [ContentTypeWriter] + public class JsonContentTypeWriter : ContentTypeWriter<JsonContentProcessorResult> + { + private string _runtimeType; + + protected override void Write(ContentWriter writer, JsonContentProcessorResult result) + { + _runtimeType = result.ContentType; + writer.Write(result.Json); + } + + public override string GetRuntimeReader(TargetPlatform targetPlatform) + { + return _runtimeType;// "MonoGame.Extended.Serialization.SpriteFactoryContentTypeReader, MonoGame.Extended"; + } + + public override string GetRuntimeType(TargetPlatform targetPlatform) + { + return _runtimeType;// "MonoGame.Extended.Serialization.SpriteFactoryContentTypeReader, MonoGame.Extended"; + } + } +}
\ No newline at end of file |