mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-05-22 13:56:12 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.Linq;
|
|
using Sandbox.MovieMaker;
|
|
|
|
namespace Editor.MovieMaker;
|
|
|
|
#nullable enable
|
|
|
|
// [MovieModification( "Stretch", Icon = "width_full" )]
|
|
file sealed class StretchModification() : PerTrackModification<StretchOptions>( StretchOptions.Default, true )
|
|
{
|
|
public override void Start( TimeSelection selection )
|
|
{
|
|
Options = Options with { SourceDuration = selection.TotalTimeRange.Duration };
|
|
}
|
|
|
|
protected override ITrackModification<TValue> OnCreateModification<TValue>( IPropertyTrack<TValue> track ) =>
|
|
new StretchTrackModification<TValue>();
|
|
}
|
|
|
|
file sealed record StretchOptions( MovieTime SourceDuration = default ) : IModificationOptions
|
|
{
|
|
public static StretchOptions Default => new();
|
|
}
|
|
|
|
file sealed class StretchTrackModification<T> : ITrackModification<T, StretchOptions>
|
|
{
|
|
public IEnumerable<PropertyBlock<T>> Apply( IReadOnlyList<PropertyBlock<T>> original,
|
|
TimeSelection selection, StretchOptions options )
|
|
{
|
|
return options.SourceDuration > 0 && options.SourceDuration != selection.TotalTimeRange
|
|
? original.Select( x => Stretch( x, selection, options ) )
|
|
: original;
|
|
}
|
|
|
|
private PropertyBlock<T> Stretch( PropertyBlock<T> original, TimeSelection selection, StretchOptions options )
|
|
{
|
|
var signal = original.Signal.SlidingStretch( options.SourceDuration, selection );
|
|
|
|
return new PropertyBlock<T>( signal, original.TimeRange );
|
|
}
|
|
}
|