1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Make Swells play samples while they're being hit

This commit is contained in:
smoogipoo 2017-12-25 15:04:22 +09:00
parent 8529eb1d3a
commit 844e39a9f6
4 changed files with 83 additions and 11 deletions

View File

@ -14,6 +14,7 @@ using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Taiko.Judgements;
using osu.Framework.Audio;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
@ -34,10 +35,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private readonly CircularContainer targetRing;
private readonly CircularContainer expandingRing;
private readonly TaikoAction[] rimActions = { TaikoAction.LeftRim, TaikoAction.RightRim };
private readonly TaikoAction[] centreActions = { TaikoAction.LeftCentre, TaikoAction.RightCentre };
private TaikoAction[] lastAction;
/// <summary>
/// The amount of times the user has hit this swell.
/// </summary>
@ -120,11 +117,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, AudioManager audio)
{
MainPiece.AccentColour = colours.YellowDark;
expandingRing.Colour = colours.YellowLight;
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
foreach (var mapping in HitObject.ProgressionSamples)
mapping.RetrieveChannels(audio);
}
protected override void LoadComplete()
@ -205,22 +205,39 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
}
}
private bool? lastWasCentre;
public override bool OnPressed(TaikoAction action)
{
// Don't handle keys before the swell starts
if (Time.Current < HitObject.StartTime)
return false;
// Find the keyset which this key corresponds to
var keySet = rimActions.Contains(action) ? rimActions : centreActions;
var isCentre = action == TaikoAction.LeftCentre || action == TaikoAction.RightCentre;
// Ensure alternating keysets
if (keySet == lastAction)
// Ensure alternating centre and rim hits
if (lastWasCentre == isCentre)
return false;
lastAction = keySet;
lastWasCentre = isCentre;
UpdateJudgement(true);
if (AllJudged)
return true;
// While the swell hasn't been fully judged, input is still blocked so it doesn't fall through to other hitobjects
// This causes the playfield to not play sounds, so they need to be handled locally
var mappingIndex = HitObject.ProgressionSamples.BinarySearch(new SwellSampleMapping { Time = Time.Current });
if (mappingIndex < 0)
mappingIndex = ~mappingIndex - 1;
var mapping = HitObject.ProgressionSamples[mappingIndex];
if (isCentre)
mapping.CentreChannel.Play();
else
mapping.RimChannel.Play();
return true;
}
}

View File

@ -1,6 +1,11 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Taiko.Objects
@ -15,5 +20,26 @@ namespace osu.Game.Rulesets.Taiko.Objects
/// The number of hits required to complete the swell successfully.
/// </summary>
public int RequiredHits = 10;
public List<SwellSampleMapping> ProgressionSamples = new List<SwellSampleMapping>();
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
var progressionSamplePoints =
new[] { controlPointInfo.SamplePointAt(StartTime) }
.Concat(controlPointInfo.SamplePoints.Where(p => p.Time > StartTime && p.Time <= EndTime));
foreach (var point in progressionSamplePoints)
{
ProgressionSamples.Add(new SwellSampleMapping
{
Time = point.Time,
Centre = point.GetSampleInfo(),
Rim = point.GetSampleInfo(SampleInfo.HIT_CLAP)
});
}
}
}
}
}

View File

@ -0,0 +1,28 @@
// 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 osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Game.Audio;
namespace osu.Game.Rulesets.Taiko.Objects
{
public class SwellSampleMapping : IComparable<SwellSampleMapping>
{
public double Time;
public SampleInfo Centre;
public SampleInfo Rim;
public SampleChannel CentreChannel { get; private set; }
public SampleChannel RimChannel { get; private set; }
public void RetrieveChannels(AudioManager audio)
{
CentreChannel = Centre.GetChannel(audio.Sample);
RimChannel = Rim.GetChannel(audio.Sample);
}
public int CompareTo(SwellSampleMapping other) => Time.CompareTo(other.Time);
}
}

View File

@ -74,6 +74,7 @@
<Compile Include="Objects\Hit.cs" />
<Compile Include="Objects\RimHit.cs" />
<Compile Include="Objects\Swell.cs" />
<Compile Include="Objects\SwellSampleMapping.cs" />
<Compile Include="Replays\TaikoFramedReplayInputHandler.cs" />
<Compile Include="Replays\TaikoAutoGenerator.cs" />
<Compile Include="Objects\TaikoHitObject.cs" />