StoryboardSample -> StoryboardSampleInfo

This commit is contained in:
iiSaLMaN 2019-08-23 14:54:39 +03:00
parent d8535574d1
commit 7b04fb1690
3 changed files with 18 additions and 18 deletions

View File

@ -121,7 +121,7 @@ namespace osu.Game.Beatmaps.Formats
var layer = parseLayer(split[2]);
var path = cleanFilename(split[3]);
var volume = split.Length > 4 ? float.Parse(split[4], CultureInfo.InvariantCulture) : 100;
storyboard.GetLayer(layer).Add(new StoryboardSample(path, time, volume));
storyboard.GetLayer(layer).Add(new StoryboardSampleInfo(path, time, (int)volume));
break;
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.IO;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
@ -17,25 +16,24 @@ namespace osu.Game.Storyboards.Drawables
/// </summary>
private const double allowable_late_start = 100;
private readonly StoryboardSample sample;
private readonly StoryboardSampleInfo sampleInfo;
private SampleChannel channel;
public override bool RemoveWhenNotAlive => false;
public DrawableStoryboardSample(StoryboardSample sample)
public DrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
{
this.sample = sample;
LifetimeStart = sample.StartTime;
this.sampleInfo = sampleInfo;
LifetimeStart = sampleInfo.StartTime;
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap)
{
// Try first with the full name, then attempt with no path
channel = beatmap.Value.Skin.GetSample(sample.Path) ?? beatmap.Value.Skin.GetSample(Path.ChangeExtension(sample.Path, null));
channel = beatmap.Value.Skin.GetSample(sampleInfo);
if (channel != null)
channel.Volume.Value = sample.Volume / 100;
channel.Volume.Value = sampleInfo.Volume / 100.0;
}
protected override void Update()
@ -43,27 +41,27 @@ namespace osu.Game.Storyboards.Drawables
base.Update();
// TODO: this logic will need to be consolidated with other game samples like hit sounds.
if (Time.Current < sample.StartTime)
if (Time.Current < sampleInfo.StartTime)
{
// We've rewound before the start time of the sample
channel?.Stop();
// In the case that the user fast-forwards to a point far beyond the start time of the sample,
// we want to be able to fall into the if-conditional below (therefore we must not have a life time end)
LifetimeStart = sample.StartTime;
LifetimeStart = sampleInfo.StartTime;
LifetimeEnd = double.MaxValue;
}
else if (Time.Current - Time.Elapsed < sample.StartTime)
else if (Time.Current - Time.Elapsed < sampleInfo.StartTime)
{
// We've passed the start time of the sample. We only play the sample if we're within an allowable range
// from the sample's start, to reduce layering if we've been fast-forwarded far into the future
if (Time.Current - sample.StartTime < allowable_late_start)
if (Time.Current - sampleInfo.StartTime < allowable_late_start)
channel?.Play();
// In the case that the user rewinds to a point far behind the start time of the sample,
// we want to be able to fall into the if-conditional above (therefore we must not have a life time start)
LifetimeStart = double.MinValue;
LifetimeEnd = sample.StartTime;
LifetimeEnd = sampleInfo.StartTime;
}
}
}

View File

@ -1,21 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Audio;
using osu.Game.Storyboards.Drawables;
namespace osu.Game.Storyboards
{
public class StoryboardSample : IStoryboardElement
public class StoryboardSampleInfo : IStoryboardElement, ISampleInfo
{
public string Path { get; set; }
public string Path { get; }
public bool IsDrawable => true;
public double StartTime { get; }
public float Volume;
public int Volume { get; }
public StoryboardSample(string path, double time, float volume)
public StoryboardSampleInfo(string path, double time, int volume)
{
Path = path;
StartTime = time;