1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Fully parse control points.

This commit is contained in:
smoogipooo 2017-04-04 13:11:04 +09:00
parent a742664675
commit 4b424263ce
6 changed files with 61 additions and 21 deletions

View File

@ -55,7 +55,6 @@ namespace osu.Game.Tests.Beatmaps.Formats
var beatmapInfo = decoder.Decode(new StreamReader(stream)).BeatmapInfo;
Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
Assert.AreEqual(false, beatmapInfo.Countdown);
Assert.AreEqual(SampleSet.Soft, beatmapInfo.SampleSet);
Assert.AreEqual(0.7f, beatmapInfo.StackLeniency);
Assert.AreEqual(false, beatmapInfo.SpecialStyle);
Assert.AreEqual(PlayMode.Osu, beatmapInfo.Mode);

View File

@ -31,6 +31,10 @@ namespace osu.Game.Beatmaps.Formats
// TODO: Not sure how far back to go, or differences between versions
}
private SampleSet defaultSampleSet;
private int defaultSampleVolume;
private bool samplesMatchPlaybackRate;
private readonly int beatmapVersion;
public OsuLegacyDecoder()
@ -73,7 +77,13 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.Countdown = int.Parse(val) == 1;
break;
case @"SampleSet":
beatmap.BeatmapInfo.SampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val);
defaultSampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val);
break;
case @"SampleVolume":
defaultSampleVolume = int.Parse(val);
break;
case "SamplesMatchPlaybackRate":
samplesMatchPlaybackRate = val[0] == '1';
break;
case @"StackLeniency":
beatmap.BeatmapInfo.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo);
@ -203,28 +213,56 @@ namespace osu.Game.Beatmaps.Formats
private void handleTimingPoints(Beatmap beatmap, string val)
{
ControlPoint cp = null;
string[] split = val.Split(',');
if (split.Length > 2)
double time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo);
double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);
TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
if (split.Length >= 3)
timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]);
SampleSet sampleSet = defaultSampleSet;
if (split.Length >= 4)
sampleSet = (SampleSet)int.Parse(split[3]);
SampleBank sampleBank = SampleBank.Default;
if (split.Length >= 5)
sampleBank = (SampleBank)int.Parse(split[4]);
int sampleVolume = defaultSampleVolume;
if (split.Length >= 6)
sampleVolume = int.Parse(split[5]);
bool timingChange = true;
if (split.Length >= 7)
timingChange = split[6][0] == '1';
bool kiaiMode = false;
bool omitFirstBarSignature = false;
if (split.Length >= 8)
{
int effectFlags = split.Length > 7 ? Convert.ToInt32(split[7], NumberFormatInfo.InvariantInfo) : 0;
double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);
cp = new ControlPoint
{
Time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo),
BeatLength = beatLength > 0 ? beatLength : 0,
VelocityAdjustment = beatLength < 0 ? -beatLength / 100.0 : 1,
TimingChange = split.Length <= 6 || split[6][0] == '1',
KiaiMode = (effectFlags & 1) > 0,
OmitFirstBarLine = (effectFlags & 8) > 0,
TimeSignature = (TimeSignatures)int.Parse(split[2])
};
int effectFlags = int.Parse(split[7]);
kiaiMode = (effectFlags & 1) > 0;
omitFirstBarSignature = (effectFlags & 8) > 0;
}
if (cp != null)
beatmap.TimingInfo.ControlPoints.Add(cp);
beatmap.TimingInfo.ControlPoints.Add(new ControlPoint
{
Time = time,
BeatLength = beatLength,
VelocityAdjustment = beatLength < 0 ? -beatLength / 100.0 : 1,
TimingChange = timingChange,
TimeSignature = timeSignature,
Sample = new SampleInfo
{
Bank = sampleBank,
Set = sampleSet,
Volume = sampleVolume
},
KiaiMode = kiaiMode,
OmitFirstBarLine = omitFirstBarSignature
});
}
private void handleColours(Beatmap beatmap, string key, string val, ref bool hasCustomColours)

View File

@ -5,6 +5,6 @@ namespace osu.Game.Beatmaps.Samples
{
public class HitSampleInfo : SampleInfo
{
public SampleType Type { get; set; }
public SampleType Type;
}
}

View File

@ -7,5 +7,6 @@ namespace osu.Game.Beatmaps.Samples
{
public SampleBank Bank;
public SampleSet Set;
public int Volume;
}
}

View File

@ -1,6 +1,8 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps.Samples;
namespace osu.Game.Beatmaps.Timing
{
public class ControlPoint
@ -11,6 +13,7 @@ namespace osu.Game.Beatmaps.Timing
TimingChange = true,
};
public SampleInfo Sample;
public TimeSignatures TimeSignature;
public double Time;
public double BeatLength;

View File

@ -46,7 +46,6 @@ namespace osu.Game.Database
// General
public int AudioLeadIn { get; set; }
public bool Countdown { get; set; }
public SampleSet SampleSet { get; set; }
public float StackLeniency { get; set; }
public bool SpecialStyle { get; set; }
public PlayMode Mode { get; set; }