1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 05:43:21 +08:00

Merge branch 'master' into fix-info-wedge

This commit is contained in:
Dean Herbert 2017-12-23 04:04:18 +09:00 committed by GitHub
commit 77f1b59853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 9073 additions and 258 deletions

@ -1 +1 @@
Subproject commit f4fde31f8c09305d2130064da2f7bae995be8286 Subproject commit 08f85f9bf9a7376aec8dfcde8c7c96d267d8c295

View File

@ -37,9 +37,9 @@ namespace osu.Game.Rulesets.Catch.Objects
/// </summary> /// </summary>
public CatchHitObject HyperDashTarget; public CatchHitObject HyperDashTarget;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
Scale = 1.0f - 0.7f * (difficulty.CircleSize - 5) / 5; Scale = 1.0f - 0.7f * (difficulty.CircleSize - 5) / 5;
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using OpenTK; using OpenTK;
@ -25,7 +26,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawable
RelativeChildSize = new Vector2(1, (float)HitObject.Duration) RelativeChildSize = new Vector2(1, (float)HitObject.Duration)
}; };
foreach (CatchHitObject tick in s.Ticks) foreach (CatchHitObject tick in s.NestedHitObjects.OfType<CatchHitObject>())
{ {
TinyDroplet tiny = tick as TinyDroplet; TinyDroplet tiny = tick as TinyDroplet;
if (tiny != null) if (tiny != null)

View File

@ -11,7 +11,6 @@ using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using OpenTK; using OpenTK;
using osu.Framework.Lists;
namespace osu.Game.Rulesets.Catch.Objects namespace osu.Game.Rulesets.Catch.Objects
{ {
@ -29,9 +28,9 @@ namespace osu.Game.Rulesets.Catch.Objects
public double Velocity; public double Velocity;
public double TickDistance; public double TickDistance;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);
@ -42,92 +41,94 @@ namespace osu.Game.Rulesets.Catch.Objects
TickDistance = scoringDistance / difficulty.SliderTickRate; TickDistance = scoringDistance / difficulty.SliderTickRate;
} }
public IEnumerable<CatchHitObject> Ticks protected override void CreateNestedHitObjects()
{ {
get base.CreateNestedHitObjects();
createTicks();
}
private void createTicks()
{
if (TickDistance == 0)
return;
var length = Curve.Distance;
var tickDistance = Math.Min(TickDistance, length);
var repeatDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
AddNested(new Fruit
{ {
SortedList<CatchHitObject> ticks = new SortedList<CatchHitObject>((a, b) => a.StartTime.CompareTo(b.StartTime)); Samples = Samples,
ComboColour = ComboColour,
StartTime = StartTime,
X = X
});
if (TickDistance == 0) for (var repeat = 0; repeat < RepeatCount; repeat++)
return ticks; {
var repeatStartTime = StartTime + repeat * repeatDuration;
var reversed = repeat % 2 == 1;
var length = Curve.Distance; for (var d = tickDistance; d <= length; d += tickDistance)
var tickDistance = Math.Min(TickDistance, length);
var repeatDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
ticks.Add(new Fruit
{ {
Samples = Samples, if (d > length - minDistanceFromEnd)
ComboColour = ComboColour, break;
StartTime = StartTime,
X = X
});
for (var repeat = 0; repeat < RepeatCount; repeat++) var timeProgress = d / length;
{ var distanceProgress = reversed ? 1 - timeProgress : timeProgress;
var repeatStartTime = StartTime + repeat * repeatDuration;
var reversed = repeat % 2 == 1;
for (var d = tickDistance; d <= length; d += tickDistance) var lastTickTime = repeatStartTime + timeProgress * repeatDuration;
AddNested(new Droplet
{ {
if (d > length - minDistanceFromEnd) StartTime = lastTickTime,
break;
var timeProgress = d / length;
var distanceProgress = reversed ? 1 - timeProgress : timeProgress;
var lastTickTime = repeatStartTime + timeProgress * repeatDuration;
ticks.Add(new Droplet
{
StartTime = lastTickTime,
ComboColour = ComboColour,
X = Curve.PositionAt(distanceProgress).X / CatchPlayfield.BASE_WIDTH,
Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
{
Bank = s.Bank,
Name = @"slidertick",
Volume = s.Volume
}))
});
}
double tinyTickInterval = tickDistance / length * repeatDuration;
while (tinyTickInterval > 100)
tinyTickInterval /= 2;
for (double t = 0; t < repeatDuration; t += tinyTickInterval)
{
double progress = reversed ? 1 - t / repeatDuration : t / repeatDuration;
ticks.Add(new TinyDroplet
{
StartTime = repeatStartTime + t,
ComboColour = ComboColour,
X = Curve.PositionAt(progress).X / CatchPlayfield.BASE_WIDTH,
Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
{
Bank = s.Bank,
Name = @"slidertick",
Volume = s.Volume
}))
});
}
ticks.Add(new Fruit
{
Samples = Samples,
ComboColour = ComboColour, ComboColour = ComboColour,
StartTime = repeatStartTime + repeatDuration, X = Curve.PositionAt(distanceProgress).X / CatchPlayfield.BASE_WIDTH,
X = Curve.PositionAt(reversed ? 0 : 1).X / CatchPlayfield.BASE_WIDTH Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
{
Bank = s.Bank,
Name = @"slidertick",
Volume = s.Volume
}))
}); });
} }
return ticks; double tinyTickInterval = tickDistance / length * repeatDuration;
while (tinyTickInterval > 100)
tinyTickInterval /= 2;
for (double t = 0; t < repeatDuration; t += tinyTickInterval)
{
double progress = reversed ? 1 - t / repeatDuration : t / repeatDuration;
AddNested(new TinyDroplet
{
StartTime = repeatStartTime + t,
ComboColour = ComboColour,
X = Curve.PositionAt(progress).X / CatchPlayfield.BASE_WIDTH,
Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
{
Bank = s.Bank,
Name = @"slidertick",
Volume = s.Volume
}))
});
}
AddNested(new Fruit
{
Samples = Samples,
ComboColour = ComboColour,
StartTime = repeatStartTime + repeatDuration,
X = Curve.PositionAt(reversed ? 0 : 1).X / CatchPlayfield.BASE_WIDTH
});
} }
} }
public double EndTime => StartTime + RepeatCount * Curve.Distance / Velocity; public double EndTime => StartTime + RepeatCount * Curve.Distance / Velocity;
public float EndX => Curve.PositionAt(ProgressAt(1)).X / CatchPlayfield.BASE_WIDTH; public float EndX => Curve.PositionAt(ProgressAt(1)).X / CatchPlayfield.BASE_WIDTH;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
@ -28,7 +29,7 @@ namespace osu.Game.Rulesets.Catch.Scoring
AddJudgement(new CatchJudgement { Result = HitResult.Perfect }); AddJudgement(new CatchJudgement { Result = HitResult.Perfect });
AddJudgement(new CatchJudgement { Result = HitResult.Perfect }); AddJudgement(new CatchJudgement { Result = HitResult.Perfect });
foreach (var unused in stream.Ticks) foreach (var unused in stream.NestedHitObjects.OfType<CatchHitObject>())
AddJudgement(new CatchJudgement { Result = HitResult.Perfect }); AddJudgement(new CatchJudgement { Result = HitResult.Perfect });
continue; continue;

View File

