1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

xml reader

This commit is contained in:
Ellpeck 2020-04-22 00:47:09 +02:00
parent 99d286d834
commit 9c7f4fcfed
4 changed files with 25 additions and 3 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -1,3 +1,4 @@
using System;
using System.IO;
using Microsoft.Xna.Framework.Audio;

21
MLEM/Content/XmlReader.cs Normal file
View file

@ -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"};
}
}
}