2016-10-14 11:33:58 +08:00
|
|
|
|
using System;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Formats
|
|
|
|
|
{
|
|
|
|
|
public abstract class BeatmapDecoder
|
|
|
|
|
{
|
|
|
|
|
private static Dictionary<string, Type> decoders { get; } = new Dictionary<string, Type>();
|
|
|
|
|
|
|
|
|
|
public static BeatmapDecoder GetDecoder(TextReader stream)
|
|
|
|
|
{
|
|
|
|
|
var line = stream.ReadLine().Trim();
|
|
|
|
|
if (!decoders.ContainsKey(line))
|
|
|
|
|
throw new IOException(@"Unknown file format");
|
|
|
|
|
return (BeatmapDecoder)Activator.CreateInstance(decoders[line]);
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
2016-10-19 01:35:01 +08:00
|
|
|
|
|
|
|
|
|
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
|
|
|
|
decoders[magic] = typeof(T);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-19 01:35:01 +08:00
|
|
|
|
public abstract Beatmap Decode(TextReader stream);
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
2016-10-14 01:49:44 +08:00
|
|
|
|
}
|