@ -77,7 +77,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
} }
}); });
foreach (var tick in HitObject.Ticks) foreach (var tick in HitObject.NestedHitObjects.OfType<HoldNoteTick>())
{ {
var drawableTick = new DrawableHoldNoteTick(tick) var drawableTick = new DrawableHoldNoteTick(tick)
{ {

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
@ -63,9 +62,9 @@ namespace osu.Game.Rulesets.Mania.Objects
/// </summary> /// </summary>
private double tickSpacing = 50; private double tickSpacing = 50;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
tickSpacing = timingPoint.BeatLength / difficulty.SliderTickRate; tickSpacing = timingPoint.BeatLength / difficulty.SliderTickRate;
@ -74,29 +73,27 @@ namespace osu.Game.Rulesets.Mania.Objects
Tail.ApplyDefaults(controlPointInfo, difficulty); Tail.ApplyDefaults(controlPointInfo, difficulty);
} }
/// <summary> protected override void CreateNestedHitObjects()
/// The scoring scoring ticks of the hold note.
/// </summary>
public IEnumerable<HoldNoteTick> Ticks => ticks ?? (ticks = createTicks());
private List<HoldNoteTick> ticks;
private List<HoldNoteTick> createTicks()
{ {
var ret = new List<HoldNoteTick>(); base.CreateNestedHitObjects();
createTicks();
}
private void createTicks()
{
if (tickSpacing == 0) if (tickSpacing == 0)
return ret; return;
for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing) for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing)
{ {
ret.Add(new HoldNoteTick AddNested(new HoldNoteTick
{ {
StartTime = t, StartTime = t,
Column = Column Column = Column
}); });
} }
return ret;
} }
/// <summary> /// <summary>
@ -110,9 +107,9 @@ namespace osu.Game.Rulesets.Mania.Objects
/// </summary> /// </summary>
private const double release_window_lenience = 1.5; private const double release_window_lenience = 1.5;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
HitWindows *= release_window_lenience; HitWindows *= release_window_lenience;
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using Newtonsoft.Json;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Mania.Judgements;
@ -15,11 +16,12 @@ namespace osu.Game.Rulesets.Mania.Objects
/// <summary> /// <summary>
/// The key-press hit window for this note. /// The key-press hit window for this note.
/// </summary> /// </summary>
[JsonIgnore]
public HitWindows HitWindows { get; protected set; } = new HitWindows(); public HitWindows HitWindows { get; protected set; } = new HitWindows();
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
HitWindows = new HitWindows(difficulty.OverallDifficulty); HitWindows = new HitWindows(difficulty.OverallDifficulty);
} }

View File

@ -116,7 +116,7 @@ namespace osu.Game.Rulesets.Mania.Scoring
AddJudgement(new ManiaJudgement { Result = HitResult.Perfect }); AddJudgement(new ManiaJudgement { Result = HitResult.Perfect });
// Ticks // Ticks
int tickCount = holdNote.Ticks.Count(); int tickCount = holdNote.NestedHitObjects.OfType<HoldNoteTick>().Count();
for (int i = 0; i < tickCount; i++) for (int i = 0; i < tickCount; i++)
AddJudgement(new HoldNoteTickJudgement { Result = HitResult.Perfect }); AddJudgement(new HoldNoteTickJudgement { Result = HitResult.Perfect });
} }

View File

@ -9,7 +9,6 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Lists;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -44,7 +43,7 @@ namespace osu.Game.Rulesets.Mania.UI
// Generate the bar lines // Generate the bar lines
double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
SortedList<TimingControlPoint> timingPoints = Beatmap.ControlPointInfo.TimingPoints; var timingPoints = Beatmap.ControlPointInfo.TimingPoints;
var barLines = new List<DrawableBarLine>(); var barLines = new List<DrawableBarLine>();
for (int i = 0; i < timingPoints.Count; i++) for (int i = 0; i < timingPoints.Count; i++)

View File

@ -40,6 +40,10 @@
<HintPath>$(SolutionDir)\packages\OpenTK.3.0.0-git00009\lib\net20\OpenTK.dll</HintPath> <HintPath>$(SolutionDir)\packages\OpenTK.3.0.0-git00009\lib\net20\OpenTK.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
</ItemGroup> </ItemGroup>

View File

@ -57,6 +57,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Scale = s.Scale, Scale = s.Scale,
ComboColour = s.ComboColour, ComboColour = s.ComboColour,
Samples = s.Samples, Samples = s.Samples,
SoundControlPoint = s.SoundControlPoint
}) })
}; };
@ -66,7 +67,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
AddNested(initialCircle); AddNested(initialCircle);
var repeatDuration = s.Curve.Distance / s.Velocity; var repeatDuration = s.Curve.Distance / s.Velocity;
foreach (var tick in s.Ticks) foreach (var tick in s.NestedHitObjects.OfType<SliderTick>())
{ {
var repeatStartTime = s.StartTime + tick.RepeatIndex * repeatDuration; var repeatStartTime = s.StartTime + tick.RepeatIndex * repeatDuration;
var fadeInTime = repeatStartTime + (tick.StartTime - repeatStartTime) / 2 - (tick.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2); var fadeInTime = repeatStartTime + (tick.StartTime - repeatStartTime) / 2 - (tick.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2);
@ -83,7 +84,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
AddNested(drawableTick); AddNested(drawableTick);
} }
foreach (var repeatPoint in s.RepeatPoints) foreach (var repeatPoint in s.NestedHitObjects.OfType<RepeatPoint>())
{ {
var repeatStartTime = s.StartTime + repeatPoint.RepeatIndex * repeatDuration; var repeatStartTime = s.StartTime + repeatPoint.RepeatIndex * repeatDuration;
var fadeInTime = repeatStartTime + (repeatPoint.StartTime - repeatStartTime) / 2 - (repeatPoint.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2); var fadeInTime = repeatStartTime + (repeatPoint.StartTime - repeatStartTime) / 2 - (repeatPoint.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2);

View File

@ -68,9 +68,9 @@ namespace osu.Game.Rulesets.Osu.Objects
return HitResult.Miss; return HitResult.Miss;
} }
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2; Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2;
} }

View File

@ -74,9 +74,9 @@ namespace osu.Game.Rulesets.Osu.Objects
public double Velocity; public double Velocity;
public double TickDistance; public double TickDistance;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);
@ -99,75 +99,78 @@ namespace osu.Game.Rulesets.Osu.Objects
public int RepeatAt(double progress) => (int)(progress * RepeatCount); public int RepeatAt(double progress) => (int)(progress * RepeatCount);
public IEnumerable<SliderTick> Ticks protected override void CreateNestedHitObjects()
{ {
get base.CreateNestedHitObjects();
createTicks();
createRepeatPoints();
}
private void createTicks()
{
if (TickDistance == 0) return;
var length = Curve.Distance;
var tickDistance = Math.Min(TickDistance, length);
var repeatDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
for (var repeat = 0; repeat < RepeatCount; repeat++)
{ {
if (TickDistance == 0) yield break; var repeatStartTime = StartTime + repeat * repeatDuration;
var reversed = repeat % 2 == 1;
var length = Curve.Distance; for (var d = tickDistance; d <= length; d += tickDistance)
var tickDistance = Math.Min(TickDistance, length);
var repeatDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
for (var repeat = 0; repeat < RepeatCount; repeat++)
{ {
var repeatStartTime = StartTime + repeat * repeatDuration; if (d > length - minDistanceFromEnd)
var reversed = repeat % 2 == 1; break;
for (var d = tickDistance; d <= length; d += tickDistance) var distanceProgress = d / length;
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress;
AddNested(new SliderTick
{ {
if (d > length - minDistanceFromEnd) RepeatIndex = repeat,
break; StartTime = repeatStartTime + timeProgress * repeatDuration,
Position = Curve.PositionAt(distanceProgress),
var distanceProgress = d / length; StackHeight = StackHeight,
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress; Scale = Scale,
ComboColour = ComboColour,
yield return new SliderTick Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
{ {
RepeatIndex = repeat, Bank = s.Bank,
StartTime = repeatStartTime + timeProgress * repeatDuration, Name = @"slidertick",
Position = Curve.PositionAt(distanceProgress), Volume = s.Volume
StackHeight = StackHeight, }))
Scale = Scale, });
ComboColour = ComboColour,
Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
{
Bank = s.Bank,
Name = @"slidertick",
Volume = s.Volume
}))
};
}
} }
} }
} }
public IEnumerable<RepeatPoint> RepeatPoints
private void createRepeatPoints()
{ {
get var length = Curve.Distance;
var repeatPointDistance = Math.Min(Distance, length);
var repeatDuration = length / Velocity;
for (var repeat = 1; repeat < RepeatCount; repeat++)
{ {
var length = Curve.Distance; for (var d = repeatPointDistance; d <= length; d += repeatPointDistance)
var repeatPointDistance = Math.Min(Distance, length);
var repeatDuration = length / Velocity;
for (var repeat = 1; repeat < RepeatCount; repeat++)
{ {
for (var d = repeatPointDistance; d <= length; d += repeatPointDistance) var repeatStartTime = StartTime + repeat * repeatDuration;
{ var distanceProgress = d / length;
var repeatStartTime = StartTime + repeat * repeatDuration;
var distanceProgress = d / length;
yield return new RepeatPoint AddNested(new RepeatPoint
{ {
RepeatIndex = repeat, RepeatIndex = repeat,
StartTime = repeatStartTime, StartTime = repeatStartTime,
Position = Curve.PositionAt(distanceProgress), Position = Curve.PositionAt(distanceProgress),
StackHeight = StackHeight, StackHeight = StackHeight,
Scale = Scale, Scale = Scale,
ComboColour = ComboColour, ComboColour = ComboColour,
}; });
}
} }
} }
} }

