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;
|
2016-11-02 17:08:08 +08:00
|
|
|
|
using osu.Game.Beatmaps.Objects;
|
|
|
|
|
using OpenTK.Graphics;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Formats
|
|
|
|
|
{
|
|
|
|
|
public abstract class BeatmapDecoder
|
|
|
|
|
{
|
|
|
|
|
private static Dictionary<string, Type> decoders { get; } = new Dictionary<string, Type>();
|
2016-11-02 17:08:08 +08:00
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
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-11-02 17:08:08 +08:00
|
|
|
|
|
|
|
|
|
public virtual Beatmap Decode(TextReader stream)
|
|
|
|
|
{
|
|
|
|
|
Beatmap b = ParseFile(stream);
|
|
|
|
|
Process(b);
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual Beatmap Process(Beatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
ApplyColours(beatmap);
|
|
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract Beatmap ParseFile(TextReader stream);
|
|
|
|
|
|
|
|
|
|
public virtual void ApplyColours(Beatmap b)
|
|
|
|
|
{
|
|
|
|
|
List<Color4> colours = b.ComboColors ?? new List<Color4>() {
|
|
|
|
|
new Color4(17, 136, 170, 255),
|
|
|
|
|
new Color4(102,136,0, 255),
|
|
|
|
|
new Color4(204,102,0, 255),
|
|
|
|
|
new Color4(121,9,13, 255),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
foreach (HitObject h in b.HitObjects)
|
|
|
|
|
{
|
|
|
|
|
h.Colour = colours[i];
|
|
|
|
|
if (h.NewCombo) i = (i + 1) % colours.Count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
2016-10-14 01:49:44 +08:00
|
|
|
|
}
|