osu/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs

74 lines
3.1 KiB
C#
Raw Normal View History

2017-06-02 09:20:14 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-06-02 08:33:58 +00:00
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.Drawables;
using osu.Game.Rulesets.Objects.Types;
using System.Linq;
using osu.Framework.Lists;
using osu.Game.Beatmaps.ControlPoints;
using osu.Framework.MathUtils;
2017-06-02 08:43:24 +00:00
using osu.Game.Graphics;
2017-06-02 09:19:21 +00:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Timing;
using osu.Game.Rulesets.Timing.Drawables;
2017-06-02 08:33:58 +00:00
namespace osu.Game.Rulesets.Mania.Mods
{
public class ManiaModGravity : Mod, IApplicableMod<ManiaHitObject>
{
public override string Name => "Gravity";
public override double ScoreMultiplier => 0;
2017-06-02 08:43:24 +00:00
public override FontAwesome Icon => FontAwesome.fa_sort_desc;
2017-06-02 08:33:58 +00:00
public void ApplyToHitRenderer(HitRenderer<ManiaHitObject> hitRenderer)
{
var maniaHitRenderer = (ManiaHitRenderer)hitRenderer;
maniaHitRenderer.HitObjectTimingChanges = new List<DrawableTimingChange>[maniaHitRenderer.PreferredColumns];
2017-06-02 08:33:58 +00:00
maniaHitRenderer.BarlineTimingChanges = new List<DrawableTimingChange>();
for (int i = 0; i < maniaHitRenderer.PreferredColumns; i++)
maniaHitRenderer.HitObjectTimingChanges[i] = new List<DrawableTimingChange>();
2017-06-02 09:19:21 +00:00
foreach (HitObject obj in maniaHitRenderer.Objects)
2017-06-02 08:33:58 +00:00
{
2017-06-02 09:19:21 +00:00
var maniaObject = obj as ManiaHitObject;
if (maniaObject == null)
continue;
maniaHitRenderer.HitObjectTimingChanges[maniaObject.Column].Add(new DrawableManiaGravityTimingChange(new TimingChange
2017-06-02 08:33:58 +00:00
{
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;
2017-06-02 09:19:21 +00:00
for (double t = timingPoints[i].Time; Precision.DefinitelyBigger(endTime, t); t += point.BeatLength)
2017-06-02 08:33:58 +00:00
{
maniaHitRenderer.BarlineTimingChanges.Add(new DrawableManiaGravityTimingChange(new TimingChange
2017-06-02 08:33:58 +00:00
{
Time = t,
BeatLength = 1000
}));
}
}
}
}
}