namespace KKdBaseLib { public interface IKeyFrame { TKey Frame { get; set; } IKeyFrame Check(); IKeyFrame ToKeyFrameT0(); IKeyFrame ToKeyFrameT1(); IKeyFrame ToKeyFrameT2(); IKeyFrame ToKeyFrameT3(); string ToString(); string ToString(bool Brackets); } public struct KeyFrameT0 : IKeyFrame { public TKey Frame { get; set; } public IKeyFrame ToKeyFrameT0() => new KeyFrameT0 { Frame = Frame }; public IKeyFrame ToKeyFrameT1() => new KeyFrameT1 { Frame = Frame }; public IKeyFrame ToKeyFrameT2() => new KeyFrameT2 { Frame = Frame }; public IKeyFrame ToKeyFrameT3() => new KeyFrameT3 { Frame = Frame }; public IKeyFrame Check() => this; public override string ToString() => Extensions.ToString(Frame); public string ToString(bool Brackets) => Extensions.ToString(Frame); } public struct KeyFrameT1 : IKeyFrame { public TKey Frame { get; set; } public TVal Value; public IKeyFrame ToKeyFrameT0() => new KeyFrameT0 { Frame = Frame }; public IKeyFrame ToKeyFrameT1() => new KeyFrameT1 { Frame = Frame, Value = Value }; public IKeyFrame ToKeyFrameT2() => new KeyFrameT2 { Frame = Frame, Value = Value }; public IKeyFrame ToKeyFrameT3() => new KeyFrameT3 { Frame = Frame, Value = Value }; public IKeyFrame Check() => Value.Equals(default(TVal)) ? ToKeyFrameT0() : (this); public override string ToString() => ToString(true); public string ToString(bool Brackets) => (Brackets ? "(" : "") + Extensions.ToString(Frame) + "," + Extensions.ToString(Value) + (Brackets ? ")" : ""); } public struct KeyFrameT2 : IKeyFrame { public TKey Frame { get; set; } public TVal Value; public TVal Interpolation; public IKeyFrame ToKeyFrameT0() => new KeyFrameT0 { Frame = Frame }; public IKeyFrame ToKeyFrameT1() => new KeyFrameT1 { Frame = Frame, Value = Value }; public IKeyFrame ToKeyFrameT2() => new KeyFrameT2 { Frame = Frame, Value = Value, Interpolation = Interpolation}; public IKeyFrame ToKeyFrameT3() => new KeyFrameT3 { Frame = Frame, Value = Value, Interpolation1 = Interpolation, Interpolation2 = Interpolation }; public IKeyFrame ToKeyFrameT3(IKeyFrame Previous) => Previous is KeyFrameT2 PreviousT2 ? new KeyFrameT3 { Frame = Frame, Value = Value, Interpolation1 = PreviousT2.Interpolation, Interpolation2 = Interpolation } : new KeyFrameT3 { Frame = Frame, Value = Value, Interpolation1 = Interpolation, Interpolation2 = Interpolation }; public IKeyFrame Check() { if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal))) return ToKeyFrameT0(); else if ( Interpolation.Equals(default(TVal))) return ToKeyFrameT1(); return this; } public override string ToString() => ToString(true); public string ToString(bool Brackets) => (Brackets ? "(" : "") + Extensions.ToString(Frame) + "," + Extensions. ToString(Value) + "," + Extensions.ToString(Interpolation) + (Brackets ? ")" : ""); } public struct KeyFrameT3 : IKeyFrame { public TKey Frame { get; set; } public TVal Value; public TVal Interpolation1; public TVal Interpolation2; public IKeyFrame ToKeyFrameT0() => new KeyFrameT0 { Frame = Frame }; public IKeyFrame ToKeyFrameT1() => new KeyFrameT1 { Frame = Frame, Value = Value }; public IKeyFrame ToKeyFrameT2() => new KeyFrameT2 { Frame = Frame, Value = Value, Interpolation = Interpolation1 }; public IKeyFrame ToKeyFrameT3() => new KeyFrameT3 { Frame = Frame, Value = Value, Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 }; public IKeyFrame Check() { if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) && Interpolation2.Equals(default(TVal))) return ToKeyFrameT0(); else if (Interpolation1.Equals(default(TVal)) && Interpolation2.Equals(default(TVal))) return ToKeyFrameT1(); else if (Interpolation1.Equals(Interpolation2)) return ToKeyFrameT2(); return this; } public override string ToString() => ToString(true); public string ToString(bool Brackets) => (Brackets ? "(" : "") + Extensions.ToString(Frame) + "," + Extensions.ToString(Value) + "," + Extensions.ToString(Interpolation1) + "," + Extensions.ToString(Interpolation2) + (Brackets ? ")" : ""); public IKeyFrame ToKeyFrameT2(IKeyFrame Previous, out IKeyFrame Current) { Current = Previous is KeyFrameT2 PreviousT2 ? new KeyFrameT2 { Frame = PreviousT2.Frame, Value = PreviousT2.Value, Interpolation = Interpolation1 } : new KeyFrameT2 { Frame = Frame, Value = Value, Interpolation = Interpolation1 }; return new KeyFrameT2 { Frame = Frame, Value = Value, Interpolation = Interpolation2 }; } } }