1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 02:32:59 +08:00

Add gravity mod.

This commit is contained in:
smoogipooo 2017-06-02 17:33:58 +09:00
parent 8f6118ffb8
commit b46a9dd0ef
5 changed files with 110 additions and 6 deletions

View File

@ -89,6 +89,7 @@ namespace osu.Game.Rulesets.Mania
new ModCinema(),
},
},
new ManiaModGravity()
};
default:

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.Mania.Timing;
using osu.Game.Rulesets.Mania.Timing.Drawables;
using osu.Game.Rulesets.Objects.Types;
using System.Linq;
using osu.Framework.Lists;
using osu.Game.Beatmaps.ControlPoints;
using osu.Framework.MathUtils;
namespace osu.Game.Rulesets.Mania.Mods
{
public class ManiaModGravity : Mod, IApplicableMod<ManiaHitObject>
{
public override string Name => "Gravity";
public override double ScoreMultiplier => 0;
public void ApplyToHitRenderer(HitRenderer<ManiaHitObject> hitRenderer)
{
var maniaHitRenderer = (ManiaHitRenderer)hitRenderer;
maniaHitRenderer.HitObjectTimingChanges = new Dictionary<int, List<DrawableTimingChange>>();
maniaHitRenderer.BarlineTimingChanges = new List<DrawableTimingChange>();
foreach (ManiaHitObject obj in maniaHitRenderer.Objects)
{
List<DrawableTimingChange> timingChanges;
if (!maniaHitRenderer.HitObjectTimingChanges.TryGetValue(obj.Column, out timingChanges))
maniaHitRenderer.HitObjectTimingChanges[obj.Column] = timingChanges = new List<DrawableTimingChange>();
timingChanges.Add(new DrawableGravityTimingChange(new TimingChange
{
Time = obj.StartTime,
BeatLength = 1000
}));
}
double lastObjectTime = (maniaHitRenderer.Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? maniaHitRenderer.Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
SortedList<TimingControlPoint> timingPoints = maniaHitRenderer.Beatmap.ControlPointInfo.TimingPoints;
for (int i = 0; i < timingPoints.Count; i++)
{
TimingControlPoint point = timingPoints[i];
// Stop on the beat before the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time - point.BeatLength : lastObjectTime + point.BeatLength * (int)point.TimeSignature;
int index = 0;
for (double t = timingPoints[i].Time; Precision.DefinitelyBigger(endTime, t); t += point.BeatLength, index++)
{
maniaHitRenderer.BarlineTimingChanges.Add(new DrawableGravityTimingChange(new TimingChange
{
Time = t,
BeatLength = 1000
}));
}
}
}
}
}

View File

@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Mania.Timing
/// </summary>
/// <param name="hitObject">The hit object to contain.</param>
/// <returns>The last timing change which can contain <paramref name="hitObject"/>. Null if no timing change can contain the hit object.</returns>
private DrawableTimingChange timingChangeFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject));
private DrawableTimingChange timingChangeFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)) ?? Children.LastOrDefault();
}
/// <summary>

View File

@ -31,15 +31,26 @@ namespace osu.Game.Rulesets.Mania.UI
{
public class ManiaHitRenderer : HitRenderer<ManiaHitObject, ManiaJudgement>
{
public int? Columns;
private int? columns;
public int Columns => columns ?? (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize);
public Dictionary<int, List<DrawableTimingChange>> HitObjectTimingChanges;
public List<DrawableTimingChange> BarlineTimingChanges;
public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset)
{
generateTimingChanges();
}
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield()
private void generateTimingChanges()
{
if (HitObjectTimingChanges != null || BarlineTimingChanges != null)
return;
HitObjectTimingChanges = new Dictionary<int, List<DrawableTimingChange>>();
BarlineTimingChanges = new List<DrawableTimingChange>();
double lastSpeedMultiplier = 1;
double lastBeatLength = 500;
@ -80,7 +91,24 @@ namespace osu.Game.Rulesets.Mania.UI
.GroupBy(s => s.BeatLength * s.SpeedMultiplier).Select(g => g.First())
.ToList();
var playfield = new ManiaPlayfield(Columns ?? (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize))
timingChanges.ForEach(t =>
{
for (int i = 0; i < Columns; i++)
{
List<DrawableTimingChange> columnTimingChanges;
if (!HitObjectTimingChanges.TryGetValue(i, out columnTimingChanges))
HitObjectTimingChanges[i] = columnTimingChanges = new List<DrawableTimingChange>();
columnTimingChanges.Add(new DrawableScrollingTimingChange(t));
}
BarlineTimingChanges.Add(new DrawableScrollingTimingChange(t));
});
}
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield()
{
var playfield = new ManiaPlayfield(Columns)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -88,8 +116,17 @@ namespace osu.Game.Rulesets.Mania.UI
Scale = new Vector2(1, -1)
};
timingChanges.ForEach(t => playfield.Columns.ForEach(c => c.Add(new DrawableScrollingTimingChange(t))));
timingChanges.ForEach(t => playfield.Add(new DrawableScrollingTimingChange(t)));
foreach (var kvp in HitObjectTimingChanges)
{
int column = kvp.Key;
List<DrawableTimingChange> timingChanges = kvp.Value;
foreach (var change in timingChanges)
playfield.Columns.ElementAt(column).Add(change);
}
foreach (var change in BarlineTimingChanges)
playfield.Add(change);
return playfield;
}

View File

@ -82,6 +82,7 @@
<Compile Include="UI\ManiaPlayfield.cs" />
<Compile Include="ManiaRuleset.cs" />
<Compile Include="Mods\ManiaMod.cs" />
<Compile Include="Mods\ManiaModGravity.cs" />
<Compile Include="UI\SpecialColumnPosition.cs" />
<Compile Include="Timing\Drawables\DrawableGravityTimingChange.cs" />
<Compile Include="Timing\Drawables\DrawableScrollingTimingChange.cs" />