JD2022-TU1/main/tools/framework/JD.Serialization/Timeline/Clips/TapeReferenceClip.cs

148 lines
No EOL
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace JD.Serialization
{
public partial class TapeReferenceClip
{
[Browsable(true)]
[DisplayName("Tape Id")]
[Description("File name of the tape (.tape)")]
[ReadOnly(true)]
public string TapeId
{
get { return Path.ToString(); }
set
{
Path = new Path(value);
OnPropertyChanged();
}
}
[Browsable(true)]
[Category("Time")]
[DisplayName("Loop Count")]
[Description("The number of time the reference is played.")]
public float LoopCount
{
get
{
var tapeDuration = TapeDuration;
return tapeDuration == 0 ? 1 : Duration / (float)tapeDuration;
}
set
{
var tapeDuration = TapeDuration;
if (tapeDuration != 0)
{
Duration = (int)Math.Round(tapeDuration * value);
}
}
}
private Tape _referredTape;
[Browsable(true)]
public Tape ReferredTape
{
get
{
if (_referredTape == null && Tape != null && Tape.IsOffline)
{
try
{
var serializer = new LuaSerializer();
_referredTape = (Tape)serializer.LoadObjectFromFile(Path.getAbsolute());
}
catch (Exception ex)
{
_referredTape = new Tape
{
Id = Path.getAbsolute(),
LoadingError = ex
};
}
}
return _referredTape;
}
set { _referredTape = value; }
}
public bool IsUnresolved
{
get
{
var tape = ReferredTape;
return tape == null;
}
}
public int TapeDuration
{
get
{
var tape = ReferredTape;
if (tape == null)
{
return 0;
}
var editionContext = tape.EditionContext?.StartFrame ?? 0;
return tape.Clips.Where(clip => clip.IsActive)
.Select(clip => clip.StopFrame)
.DefaultIfEmpty(editionContext).Max() - editionContext;
}
}
public override IEnumerable<CollisionArea> CollisionAreas
{
get
{
var tape = ReferredTape;
if (tape != null)
{
foreach (var clip in tape.Clips)
{
foreach (var loopSection in this.EnumerateLoopSections())
{
if (!loopSection.IsUnusedSpace)
{
foreach (var area in clip.CollisionAreas.OfType<EffectCollisionArea>())
{
area.StartFrame -= area.Clip.ContextualOffset;
area.StopFrame -= area.Clip.ContextualOffset;
if (loopSection.IsReversed)
{
var newStart = loopSection.Length - area.StopFrame;
var newStop = loopSection.Length - area.StartFrame;
area.StartFrame = newStart;
area.StopFrame = newStop;
}
area.StartFrame += loopSection.Start;
area.StopFrame += loopSection.Start;
area.StartFrame = Math.Max(StartFrame, area.StartFrame);
area.StopFrame = Math.Min(StopFrame, area.StopFrame);
area.Clip = this;
yield return area;
}
}
}
}
}
foreach (var area in base.CollisionAreas)
{
yield return area;
}
}
}
}
}