View File

@ -19,9 +19,9 @@ namespace osu.Game.Rulesets.Osu.Objects
public override bool NewCombo => true; public override bool NewCombo => true;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
SpinsRequired = (int)(Duration / 1000 * BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 3, 5, 7.5)); SpinsRequired = (int)(Duration / 1000 * BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 3, 5, 7.5));

View File

@ -107,7 +107,7 @@ namespace osu.Game.Rulesets.Osu.OsuDifficulty.Preprocessing
} }
}); });
var scoringTimes = slider.Ticks.Select(t => t.StartTime).Concat(slider.RepeatPoints.Select(r => r.StartTime)).OrderBy(t => t); var scoringTimes = slider.NestedHitObjects.Select(t => t.StartTime);
foreach (var time in scoringTimes) foreach (var time in scoringTimes)
computeVertex(time); computeVertex(time);
computeVertex(slider.EndTime); computeVertex(slider.EndTime);

View File

@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Osu.Scoring
countHitCircles = Beatmap.HitObjects.Count(h => h is HitCircle); countHitCircles = Beatmap.HitObjects.Count(h => h is HitCircle);
beatmapMaxCombo = Beatmap.HitObjects.Count; beatmapMaxCombo = Beatmap.HitObjects.Count;
beatmapMaxCombo += Beatmap.HitObjects.OfType<Slider>().Sum(s => s.RepeatCount + s.Ticks.Count()); beatmapMaxCombo += Beatmap.HitObjects.OfType<Slider>().Sum(s => s.NestedHitObjects.Count) + 1;
} }
public override double Calculate(Dictionary<string, double> categoryRatings = null) public override double Calculate(Dictionary<string, double> categoryRatings = null)

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
@ -39,11 +40,11 @@ namespace osu.Game.Rulesets.Osu.Scoring
AddJudgement(new OsuJudgement { Result = HitResult.Great }); AddJudgement(new OsuJudgement { Result = HitResult.Great });
// Ticks // Ticks
foreach (var unused in slider.Ticks) foreach (var unused in slider.NestedHitObjects.OfType<SliderTick>())
AddJudgement(new OsuJudgement { Result = HitResult.Great }); AddJudgement(new OsuJudgement { Result = HitResult.Great });
//Repeats //Repeats
foreach (var unused in slider.RepeatPoints) foreach (var unused in slider.NestedHitObjects.OfType<RepeatPoint>())
AddJudgement(new OsuJudgement { Result = HitResult.Great }); AddJudgement(new OsuJudgement { Result = HitResult.Great });
} }

View File

@ -43,7 +43,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
RelativeChildSize = new Vector2((float)HitObject.Duration, 1) RelativeChildSize = new Vector2((float)HitObject.Duration, 1)
}); });
foreach (var tick in drumRoll.Ticks) foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
{ {
var newTick = new DrawableDrumRollTick(tick); var newTick = new DrawableDrumRollTick(tick);
newTick.OnJudgement += onTickJudgement; newTick.OnJudgement += onTickJudgement;

View File

@ -3,7 +3,6 @@
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -37,47 +36,40 @@ namespace osu.Game.Rulesets.Taiko.Objects
/// </summary> /// </summary>
public double RequiredGreatHits { get; protected set; } public double RequiredGreatHits { get; protected set; }
/// <summary>
/// Total number of drum roll ticks.
/// </summary>
public int TotalTicks => Ticks.Count();
/// <summary>
/// Initializes the drum roll ticks if not initialized and returns them.
/// </summary>
public IEnumerable<DrumRollTick> Ticks => ticks ?? (ticks = createTicks());
private List<DrumRollTick> ticks;
/// <summary> /// <summary>
/// The length (in milliseconds) between ticks of this drumroll. /// The length (in milliseconds) between ticks of this drumroll.
/// <para>Half of this value is the hit window of the ticks.</para> /// <para>Half of this value is the hit window of the ticks.</para>
/// </summary> /// </summary>
private double tickSpacing = 100; private double tickSpacing = 100;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
tickSpacing = timingPoint.BeatLength / TickRate; tickSpacing = timingPoint.BeatLength / TickRate;
RequiredGoodHits = TotalTicks * Math.Min(0.15, 0.05 + 0.10 / 6 * difficulty.OverallDifficulty); RequiredGoodHits = NestedHitObjects.Count * Math.Min(0.15, 0.05 + 0.10 / 6 * difficulty.OverallDifficulty);
RequiredGreatHits = TotalTicks * Math.Min(0.30, 0.10 + 0.20 / 6 * difficulty.OverallDifficulty); RequiredGreatHits = NestedHitObjects.Count * Math.Min(0.30, 0.10 + 0.20 / 6 * difficulty.OverallDifficulty);
} }
private List<DrumRollTick> createTicks() protected override void CreateNestedHitObjects()
{ {
var ret = new List<DrumRollTick>(); base.CreateNestedHitObjects();
createTicks();
}
private void createTicks()
{
if (tickSpacing == 0) if (tickSpacing == 0)
return ret; return;
bool first = true; bool first = true;
for (double t = StartTime; t < EndTime + tickSpacing / 2; t += tickSpacing) for (double t = StartTime; t < EndTime + tickSpacing / 2; t += tickSpacing)
{ {
ret.Add(new DrumRollTick AddNested(new DrumRollTick
{ {
FirstTick = first, FirstTick = first,
TickSpacing = tickSpacing, TickSpacing = tickSpacing,
@ -93,8 +85,6 @@ namespace osu.Game.Rulesets.Taiko.Objects
first = false; first = false;
} }
return ret;
} }
} }
} }

View File

