mirror of
https://github.com/osukey/osukey.git
synced 2025-06-25 05:07:59 +09:00
Make storyboard loops work.
This commit is contained in:
parent
e4a2ad5eb5
commit
e8ab853f6f
@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using osu.Framework.Graphics;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Graphics.Transforms;
|
|
||||||
|
|
||||||
namespace osu.Game.Storyboards
|
namespace osu.Game.Storyboards
|
||||||
{
|
{
|
||||||
@ -20,11 +19,15 @@ namespace osu.Game.Storyboards
|
|||||||
LoopCount = loopCount;
|
LoopCount = loopCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ApplyTransforms(Drawable drawable, double offset = 0)
|
public override IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
|
||||||
=> base.ApplyTransforms(drawable, offset + LoopStartTime);
|
{
|
||||||
|
for (var loop = 0; loop < LoopCount; loop++)
|
||||||
protected override void PostProcess(ICommand command, TransformSequence<Drawable> sequence)
|
{
|
||||||
=> sequence.Loop(CommandsDuration - command.Duration, LoopCount);
|
var loopOffset = LoopStartTime + loop * CommandsDuration;
|
||||||
|
foreach (var command in base.GetCommands(timelineSelector, offset + loopOffset))
|
||||||
|
yield return command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
=> $"{LoopStartTime} x{LoopCount}";
|
=> $"{LoopStartTime} x{LoopCount}";
|
||||||
|
@ -3,14 +3,13 @@
|
|||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Transforms;
|
|
||||||
using osu.Game.Storyboards.Drawables;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Storyboards
|
namespace osu.Game.Storyboards
|
||||||
{
|
{
|
||||||
|
public delegate CommandTimeline<T> CommandTimelineSelector<T>(CommandTimelineGroup commandTimelineGroup);
|
||||||
|
|
||||||
public class CommandTimelineGroup
|
public class CommandTimelineGroup
|
||||||
{
|
{
|
||||||
public CommandTimeline<float> X = new CommandTimeline<float>();
|
public CommandTimeline<float> X = new CommandTimeline<float>();
|
||||||
@ -49,63 +48,20 @@ namespace osu.Game.Storyboards
|
|||||||
|
|
||||||
public bool HasCommands => Timelines.Any(t => t.HasCommands);
|
public bool HasCommands => Timelines.Any(t => t.HasCommands);
|
||||||
|
|
||||||
public virtual void ApplyTransforms(Drawable drawable, double offset = 0)
|
public virtual IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
|
||||||
{
|
{
|
||||||
if (X.HasCommands) drawable.X = X.StartValue;
|
if (offset != 0)
|
||||||
foreach (var command in X.Commands)
|
return timelineSelector(this).Commands.Select(command =>
|
||||||
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
|
new CommandTimeline<T>.TypedCommand
|
||||||
PostProcess(command,
|
{
|
||||||
drawable.MoveToX(command.StartValue)
|
Easing = command.Easing,
|
||||||
.MoveToX(command.EndValue, command.Duration, command.Easing));
|
StartTime = offset + command.StartTime,
|
||||||
|
EndTime = offset + command.EndTime,
|
||||||
|
StartValue = command.StartValue,
|
||||||
|
EndValue = command.EndValue,
|
||||||
|
});
|
||||||
|
|
||||||
if (Y.HasCommands) drawable.Y = Y.StartValue;
|
return timelineSelector(this).Commands;
|
||||||
foreach (var command in Y.Commands)
|
|
||||||
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
|
|
||||||
PostProcess(command,
|
|
||||||
drawable.MoveToY(command.StartValue)
|
|
||||||
.MoveToY(command.EndValue, command.Duration, command.Easing));
|
|
||||||
|
|
||||||
if (Scale.HasCommands) drawable.Scale = Scale.StartValue;
|
|
||||||
foreach (var command in Scale.Commands)
|
|
||||||
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
|
|
||||||
PostProcess(command,
|
|
||||||
drawable.ScaleTo(command.StartValue)
|
|
||||||
.ScaleTo(command.EndValue, command.Duration, command.Easing));
|
|
||||||
|
|
||||||
if (Rotation.HasCommands) drawable.Rotation = Rotation.StartValue;
|
|
||||||
foreach (var command in Rotation.Commands)
|
|
||||||
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
|
|
||||||
PostProcess(command,
|
|
||||||
drawable.RotateTo(command.StartValue)
|
|
||||||
.RotateTo(command.EndValue, command.Duration, command.Easing));
|
|
||||||
|
|
||||||
if (Colour.HasCommands) drawable.Colour = Colour.StartValue;
|
|
||||||
foreach (var command in Colour.Commands)
|
|
||||||
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
|
|
||||||
PostProcess(command,
|
|
||||||
drawable.FadeColour(command.StartValue)
|
|
||||||
.FadeColour(command.EndValue, command.Duration, command.Easing));
|
|
||||||
|
|
||||||
if (Alpha.HasCommands) drawable.Alpha = Alpha.StartValue;
|
|
||||||
foreach (var command in Alpha.Commands)
|
|
||||||
using (drawable.BeginAbsoluteSequence(offset + command.StartTime))
|
|
||||||
PostProcess(command,
|
|
||||||
drawable.FadeTo(command.StartValue)
|
|
||||||
.FadeTo(command.EndValue, command.Duration, command.Easing));
|
|
||||||
|
|
||||||
if (Additive.HasCommands)
|
|
||||||
drawable.BlendingMode = BlendingMode.Additive;
|
|
||||||
|
|
||||||
var flippable = drawable as IFlippable;
|
|
||||||
if (flippable != null)
|
|
||||||
{
|
|
||||||
flippable.FlipH = FlipH.HasCommands;
|
|
||||||
flippable.FlipV = FlipV.HasCommands;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void PostProcess(ICommand command, TransformSequence<Drawable> sequence)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Storyboards.Drawables;
|
using osu.Game.Storyboards.Drawables;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -18,6 +19,9 @@ namespace osu.Game.Storyboards
|
|||||||
private readonly List<CommandLoop> loops = new List<CommandLoop>();
|
private readonly List<CommandLoop> loops = new List<CommandLoop>();
|
||||||
private readonly List<CommandTrigger> triggers = new List<CommandTrigger>();
|
private readonly List<CommandTrigger> triggers = new List<CommandTrigger>();
|
||||||
|
|
||||||
|
private delegate void DrawablePropertyInitializer<T>(Drawable drawable, T value);
|
||||||
|
private delegate void DrawableTransformer<T>(Drawable drawable, T value, double duration, Easing easing);
|
||||||
|
|
||||||
public SpriteDefinition(string path, Anchor origin, Vector2 initialPosition)
|
public SpriteDefinition(string path, Anchor origin, Vector2 initialPosition)
|
||||||
{
|
{
|
||||||
Path = path;
|
Path = path;
|
||||||
@ -42,11 +46,60 @@ namespace osu.Game.Storyboards
|
|||||||
public virtual Drawable CreateDrawable()
|
public virtual Drawable CreateDrawable()
|
||||||
=> new StoryboardSprite(this);
|
=> new StoryboardSprite(this);
|
||||||
|
|
||||||
public override void ApplyTransforms(Drawable target, double offset = 0)
|
public override IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
|
||||||
{
|
{
|
||||||
base.ApplyTransforms(target, offset);
|
var result = base.GetCommands(timelineSelector, offset);
|
||||||
foreach (var loop in loops.OrderBy(l => l.StartTime))
|
foreach (var loop in loops)
|
||||||
loop.ApplyTransforms(target, offset);
|
result = result.Concat(loop.GetCommands(timelineSelector, offset));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyTransforms(Drawable drawable, IEnumerable<Tuple<CommandTimelineGroup, double>> triggeredGroups = null)
|
||||||
|
{
|
||||||
|
applyCommands(drawable, triggeredGroups, g => g.X, (d, value) => d.X = value, (d, value, duration, easing) => d.MoveToX(value, duration, easing));
|
||||||
|
applyCommands(drawable, triggeredGroups, g => g.Y, (d, value) => d.Y = value, (d, value, duration, easing) => d.MoveToY(value, duration, easing));
|
||||||
|
applyCommands(drawable, triggeredGroups, g => g.Scale, (d, value) => d.Scale = value, (d, value, duration, easing) => d.ScaleTo(value, duration, easing));
|
||||||
|
applyCommands(drawable, triggeredGroups, g => g.Rotation, (d, value) => d.Rotation = value, (d, value, duration, easing) => d.RotateTo(value, duration, easing));
|
||||||
|
applyCommands(drawable, triggeredGroups, g => g.Colour, (d, value) => d.Colour = value, (d, value, duration, easing) => d.FadeColour(value, duration, easing));
|
||||||
|
applyCommands(drawable, triggeredGroups, g => g.Alpha, (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing));
|
||||||
|
|
||||||
|
if (getAggregatedCommands(g => g.Additive, triggeredGroups).Any())
|
||||||
|
drawable.BlendingMode = BlendingMode.Additive;
|
||||||
|
|
||||||
|
var flippable = drawable as IFlippable;
|
||||||
|
if (flippable != null)
|
||||||
|
{
|
||||||
|
flippable.FlipH = getAggregatedCommands(g => g.FlipH, triggeredGroups).Any();
|
||||||
|
flippable.FlipV = getAggregatedCommands(g => g.FlipV, triggeredGroups).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCommands<T>(Drawable drawable, IEnumerable<Tuple<CommandTimelineGroup, double>> triggeredGroups,
|
||||||
|
CommandTimelineSelector<T> timelineSelector, DrawablePropertyInitializer<T> initializeProperty, DrawableTransformer<T> transform)
|
||||||
|
{
|
||||||
|
var initialized = false;
|
||||||
|
foreach (var command in getAggregatedCommands(timelineSelector, triggeredGroups))
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
initializeProperty(drawable, command.StartValue);
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
using (drawable.BeginAbsoluteSequence(command.StartTime))
|
||||||
|
{
|
||||||
|
transform(drawable, command.StartValue, 0, Easing.None);
|
||||||
|
transform(drawable, command.EndValue, command.Duration, command.Easing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<CommandTimeline<T>.TypedCommand> getAggregatedCommands<T>(CommandTimelineSelector<T> timelineSelector, IEnumerable<Tuple<CommandTimelineGroup, double>> triggeredGroups)
|
||||||
|
{
|
||||||
|
var commands = GetCommands(timelineSelector);
|
||||||
|
if (triggeredGroups != null)
|
||||||
|
foreach (var pair in triggeredGroups)
|
||||||
|
commands = commands.Concat(pair.Item1.GetCommands(timelineSelector, pair.Item2));
|
||||||
|
return commands.OrderBy(l => l.StartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user