mirror of
https://github.com/ppy/osu
synced 2024-12-25 16:22:23 +00:00
27 lines
822 B
C#
27 lines
822 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
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]);
|
|
}
|
|
|
|
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder
|
|
{
|
|
decoders[magic] = typeof(T);
|
|
}
|
|
|
|
public abstract Beatmap Decode(TextReader stream);
|
|
}
|
|
}
|