mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
xml reader
This commit is contained in:
parent
99d286d834
commit
9c7f4fcfed
4 changed files with 25 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
|
||||
|
|
21
MLEM/Content/XmlReader.cs
Normal file
21
MLEM/Content/XmlReader.cs
Normal 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"};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue