1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Code cleanup

This commit is contained in:
Henry Lin 2021-06-14 21:34:34 +08:00
parent 12a17d0983
commit 04c0db6dce
3 changed files with 105 additions and 115 deletions

View File

@ -61,7 +61,7 @@ namespace osu.Game.Rulesets.Osu.Mods
}
// Maximum distance to jump
public const float MAX_DISTANCE = 250f;
private const float max_distance = 250f;
public override void ApplyToBeatmap(IBeatmap beatmap)
{
@ -69,30 +69,20 @@ namespace osu.Game.Rulesets.Osu.Mods
var rng = new Random(Seed.Value.GetValueOrDefault());
float nextSingle(float max = 1f)
{
return (float)(rng.NextDouble() * max);
}
float nextSingle(float max = 1f) => (float)(rng.NextDouble() * max);
var osuBeatmap = (OsuBeatmap)beatmap;
var origHitObjects = osuBeatmap.HitObjects.OrderBy(x => x.StartTime).ToList();
// Only place circles between startTime and endTime
var startTime = origHitObjects.First().StartTime;
double endTime;
var endObj = origHitObjects.Last();
switch (endObj)
var endTime = endObj switch
{
case Slider slider:
endTime = slider.EndTime;
break;
case Spinner spinner:
endTime = spinner.EndTime;
break;
default:
endTime = endObj.StartTime;
break;
}
Slider slider => slider.EndTime,
Spinner spinner => spinner.EndTime,
_ => endObj.StartTime
};
// Generate the beats
var beats = osuBeatmap.ControlPointInfo.TimingPoints
@ -101,11 +91,13 @@ namespace osu.Game.Rulesets.Osu.Mods
{
var tpBeats = new List<double>();
var currentTime = tp.Time;
while (Precision.AlmostBigger(endTime, currentTime) && osuBeatmap.ControlPointInfo.TimingPointAt(currentTime) == tp)
{
tpBeats.Add(currentTime);
currentTime += tp.BeatLength;
}
return tpBeats;
})
// Remove beats that are before startTime
@ -122,9 +114,8 @@ namespace osu.Game.Rulesets.Osu.Mods
.Where((x, idx) =>
{
if (idx == beats.Count - 1) return true;
if (Precision.AlmostBigger(osuBeatmap.ControlPointInfo.TimingPointAt(x).BeatLength / 2, beats[idx + 1] - x))
return false;
return true;
return !Precision.AlmostBigger(osuBeatmap.ControlPointInfo.TimingPointAt(x).BeatLength / 2, beats[idx + 1] - x);
})
.Select(x =>
{
@ -139,6 +130,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{
var x = hitObjects[i];
var samples = getSamplesAtTime(origHitObjects, x.StartTime);
if (samples == null)
{
if (i > 0)
@ -155,11 +147,11 @@ namespace osu.Game.Rulesets.Osu.Mods
hitObjects.ForEach(x =>
{
var origObj = origHitObjects.FindLast(y => Precision.AlmostBigger(x.StartTime, y.StartTime));
if (origObj == null) x.ComboIndex = 0;
else x.ComboIndex = origObj.ComboIndex;
x.ComboIndex = origObj?.ComboIndex ?? 0;
});
// Then reprocess them to ensure continuity in the combo indices and add indices in current combo
var combos = hitObjects.GroupBy(x => x.ComboIndex).ToList();
for (int i = 0; i < combos.Count; i++)
{
var group = combos[i].ToList();
@ -176,16 +168,18 @@ namespace osu.Game.Rulesets.Osu.Mods
// Position all hit circles
var direction = MathHelper.TwoPi * nextSingle();
for (int i = 0; i < hitObjects.Count; i++)
{
var x = hitObjects[i];
if (i == 0)
{
x.Position = new Vector2(nextSingle(OsuPlayfield.BASE_SIZE.X), nextSingle(OsuPlayfield.BASE_SIZE.Y));
}
else
{
var distance = Math.Min(MAX_DISTANCE, 40f * (float)Math.Pow(1.05, x.ComboIndex));
var distance = Math.Min(max_distance, 40f * (float)Math.Pow(1.05, x.ComboIndex));
var relativePos = new Vector2(
distance * (float)Math.Cos(direction),
distance * (float)Math.Sin(direction)
@ -209,7 +203,7 @@ namespace osu.Game.Rulesets.Osu.Mods
if (x.LastInCombo)
direction = MathHelper.TwoPi * nextSingle();
else
direction += distance / MAX_DISTANCE * (nextSingle() * MathHelper.TwoPi - MathHelper.Pi);
direction += distance / max_distance * (nextSingle() * MathHelper.TwoPi - MathHelper.Pi);
}
}
@ -227,25 +221,24 @@ namespace osu.Game.Rulesets.Osu.Mods
/// <param name="hitObjects">The list of hit objects in a beatmap, ordered by StartTime</param>
/// <param name="time">The point in time to get samples for</param>
/// <returns>Hit samples</returns>
private IList<HitSampleInfo> getSamplesAtTime(List<OsuHitObject> hitObjects, double time)
private IList<HitSampleInfo> getSamplesAtTime(IEnumerable<OsuHitObject> hitObjects, double time)
{
var sampleObj = hitObjects.FirstOrDefault(x =>
{
if (Precision.AlmostEquals(time, x.StartTime)) return true;
if (x is Slider slider
&& Precision.AlmostBigger(time, slider.StartTime)
&& Precision.AlmostBigger(slider.EndTime, time))
{
if (Precision.AlmostEquals((time - slider.StartTime) % slider.SpanDuration, 0))
{
return true;
}
}
if (!(x is Slider s))
return false;
if (!Precision.AlmostBigger(time, s.StartTime)
|| !Precision.AlmostBigger(s.EndTime, time))
return false;
return Precision.AlmostEquals((time - s.StartTime) % s.SpanDuration, 0);
});
if (sampleObj == null) return null;
IList<HitSampleInfo> samples = null;
IList<HitSampleInfo> samples;
if (sampleObj is Slider slider)
{
samples = slider.NodeSamples[(int)Math.Round((time - slider.StartTime) % slider.SpanDuration)];
@ -254,6 +247,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{
samples = sampleObj.Samples;
}
return samples;
}
@ -269,8 +263,8 @@ namespace osu.Game.Rulesets.Osu.Mods
var h = (OsuHitObject)drawable.HitObject;
// apply grow and fade effect
if (drawable is DrawableHitCircle circle)
{
if (!(drawable is DrawableHitCircle circle)) return;
using (drawable.BeginAbsoluteSequence(h.StartTime - h.TimePreempt))
{
// todo: this doesn't feel quite right yet
@ -283,7 +277,6 @@ namespace osu.Game.Rulesets.Osu.Mods
circle.ApproachCircle.Hide();
}
}
}
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
{
@ -347,7 +340,7 @@ namespace osu.Game.Rulesets.Osu.Mods
}
/// <summary>
/// Rotates vector "initial" towards vector "destinantion"
/// Rotates vector "initial" towards vector "destination"
/// </summary>
/// <param name="initial">Vector to rotate to "destination"</param>
/// <param name="destination">Vector "initial" should be rotated to</param>
@ -399,7 +392,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{
InternalChildren = new Drawable[]
{
sample = new PausableSkinnableSound(new SampleInfo("spinnerbonus")), // todo: use another sample?
sample = new PausableSkinnableSound(new SampleInfo("spinnerbonus")) // todo: use another sample?
};
}

View File

@ -5,7 +5,6 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
@ -18,11 +17,14 @@ namespace osu.Game.Rulesets.Mods
public class SeedSettingsControl : SettingsItem<int?>
{
protected override Drawable CreateControl() => new SeedControl
protected override Drawable CreateControl()
{
return new SeedControl
{
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding { Top = 5 }
};
}
private sealed class SeedControl : CompositeDrawable, IHasCurrentValue<int?>
{

View File

@ -2,14 +2,9 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
namespace osu.Game.Rulesets.Mods
{