From 9c7f4fcfedad8e065a113460993b36631dd69387 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 22 Apr 2020 00:47:09 +0200 Subject: [PATCH] xml reader --- MLEM/Content/RawContentManager.cs | 2 +- MLEM/Content/RawContentReader.cs | 4 ++-- MLEM/Content/SoundEffectReader.cs | 1 + MLEM/Content/XmlReader.cs | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 MLEM/Content/XmlReader.cs diff --git a/MLEM/Content/RawContentManager.cs b/MLEM/Content/RawContentManager.cs index 2255d8d..820779c 100644 --- a/MLEM/Content/RawContentManager.cs +++ b/MLEM/Content/RawContentManager.cs @@ -50,7 +50,7 @@ namespace MLEM.Content { if (!file.Exists) continue; using (var stream = file.OpenRead()) { - var read = reader.Read(this, assetName, stream, existing); + var read = reader.Read(this, assetName, stream, typeof(T), existing); if (!(read is T t)) throw new ContentLoadException($"{reader} returned non-{typeof(T)} for asset {assetName}"); this.LoadedAssets[assetName] = t; diff --git a/MLEM/Content/RawContentReader.cs b/MLEM/Content/RawContentReader.cs index 82e31aa..1aa1d33 100644 --- a/MLEM/Content/RawContentReader.cs +++ b/MLEM/Content/RawContentReader.cs @@ -6,7 +6,7 @@ namespace MLEM.Content { public abstract bool CanRead(Type t); - public abstract object Read(RawContentManager manager, string assetPath, Stream stream, object existing); + public abstract object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing); public abstract string[] GetFileExtensions(); @@ -18,7 +18,7 @@ namespace MLEM.Content { return typeof(T).IsAssignableFrom(t); } - public override object Read(RawContentManager manager, string assetPath, Stream stream, object existing) { + public override object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing) { return this.Read(manager, assetPath, stream, (T) existing); } diff --git a/MLEM/Content/SoundEffectReader.cs b/MLEM/Content/SoundEffectReader.cs index a5ca9d2..26411f6 100644 --- a/MLEM/Content/SoundEffectReader.cs +++ b/MLEM/Content/SoundEffectReader.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using Microsoft.Xna.Framework.Audio; diff --git a/MLEM/Content/XmlReader.cs b/MLEM/Content/XmlReader.cs new file mode 100644 index 0000000..28b6833 --- /dev/null +++ b/MLEM/Content/XmlReader.cs @@ -0,0 +1,21 @@ +using System; +using System.IO; +using System.Xml.Serialization; + +namespace MLEM.Content { + public class XmlReader : RawContentReader { + + public override bool CanRead(Type t) { + return true; + } + + public override object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing) { + return new XmlSerializer(t).Deserialize(stream); + } + + public override string[] GetFileExtensions() { + return new[] {"xml"}; + } + + } +} \ No newline at end of file