@ -23,9 +23,9 @@ namespace osu.Game.Rulesets.Taiko.Objects
/// </summary> /// </summary>
public double HitWindowMiss = 95; public double HitWindowMiss = 95;
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
HitWindowGreat = BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 50, 35, 20); HitWindowGreat = BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 50, 35, 20);
HitWindowGood = BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 120, 80, 50); HitWindowGood = BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 120, 80, 50);

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.Objects;
@ -83,7 +84,7 @@ namespace osu.Game.Rulesets.Taiko.Replays
} }
else if (drumRoll != null) else if (drumRoll != null)
{ {
foreach (var tick in drumRoll.Ticks) foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
{ {
Frames.Add(new ReplayFrame(tick.StartTime, null, null, hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2)); Frames.Add(new ReplayFrame(tick.StartTime, null, null, hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2));
hitButton = !hitButton; hitButton = !hitButton;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -88,7 +89,7 @@ namespace osu.Game.Rulesets.Taiko.Scoring
} }
else if (obj is DrumRoll) else if (obj is DrumRoll)
{ {
for (int i = 0; i < ((DrumRoll)obj).TotalTicks; i++) for (int i = 0; i < ((DrumRoll)obj).NestedHitObjects.OfType<DrumRollTick>().Count(); i++)
{ {
AddJudgement(new TaikoDrumRollTickJudgement { Result = HitResult.Great }); AddJudgement(new TaikoDrumRollTickJudgement { Result = HitResult.Great });

View File

@ -0,0 +1,176 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO;
using System.Linq;
using DeepEqual.Syntax;
using NUnit.Framework;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO.Serialization;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Tests.Resources;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Tests.Beatmaps.Formats
{
[TestFixture]
public class OsuJsonDecoderTest
{
private const string normal = "Soleily - Renatus (Gamu) [Insane].osu";
private const string marathon = "Within Temptation - The Unforgiving (Armin) [Marathon].osu";
private const string with_sb = "Kozato snow - Rengetsu Ouka (_Kiva) [Yuki YukI].osu";
[Test]
public void TestDecodeMetadata()
{
var beatmap = decodeAsJson(normal);
var meta = beatmap.BeatmapInfo.Metadata;
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);
Assert.AreEqual("Gamu", meta.AuthorString);
Assert.AreEqual("machinetop_background.jpg", meta.BackgroundFile);
Assert.AreEqual(164471, meta.PreviewTime);
Assert.AreEqual(string.Empty, meta.Source);
Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", meta.Tags);
Assert.AreEqual("Renatus", meta.Title);
Assert.AreEqual("Renatus", meta.TitleUnicode);
}
[Test]
public void TestDecodeGeneral()
{
var beatmap = decodeAsJson(normal);
var beatmapInfo = beatmap.BeatmapInfo;
Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
Assert.AreEqual(false, beatmapInfo.Countdown);
Assert.AreEqual(0.7f, beatmapInfo.StackLeniency);
Assert.AreEqual(false, beatmapInfo.SpecialStyle);
Assert.IsTrue(beatmapInfo.RulesetID == 0);
Assert.AreEqual(false, beatmapInfo.LetterboxInBreaks);
Assert.AreEqual(false, beatmapInfo.WidescreenStoryboard);
}
[Test]
public void TestDecodeEditor()
{
var beatmap = decodeAsJson(normal);
var beatmapInfo = beatmap.BeatmapInfo;
int[] expectedBookmarks =
{
11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351,
95901, 106450, 116999, 119637, 130186, 140735, 151285,
161834, 164471, 175020, 185570, 196119, 206669, 209306
};
Assert.AreEqual(expectedBookmarks.Length, beatmapInfo.Bookmarks.Length);
for (int i = 0; i < expectedBookmarks.Length; i++)
Assert.AreEqual(expectedBookmarks[i], beatmapInfo.Bookmarks[i]);
Assert.AreEqual(1.8, beatmapInfo.DistanceSpacing);
Assert.AreEqual(4, beatmapInfo.BeatDivisor);
Assert.AreEqual(4, beatmapInfo.GridSize);
Assert.AreEqual(2, beatmapInfo.TimelineZoom);
}
[Test]
public void TestDecodeDifficulty()
{
var beatmap = decodeAsJson(normal);
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
Assert.AreEqual(6.5f, difficulty.DrainRate);
Assert.AreEqual(4, difficulty.CircleSize);
Assert.AreEqual(8, difficulty.OverallDifficulty);
Assert.AreEqual(9, difficulty.ApproachRate);
Assert.AreEqual(1.8f, difficulty.SliderMultiplier);
Assert.AreEqual(2, difficulty.SliderTickRate);
}
[Test]
public void TestDecodeColors()
{
var beatmap = decodeAsJson(normal);
Color4[] expected =
{
new Color4(142, 199, 255, 255),
new Color4(255, 128, 128, 255),
new Color4(128, 255, 255, 255),
new Color4(128, 255, 128, 255),
new Color4(255, 187, 255, 255),
new Color4(255, 177, 140, 255),
};
Assert.AreEqual(expected.Length, beatmap.ComboColors.Count);
for (int i = 0; i < expected.Length; i++)
Assert.AreEqual(expected[i], beatmap.ComboColors[i]);
}
[Test]
public void TestDecodeHitObjects()
{
var beatmap = decodeAsJson(normal);
var curveData = beatmap.HitObjects[0] as IHasCurve;
var positionData = beatmap.HitObjects[0] as IHasPosition;
Assert.IsNotNull(positionData);
Assert.IsNotNull(curveData);
Assert.AreEqual(new Vector2(192, 168), positionData.Position);
Assert.AreEqual(956, beatmap.HitObjects[0].StartTime);
Assert.IsTrue(beatmap.HitObjects[0].Samples.Any(s => s.Name == SampleInfo.HIT_NORMAL));
positionData = beatmap.HitObjects[1] as IHasPosition;
Assert.IsNotNull(positionData);
Assert.AreEqual(new Vector2(304, 56), positionData.Position);
Assert.AreEqual(1285, beatmap.HitObjects[1].StartTime);
Assert.IsTrue(beatmap.HitObjects[1].Samples.Any(s => s.Name == SampleInfo.HIT_CLAP));
}
[TestCase(normal)]
[TestCase(marathon)]
// Currently fails:
// [TestCase(with_sb)]
public void TestParity(string beatmap)
{
var beatmaps = decode(beatmap);
beatmaps.jsonDecoded.ShouldDeepEqual(beatmaps.legacyDecoded);
}
/// <summary>
/// Reads a .osu file first with a <see cref="LegacyBeatmapDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
/// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="JsonBeatmapDecoder"/>.
/// </summary>
/// <param name="filename">The .osu file to decode.</param>
/// <returns>The <see cref="Beatmap"/> after being decoded by an <see cref="LegacyBeatmapDecoder"/>.</returns>
private Beatmap decodeAsJson(string filename) => decode(filename).jsonDecoded;
/// <summary>
/// Reads a .osu file first with a <see cref="LegacyBeatmapDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
/// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="JsonBeatmapDecoder"/>.
/// </summary>
/// <param name="filename">The .osu file to decode.</param>
/// <returns>The <see cref="Beatmap"/> after being decoded by an <see cref="LegacyBeatmapDecoder"/>.</returns>
private (Beatmap legacyDecoded, Beatmap jsonDecoded) decode(string filename)
{
using (var stream = Resource.OpenResource(filename))
using (var sr = new StreamReader(stream))
{
var legacyDecoded = new LegacyBeatmapDecoder().DecodeBeatmap(sr);
using (var ms = new MemoryStream())
using (var sw = new StreamWriter(ms))
using (var sr2 = new StreamReader(ms))
{
sw.Write(legacyDecoded.Serialize());
sw.Flush();
ms.Position = 0;
return (legacyDecoded, new JsonBeatmapDecoder().DecodeBeatmap(sr2));
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -7,13 +7,13 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Lists;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays; using osu.Game.Overlays;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Lists;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {

View File

@ -30,6 +30,9 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="DeepEqual, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>$(SolutionDir)\packages\DeepEqual.1.6.0.0\lib\net40\DeepEqual.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> <Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath> <HintPath>$(SolutionDir)\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@ -83,6 +86,7 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Beatmaps\Formats\OsuJsonDecoderTest.cs" />
<Compile Include="Beatmaps\Formats\LegacyStoryboardDecoderTest.cs" /> <Compile Include="Beatmaps\Formats\LegacyStoryboardDecoderTest.cs" />
<Compile Include="Beatmaps\IO\OszArchiveReaderTest.cs" /> <Compile Include="Beatmaps\IO\OszArchiveReaderTest.cs" />
<Compile Include="Beatmaps\IO\ImportBeatmapTest.cs" /> <Compile Include="Beatmaps\IO\ImportBeatmapTest.cs" />
@ -153,6 +157,8 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\Soleily - Renatus %28Gamu%29 [Insane].osu" /> <EmbeddedResource Include="Resources\Soleily - Renatus %28Gamu%29 [Insane].osu" />
<EmbeddedResource Include="Resources\Himeringo - Yotsuya-san ni Yoroshiku %28RLC%29 [Winber1%27s Extreme].osu" /> <EmbeddedResource Include="Resources\Himeringo - Yotsuya-san ni Yoroshiku %28RLC%29 [Winber1%27s Extreme].osu" />
<EmbeddedResource Include="Resources\Within Temptation - The Unforgiving %28Armin%29 [Marathon].osu" />
<EmbeddedResource Include="Resources\Kozato snow - Rengetsu Ouka %28_Kiva%29 [Yuki YukI].osu" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -4,6 +4,7 @@ Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
--> -->
<packages> <packages>
<package id="DeepEqual" version="1.6.0.0" targetFramework="net461" />
<package id="NUnit" version="3.8.1" targetFramework="net461" /> <package id="NUnit" version="3.8.1" targetFramework="net461" />
<package id="OpenTK" version="3.0.0-git00009" targetFramework="net461" /> <package id="OpenTK" version="3.0.0-git00009" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" /> <package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />

View File

@ -1,8 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
namespace osu.Game.Audio namespace osu.Game.Audio
{ {
[Serializable]
public class SampleInfo public class SampleInfo
{ {
public const string HIT_WHISTLE = @"hitwhistle"; public const string HIT_WHISTLE = @"hitwhistle";

View File

@ -8,19 +8,21 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.IO.Serialization; using osu.Game.IO.Serialization;
using Newtonsoft.Json;
using osu.Game.IO.Serialization.Converters;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
/// <summary> /// <summary>
/// A Beatmap containing converted HitObjects. /// A Beatmap containing converted HitObjects.
/// </summary> /// </summary>
public class Beatmap<T> public class Beatmap<T> : IJsonSerializable
where T : HitObject where T : HitObject
{ {
public BeatmapInfo BeatmapInfo = new BeatmapInfo(); public BeatmapInfo BeatmapInfo = new BeatmapInfo();
public ControlPointInfo ControlPointInfo = new ControlPointInfo(); public ControlPointInfo ControlPointInfo = new ControlPointInfo();
public List<BreakPeriod> Breaks = new List<BreakPeriod>(); public List<BreakPeriod> Breaks = new List<BreakPeriod>();
public readonly List<Color4> ComboColors = new List<Color4> public List<Color4> ComboColors = new List<Color4>
{ {
new Color4(17, 136, 170, 255), new Color4(17, 136, 170, 255),
new Color4(102, 136, 0, 255), new Color4(102, 136, 0, 255),
@ -28,16 +30,19 @@ namespace osu.Game.Beatmaps
new Color4(121, 9, 13, 255) new Color4(121, 9, 13, 255)
}; };
[JsonIgnore]
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata; public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
/// <summary> /// <summary>
/// The HitObjects this Beatmap contains. /// The HitObjects this Beatmap contains.
/// </summary> /// </summary>
[JsonConverter(typeof(TypedListConverter<HitObject>))]
public List<T> HitObjects = new List<T>(); public List<T> HitObjects = new List<T>();
/// <summary> /// <summary>
/// Total amount of break time in the beatmap. /// Total amount of break time in the beatmap.
/// </summary> /// </summary>
[JsonIgnore]
public double TotalBreakTime => Breaks.Sum(b => b.Duration); public double TotalBreakTime => Breaks.Sum(b => b.Duration);
/// <summary> /// <summary>

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
@ -13,6 +14,7 @@ namespace osu.Game.Beatmaps
public const float DEFAULT_DIFFICULTY = 5; public const float DEFAULT_DIFFICULTY = 5;
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
public int ID { get; set; } public int ID { get; set; }
public float DrainRate { get; set; } = DEFAULT_DIFFICULTY; public float DrainRate { get; set; } = DEFAULT_DIFFICULTY;

View File

@ -12,9 +12,11 @@ using osu.Game.Rulesets;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
[Serializable]
public class BeatmapInfo : IEquatable<BeatmapInfo>, IJsonSerializable, IHasPrimaryKey public class BeatmapInfo : IEquatable<BeatmapInfo>, IJsonSerializable, IHasPrimaryKey
{ {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
public int ID { get; set; } public int ID { get; set; }
//TODO: should be in database //TODO: should be in database
@ -38,13 +40,16 @@ namespace osu.Game.Beatmaps
set { onlineBeatmapSetID = value > 0 ? value : null; } set { onlineBeatmapSetID = value > 0 ? value : null; }
} }
[JsonIgnore]
public int BeatmapSetInfoID { get; set; } public int BeatmapSetInfoID { get; set; }
[Required] [Required]
[JsonIgnore]
public BeatmapSetInfo BeatmapSet { get; set; } public BeatmapSetInfo BeatmapSet { get; set; }
public BeatmapMetadata Metadata { get; set; } public BeatmapMetadata Metadata { get; set; }
[JsonIgnore]
public int BaseDifficultyID { get; set; } public int BaseDifficultyID { get; set; }
public BeatmapDifficulty BaseDifficulty { get; set; } public BeatmapDifficulty BaseDifficulty { get; set; }
@ -60,6 +65,7 @@ namespace osu.Game.Beatmaps
[JsonProperty("file_sha2")] [JsonProperty("file_sha2")]
public string Hash { get; set; } public string Hash { get; set; }
[JsonIgnore]
public bool Hidden { get; set; } public bool Hidden { get; set; }
/// <summary> /// <summary>

View File

@ -10,9 +10,11 @@ using osu.Game.Users;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
[Serializable]
public class BeatmapMetadata : IEquatable<BeatmapMetadata> public class BeatmapMetadata : IEquatable<BeatmapMetadata>
{ {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
public int ID { get; set; } public int ID { get; set; }
private int? onlineBeatmapSetID; private int? onlineBeatmapSetID;
@ -30,7 +32,10 @@ namespace osu.Game.Beatmaps
public string Artist { get; set; } public string Artist { get; set; }
public string ArtistUnicode { get; set; } public string ArtistUnicode { get; set; }
[JsonIgnore]
public List<BeatmapInfo> Beatmaps { get; set; } public List<BeatmapInfo> Beatmaps { get; set; }
[JsonIgnore]
public List<BeatmapSetInfo> BeatmapSets { get; set; } public List<BeatmapSetInfo> BeatmapSets { get; set; }
/// <summary> /// <summary>
@ -47,6 +52,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// The author of the beatmaps in this set. /// The author of the beatmaps in this set.
/// </summary> /// </summary>
[JsonIgnore]
public User Author; public User Author;
public string Source { get; set; } public string Source { get; set; }
@ -59,6 +65,7 @@ namespace osu.Game.Beatmaps
public override string ToString() => $"{Artist} - {Title} ({Author})"; public override string ToString() => $"{Artist} - {Title} ({Author})";
[JsonIgnore]
public string[] SearchableTerms => new[] public string[] SearchableTerms => new[]
{ {
Author?.Username, Author?.Username,

View File

@ -4,31 +4,37 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Lists; using osu.Framework.Lists;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
{ {
[Serializable]
public class ControlPointInfo public class ControlPointInfo
{ {
/// <summary> /// <summary>
/// All timing points. /// All timing points.
/// </summary> /// </summary>
public readonly SortedList<TimingControlPoint> TimingPoints = new SortedList<TimingControlPoint>(Comparer<TimingControlPoint>.Default); [JsonProperty]
public SortedList<TimingControlPoint> TimingPoints { get; private set; } = new SortedList<TimingControlPoint>(Comparer<TimingControlPoint>.Default);
/// <summary> /// <summary>
/// All difficulty points. /// All difficulty points.
/// </summary> /// </summary>
public readonly SortedList<DifficultyControlPoint> DifficultyPoints = new SortedList<DifficultyControlPoint>(Comparer<DifficultyControlPoint>.Default); [JsonProperty]
public SortedList<DifficultyControlPoint> DifficultyPoints { get; private set; } = new SortedList<DifficultyControlPoint>(Comparer<DifficultyControlPoint>.Default);
/// <summary> /// <summary>
/// All sound points. /// All sound points.
/// </summary> /// </summary>
public readonly SortedList<SoundControlPoint> SoundPoints = new SortedList<SoundControlPoint>(Comparer<SoundControlPoint>.Default); [JsonProperty]
public SortedList<SoundControlPoint> SoundPoints { get; private set; } = new SortedList<SoundControlPoint>(Comparer<SoundControlPoint>.Default);
/// <summary> /// <summary>
/// All effect points. /// All effect points.
/// </summary> /// </summary>
public readonly SortedList<EffectControlPoint> EffectPoints = new SortedList<EffectControlPoint>(Comparer<EffectControlPoint>.Default); [JsonProperty]
public SortedList<EffectControlPoint> EffectPoints { get; private set; } = new SortedList<EffectControlPoint>(Comparer<EffectControlPoint>.Default);
/// <summary> /// <summary>
/// Finds the difficulty control point that is active at <paramref name="time"/>. /// Finds the difficulty control point that is active at <paramref name="time"/>.
@ -58,18 +64,21 @@ namespace osu.Game.Beatmaps.ControlPoints
/// <returns>The timing control point.</returns> /// <returns>The timing control point.</returns>
public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault()); public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault());
[JsonIgnore]
/// <summary> /// <summary>
/// Finds the maximum BPM represented by any timing control point. /// Finds the maximum BPM represented by any timing control point.
/// </summary> /// </summary>
public double BPMMaximum => public double BPMMaximum =>
60000 / (TimingPoints.OrderBy(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; 60000 / (TimingPoints.OrderBy(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength;
[JsonIgnore]
/// <summary> /// <summary>
/// Finds the minimum BPM represented by any timing control point. /// Finds the minimum BPM represented by any timing control point.
/// </summary> /// </summary>
public double BPMMinimum => public double BPMMinimum =>
60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; 60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength;
[JsonIgnore]
/// <summary> /// <summary>
/// Finds the mode BPM (most common BPM) represented by the control points. /// Finds the mode BPM (most common BPM) represented by the control points.
/// </summary> /// </summary>
@ -108,4 +117,4 @@ namespace osu.Game.Beatmaps.ControlPoints
return list[index - 1]; return list[index - 1];
} }
} }
} }

View File

@ -5,14 +5,16 @@ namespace osu.Game.Beatmaps.ControlPoints
{ {
public class SoundControlPoint : ControlPoint public class SoundControlPoint : ControlPoint
{ {
public const string DEFAULT_BANK = "normal";
/// <summary> /// <summary>
/// The default sample bank at this control point. /// The default sample bank at this control point.
/// </summary> /// </summary>
public string SampleBank; public string SampleBank = DEFAULT_BANK;
/// <summary> /// <summary>
/// The default sample volume at this control point. /// The default sample volume at this control point.
/// </summary> /// </summary>
public int SampleVolume; public int SampleVolume;
} }
} }

View File

@ -10,11 +10,12 @@ namespace osu.Game.Beatmaps.Formats
{ {
public abstract class Decoder public abstract class Decoder
{ {
private static readonly Dictionary<string, Type> decoders = new Dictionary<string, Type>(); private static readonly Dictionary<string, Func<string, Decoder>> decoders = new Dictionary<string, Func<string, Decoder>>();
static Decoder() static Decoder()
{ {
LegacyDecoder.Register(); LegacyDecoder.Register();
JsonBeatmapDecoder.Register();
} }
/// <summary> /// <summary>
@ -33,17 +34,18 @@ namespace osu.Game.Beatmaps.Formats
if (line == null || !decoders.ContainsKey(line)) if (line == null || !decoders.ContainsKey(line))
throw new IOException(@"Unknown file format"); throw new IOException(@"Unknown file format");
return (Decoder)Activator.CreateInstance(decoders[line], line);
return decoders[line](line);
} }
/// <summary> /// <summary>
/// Adds the <see cref="Decoder"/> to the list of <see cref="Beatmap"/> and <see cref="Storyboard"/> decoder. /// Registers an instantiation function for a <see cref="Decoder"/>.
/// </summary> /// </summary>
/// <typeparam name="T">Type to decode a <see cref="Beatmap"/> with.</typeparam> /// <param name="magic">A string in the file which triggers this decoder to be used.</param>
/// <param name="version">A string representation of the version.</param> /// <param name="constructor">A function which constructs the <see cref="Decoder"/> given <paramref name="magic"/>.</param>
protected static void AddDecoder<T>(string version) where T : Decoder protected static void AddDecoder(string magic, Func<string, Decoder> constructor)
{ {
decoders[version] = typeof(T); decoders[magic] = constructor;
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,35 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO;
using osu.Game.IO.Serialization;
using osu.Game.Storyboards;
namespace osu.Game.Beatmaps.Formats
{
public class JsonBeatmapDecoder : Decoder
{
public static void Register()
{
AddDecoder("{", m => new JsonBeatmapDecoder());
}
public override Decoder GetStoryboardDecoder() => this;
protected override void ParseBeatmap(StreamReader stream, Beatmap beatmap)
{
stream.BaseStream.Position = 0;
stream.DiscardBufferedData();
stream.ReadToEnd().DeserializeInto(beatmap);
foreach (var hitObject in beatmap.HitObjects)
hitObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
}
protected override void ParseStoryboard(StreamReader stream, Storyboard storyboard)
{
// throw new System.NotImplementedException();
}
}
}

View File

@ -13,18 +13,18 @@ namespace osu.Game.Beatmaps.Formats
{ {
public static void Register() public static void Register()
{ {
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v14"); AddDecoder(@"osu file format v14", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v13"); AddDecoder(@"osu file format v13", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v12"); AddDecoder(@"osu file format v12", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v11"); AddDecoder(@"osu file format v11", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v10"); AddDecoder(@"osu file format v10", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v9"); AddDecoder(@"osu file format v9", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v8"); AddDecoder(@"osu file format v8", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v7"); AddDecoder(@"osu file format v7", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v6"); AddDecoder(@"osu file format v6", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v5"); AddDecoder(@"osu file format v5", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v4"); AddDecoder(@"osu file format v4", m => new LegacyBeatmapDecoder(m));
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v3"); AddDecoder(@"osu file format v3", m => new LegacyBeatmapDecoder(m));
// TODO: differences between versions // TODO: differences between versions
} }

View File

@ -10,6 +10,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Game.Storyboards; using osu.Game.Storyboards;
using osu.Framework.IO.File;
using System.IO;
using osu.Game.IO.Serialization;
using System.Diagnostics;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
@ -38,6 +42,17 @@ namespace osu.Game.Beatmaps
storyboard = new AsyncLazy<Storyboard>(populateStoryboard); storyboard = new AsyncLazy<Storyboard>(populateStoryboard);
} }
/// <summary>
/// Saves the <see cref="Beatmap"/>.
/// </summary>
public void Save()
{
var path = FileSafety.GetTempPath(Guid.NewGuid().ToString().Replace("-", string.Empty) + ".json");
using (var sw = new StreamWriter(path))
sw.WriteLine(Beatmap.Serialize());
Process.Start(path);
}
protected abstract Beatmap GetBeatmap(); protected abstract Beatmap GetBeatmap();
protected abstract Texture GetBackground(); protected abstract Texture GetBackground();
protected abstract Track GetTrack(); protected abstract Track GetTrack();

View File

@ -0,0 +1,100 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace osu.Game.IO.Serialization.Converters
{
/// <summary>
/// A type of <see cref="JsonConverter"/> that serializes a <see cref="List<T>"/> alongside
/// a lookup table for the types contained. The lookup table is used in deserialization to
/// reconstruct the objects with their original types.
/// </summary>
/// <typeparam name="T">The type of objects contained in the <see cref="List<T>"/> this attribute is attached to.</typeparam>
public class TypedListConverter<T> : JsonConverter
{
private readonly bool requiresTypeVersion;
/// <summary>
/// Constructs a new <see cref="TypedListConverter{T}"/>.
/// </summary>
// ReSharper disable once UnusedMember.Global
public TypedListConverter()
{
}
/// <summary>
/// Constructs a new <see cref="TypedListConverter{T}"/>.
/// </summary>
/// <param name="requiresTypeVersion">Whether the version of the type should be serialized.</param>
// ReSharper disable once UnusedMember.Global (Used in Beatmap)
public TypedListConverter(bool requiresTypeVersion)
{
this.requiresTypeVersion = requiresTypeVersion;
}
public override bool CanConvert(Type objectType) => objectType == typeof(List<T>);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var list = new List<T>();
var obj = JObject.Load(reader);
var lookupTable = serializer.Deserialize<List<string>>(obj["lookup_table"].CreateReader());
foreach (var tok in obj["items"])
{
var itemReader = tok.CreateReader();
var typeName = lookupTable[(int)tok["type"]];
var instance = (T)Activator.CreateInstance(Type.GetType(typeName));
serializer.Populate(itemReader, instance);
list.Add(instance);
}
return list;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var list = (List<T>)value;
var lookupTable = new List<string>();
var objects = new List<JObject>();
foreach (var item in list)
{
var type = item.GetType();
var assemblyName = type.Assembly.GetName();
var typeString = $"{type.FullName}, {assemblyName.Name}";
if (requiresTypeVersion)
typeString += $", {assemblyName.Version}";
int typeId = lookupTable.IndexOf(typeString);
if (typeId == -1)
{
lookupTable.Add(typeString);
typeId = lookupTable.Count - 1;
}
var itemObject = JObject.FromObject(item, serializer);
itemObject.AddFirst(new JProperty("type", typeId));
objects.Add(itemObject);
}
writer.WriteStartObject();
writer.WritePropertyName("lookup_table");
serializer.Serialize(writer, lookupTable);
writer.WritePropertyName("items");
serializer.Serialize(writer, objects);
writer.WriteEndObject();
}
}
}

View File

@ -0,0 +1,38 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenTK;
namespace osu.Game.IO.Serialization.Converters
{
/// <summary>
/// A type of <see cref="JsonConverter"/> that serializes only the X and Y coordinates of a <see cref="Vector2"/>.
/// </summary>
public class Vector2Converter : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(Vector2);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var obj = JObject.Load(reader);
return new Vector2((float)obj["x"], (float)obj["y"]);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var vector = (Vector2)value;
writer.WriteStartObject();
writer.WritePropertyName("x");
writer.WriteValue(vector.X);
writer.WritePropertyName("y");
writer.WriteValue(vector.Y);
writer.WriteEndObject();
}
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Game.IO.Serialization.Converters;
namespace osu.Game.IO.Serialization namespace osu.Game.IO.Serialization
{ {
@ -11,20 +12,26 @@ namespace osu.Game.IO.Serialization
public static class JsonSerializableExtensions public static class JsonSerializableExtensions
{ {
public static string Serialize(this IJsonSerializable obj) public static string Serialize(this IJsonSerializable obj) => JsonConvert.SerializeObject(obj, CreateGlobalSettings());
{
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}
public static T Deserialize<T>(this string objString) public static T Deserialize<T>(this string objString) => JsonConvert.DeserializeObject<T>(objString, CreateGlobalSettings());
{
return JsonConvert.DeserializeObject<T>(objString);
}
public static T DeepClone<T>(this T obj) public static void DeserializeInto<T>(this string objString, T target) => JsonConvert.PopulateObject(objString, target, CreateGlobalSettings());
where T : IJsonSerializable
public static T DeepClone<T>(this T obj) where T : IJsonSerializable => Deserialize<T>(Serialize(obj));
/// <summary>
/// Creates the default <see cref="JsonSerializerSettings"/> that should be used for all <see cref="IJsonSerializable"/>s.
/// </summary>
/// <returns></returns>
public static JsonSerializerSettings CreateGlobalSettings() => new JsonSerializerSettings
{ {
return Deserialize<T>(Serialize(obj)); ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
} Formatting = Formatting.Indented,
ObjectCreationHandling = ObjectCreationHandling.Replace,
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
Converters = new JsonConverter[] { new Vector2Converter() },
ContractResolver = new KeyContractResolver()
};
} }
} }

View File

@ -0,0 +1,16 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using Humanizer;
using Newtonsoft.Json.Serialization;
namespace osu.Game.IO.Serialization
{
public class KeyContractResolver : DefaultContractResolver
{
protected override string ResolvePropertyName(string propertyName)
{
return propertyName.Underscore();
}
}
}

View File

@ -86,12 +86,23 @@ namespace osu.Game.Rulesets.Objects.Drawables
{ {
foreach (SampleInfo sample in HitObject.Samples) foreach (SampleInfo sample in HitObject.Samples)
{ {
SampleChannel channel = audio.Sample.Get($@"Gameplay/{sample.Bank}-{sample.Name}"); if (HitObject.SoundControlPoint == null)
throw new ArgumentNullException(nameof(HitObject.SoundControlPoint), $"{nameof(HitObject)} must always have an attached {nameof(HitObject.SoundControlPoint)}.");
var bank = sample.Bank;
if (string.IsNullOrEmpty(bank))
bank = HitObject.SoundControlPoint.SampleBank;
int volume = sample.Volume;
if (volume == 0)
volume = HitObject.SoundControlPoint.SampleVolume;
SampleChannel channel = audio.Sample.Get($@"Gameplay/{bank}-{sample.Name}");
if (channel == null) if (channel == null)
continue; continue;
channel.Volume.Value = sample.Volume; channel.Volume.Value = volume;
Samples.Add(channel); Samples.Add(channel);
} }
} }

View File

@ -1,6 +1,10 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -30,39 +34,47 @@ namespace osu.Game.Rulesets.Objects
/// </summary> /// </summary>
public SampleInfoList Samples = new SampleInfoList(); public SampleInfoList Samples = new SampleInfoList();
[JsonIgnore]
public SoundControlPoint SoundControlPoint;
/// <summary> /// <summary>
/// Whether this <see cref="HitObject"/> is in Kiai time. /// Whether this <see cref="HitObject"/> is in Kiai time.
/// </summary> /// </summary>
[JsonIgnore]
public bool Kiai { get; private set; } public bool Kiai { get; private set; }
private readonly SortedList<HitObject> nestedHitObjects = new SortedList<HitObject>((h1, h2) => h1.StartTime.CompareTo(h2.StartTime));
[JsonIgnore]
public IReadOnlyList<HitObject> NestedHitObjects => nestedHitObjects;
/// <summary> /// <summary>
/// Applies default values to this HitObject. /// Applies default values to this HitObject.
/// </summary> /// </summary>
/// <param name="controlPointInfo">The control points.</param> /// <param name="controlPointInfo">The control points.</param>
/// <param name="difficulty">The difficulty settings to use.</param> /// <param name="difficulty">The difficulty settings to use.</param>
public virtual void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) public void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
ApplyDefaultsToSelf(controlPointInfo, difficulty);
nestedHitObjects.Clear();
CreateNestedHitObjects();
nestedHitObjects.ForEach(h => h.ApplyDefaults(controlPointInfo, difficulty));
}
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
SoundControlPoint soundPoint = controlPointInfo.SoundPointAt(StartTime); SoundControlPoint soundPoint = controlPointInfo.SoundPointAt(StartTime);
EffectControlPoint effectPoint = controlPointInfo.EffectPointAt(StartTime); EffectControlPoint effectPoint = controlPointInfo.EffectPointAt(StartTime);
Kiai |= effectPoint.KiaiMode; Kiai = effectPoint.KiaiMode;
SoundControlPoint = soundPoint;
// Initialize first sample
Samples.ForEach(s => initializeSampleInfo(s, soundPoint));
// Initialize any repeat samples
var repeatData = this as IHasRepeats;
repeatData?.RepeatSamples?.ForEach(r => r.ForEach(s => initializeSampleInfo(s, soundPoint)));
} }
private void initializeSampleInfo(SampleInfo sample, SoundControlPoint soundPoint) protected virtual void CreateNestedHitObjects()
{ {
if (sample.Volume == 0)
sample.Volume = soundPoint?.SampleVolume ?? 0;
// If the bank is not assigned a name, assign it from the control point
if (string.IsNullOrEmpty(sample.Bank))
sample.Bank = soundPoint?.SampleBank ?? @"normal";
} }
protected void AddNested(HitObject hitObject) => nestedHitObjects.Add(hitObject);
} }
} }

View File

@ -46,9 +46,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaults(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);

View File

@ -3,12 +3,14 @@
using System; using System;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
namespace osu.Game.Rulesets namespace osu.Game.Rulesets
{ {
public class RulesetInfo : IEquatable<RulesetInfo> public class RulesetInfo : IEquatable<RulesetInfo>
{ {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonIgnore]
public int? ID { get; set; } public int? ID { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -17,6 +19,7 @@ namespace osu.Game.Rulesets
public string InstantiationInfo { get; set; } public string InstantiationInfo { get; set; }
[JsonIgnore]
public bool Available { get; set; } public bool Available { get; set; }
public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this); public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this);

View File

@ -67,6 +67,8 @@ namespace osu.Game.Screens.Edit
{ {
Items = new[] Items = new[]
{ {
new EditorMenuItem("Export", MenuItemType.Standard, exportBeatmap),
new EditorMenuItemSpacer(),
new EditorMenuItem("Exit", MenuItemType.Standard, Exit) new EditorMenuItem("Exit", MenuItemType.Standard, Exit)
} }
} }
@ -136,6 +138,11 @@ namespace osu.Game.Screens.Edit
bottomBackground.Colour = colours.Gray2; bottomBackground.Colour = colours.Gray2;
} }
private void exportBeatmap()
{
Beatmap.Value.Save();
}
private void onModeChanged(EditorScreenMode mode) private void onModeChanged(EditorScreenMode mode)
{ {
currentScreen?.Exit(); currentScreen?.Exit();

View File

@ -6,6 +6,7 @@ using OpenTK.Graphics;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
namespace osu.Game.Storyboards namespace osu.Game.Storyboards
{ {
@ -23,6 +24,7 @@ namespace osu.Game.Storyboards
public CommandTimeline<bool> FlipH = new CommandTimeline<bool>(); public CommandTimeline<bool> FlipH = new CommandTimeline<bool>();
public CommandTimeline<bool> FlipV = new CommandTimeline<bool>(); public CommandTimeline<bool> FlipV = new CommandTimeline<bool>();
[JsonIgnore]
public IEnumerable<ICommandTimeline> Timelines public IEnumerable<ICommandTimeline> Timelines
{ {
get get
@ -39,14 +41,25 @@ namespace osu.Game.Storyboards
} }
} }
[JsonIgnore]
public double CommandsStartTime => Timelines.Where(t => t.HasCommands).Min(t => t.StartTime); public double CommandsStartTime => Timelines.Where(t => t.HasCommands).Min(t => t.StartTime);
[JsonIgnore]
public double CommandsEndTime => Timelines.Where(t => t.HasCommands).Max(t => t.EndTime); public double CommandsEndTime => Timelines.Where(t => t.HasCommands).Max(t => t.EndTime);
[JsonIgnore]
public double CommandsDuration => CommandsEndTime - CommandsStartTime; public double CommandsDuration => CommandsEndTime - CommandsStartTime;
[JsonIgnore]
public virtual double StartTime => CommandsStartTime; public virtual double StartTime => CommandsStartTime;
[JsonIgnore]
public virtual double EndTime => CommandsEndTime; public virtual double EndTime => CommandsEndTime;
[JsonIgnore]
public double Duration => EndTime - StartTime; public double Duration => EndTime - StartTime;
[JsonIgnore]
public bool HasCommands => Timelines.Any(t => t.HasCommands); public bool HasCommands => Timelines.Any(t => t.HasCommands);
public virtual IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0) public virtual IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)

View File

@ -263,6 +263,7 @@
<Compile Include="Beatmaps\DifficultyCalculator.cs" /> <Compile Include="Beatmaps\DifficultyCalculator.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" /> <Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapSetCover.cs" /> <Compile Include="Beatmaps\Drawables\BeatmapSetCover.cs" />
<Compile Include="Beatmaps\Formats\JsonBeatmapDecoder.cs" />
<Compile Include="Beatmaps\Formats\LegacyDecoder.cs" /> <Compile Include="Beatmaps\Formats\LegacyDecoder.cs" />
<Compile Include="Beatmaps\Formats\LegacyStoryboardDecoder.cs" /> <Compile Include="Beatmaps\Formats\LegacyStoryboardDecoder.cs" />
<Compile Include="Database\DatabaseContextFactory.cs" /> <Compile Include="Database\DatabaseContextFactory.cs" />
@ -271,6 +272,7 @@
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" /> <Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
<Compile Include="Graphics\UserInterface\HoverSounds.cs" /> <Compile Include="Graphics\UserInterface\HoverSounds.cs" />
<Compile Include="Graphics\UserInterface\OsuButton.cs" /> <Compile Include="Graphics\UserInterface\OsuButton.cs" />
<Compile Include="IO\Serialization\KeyContractResolver.cs" />
<Compile Include="Migrations\20171019041408_InitialCreate.cs" /> <Compile Include="Migrations\20171019041408_InitialCreate.cs" />
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs"> <Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
<DependentUpon>20171019041408_InitialCreate.cs</DependentUpon> <DependentUpon>20171019041408_InitialCreate.cs</DependentUpon>
@ -418,6 +420,8 @@
<Compile Include="IO\Legacy\ILegacySerializable.cs" /> <Compile Include="IO\Legacy\ILegacySerializable.cs" />
<Compile Include="IO\Legacy\SerializationReader.cs" /> <Compile Include="IO\Legacy\SerializationReader.cs" />
<Compile Include="IO\Legacy\SerializationWriter.cs" /> <Compile Include="IO\Legacy\SerializationWriter.cs" />
<Compile Include="IO\Serialization\Converters\TypedListConverter.cs" />
<Compile Include="IO\Serialization\Converters\Vector2Converter.cs" />
<Compile Include="IO\Serialization\IJsonSerializable.cs" /> <Compile Include="IO\Serialization\IJsonSerializable.cs" />
<Compile Include="IPC\BeatmapIPCChannel.cs" /> <Compile Include="IPC\BeatmapIPCChannel.cs" />
<Compile Include="IPC\ScoreIPCChannel.cs" /> <Compile Include="IPC\ScoreIPCChannel.cs" />