2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 17:56:20 +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-14 17:03:20 +08:00
|
|
|
|
using osu.Game.Modes.Objects;
|
2016-11-02 17:08:08 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-02-09 22:09:48 +08:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
|
using osu.Game.Database;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 22:09:48 +08:00
|
|
|
|
public virtual void Decode(TextReader stream, Beatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
ParseFile(stream, beatmap);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 17:08:08 +08:00
|
|
|
|
public virtual Beatmap Process(Beatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
ApplyColours(beatmap);
|
|
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 22:09:48 +08:00
|
|
|
|
protected virtual Beatmap ParseFile(TextReader stream)
|
|
|
|
|
{
|
|
|
|
|
var beatmap = new Beatmap
|
|
|
|
|
{
|
|
|
|
|
HitObjects = new List<HitObject>(),
|
|
|
|
|
ControlPoints = new List<ControlPoint>(),
|
|
|
|
|
ComboColors = new List<Color4>(),
|
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
|
{
|
|
|
|
|
Metadata = new BeatmapMetadata(),
|
|
|
|
|
BaseDifficulty = new BaseDifficulty(),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
ParseFile(stream, beatmap);
|
|
|
|
|
return beatmap;
|
|
|
|
|
}
|
|
|
|
|
protected abstract void ParseFile(TextReader stream, Beatmap beatmap);
|
2016-11-02 17:08:08 +08:00
|
|
|
|
|
|
|
|
|
public virtual void ApplyColours(Beatmap b)
|
|
|
|
|
{
|
2017-01-10 06:18:47 +08:00
|
|
|
|
List<Color4> colours = b.ComboColors ?? new List<Color4> {
|
2017-01-13 05:38:27 +08:00
|
|
|
|
new Color4(17, 136, 170, 255),
|
|
|
|
|
new Color4(102, 136, 0, 255),
|
|
|
|
|
new Color4(204, 102, 0, 255),
|
|
|
|
|
new Color4(121, 9, 13, 255),
|
2016-11-02 17:08:08 +08:00
|
|
|
|
};
|
|
|
|
|
|
2016-11-14 21:03:39 +08:00
|
|
|
|
if (colours.Count == 0) return;
|
|
|
|
|
|
2016-11-02 17:38:17 +08:00
|
|
|
|
int i = -1;
|
2016-11-02 17:08:08 +08:00
|
|
|
|
|
|
|
|
|
foreach (HitObject h in b.HitObjects)
|
|
|
|
|
{
|
2016-11-09 07:46:08 +08:00
|
|
|
|
if (h.NewCombo || i == -1) i = (i + 1) % colours.Count;
|
2016-11-02 17:38:17 +08:00
|
|
|
|
h.Colour = colours[i];
|
2016-11-02 17:08:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
2017-02-07 12:52:19 +08:00
|
|
|
|
}
|