mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 22:26:41 +09:00
Initial support code for beatmap loading
This commit is contained in:
25
osu.Game/Beatmaps/Formats/BeatmapDecoder.cs
Normal file
25
osu.Game/Beatmaps/Formats/BeatmapDecoder.cs
Normal file
@ -0,0 +1,25 @@
|
||||
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; set; } = 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);
|
||||
}
|
Reference in New Issue
Block a user