osu/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs

96 lines
3.9 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-05-10 05:56:39 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
2017-05-10 05:56:39 +00:00
using osu.Game.Beatmaps.Timing;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Scoring;
using osu.Game.Rulesets.Objects.Drawables;
2017-05-10 05:56:39 +00:00
using osu.Game.Rulesets.Objects.Types;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Scoring;
2017-05-10 05:56:39 +00:00
using osu.Game.Rulesets.Taiko.Timing;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.UI;
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Mania.UI
{
2017-05-03 03:44:19 +00:00
public class ManiaHitRenderer : HitRenderer<ManiaHitObject, ManiaJudgement>
{
public int? Columns;
public ManiaHitRenderer(WorkingBeatmap beatmap)
: base(beatmap)
{
2017-05-10 05:56:39 +00:00
// Has to be done before drawable hit objects are generated in load()
loadTimingSections();
}
private void loadTimingSections()
{
var maniaPlayfield = Playfield as ManiaPlayfield;
if (maniaPlayfield == null)
return;
var sections = new List<TimingSection>();
// Construct all the relevant timing sections
ControlPoint lastTimingChange = null;
foreach (ControlPoint point in Beatmap.TimingInfo.ControlPoints)
{
if (point.TimingChange)
lastTimingChange = point;
sections.Add(new TimingSection
{
StartTime = point.Time,
// Todo: Should this be dividing by beatlength?
BeatLength = point.SpeedMultiplier * lastTimingChange.BeatLength,
TimeSignature = point.TimeSignature
});
}
double lastObjectTime = (Objects.Last() as IHasEndTime)?.EndTime ?? Objects.Last().StartTime;
// Perform some post processing of the timing sections
sections = sections
// Collapse sections after the last hit object
.Where(s => s.StartTime <= lastObjectTime)
// Collapse sections with the same start time
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime)
// Collapse sections with the same beat length
.GroupBy(s => s.BeatLength).Select(g => g.First())
.ToList();
// Determine duration of timing sections
for (int i = 0; i < sections.Count; i++)
{
if (i < sections.Count - 1)
sections[i].Duration = sections[i + 1].StartTime - sections[i].StartTime;
else
{
// Extra length added for the last timing section to extend past the last hitobject
double extraLength = sections[i].BeatLength * (int)sections[i].TimeSignature;
sections[i].Duration = lastObjectTime + extraLength - sections[i].StartTime;
}
}
sections.ForEach(s => maniaPlayfield.Columns.Children.ForEach(c => c.AddTimingSection(s)));
}
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this);
2017-05-03 03:44:19 +00:00
protected override BeatmapConverter<ManiaHitObject> CreateBeatmapConverter() => new ManiaBeatmapConverter();
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield() => new ManiaPlayfield(Columns ?? (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize));
2017-05-03 03:44:19 +00:00
protected override DrawableHitObject<ManiaHitObject, ManiaJudgement> GetVisualRepresentation(ManiaHitObject h) => null;
}
}