269 lines
8.9 KiB
C#
269 lines
8.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using JD.Core;
|
|
using JD.Core.Collections;
|
|
using JD.Core.Helpers;
|
|
using JD.Interfaces.Editors;
|
|
|
|
namespace JD.Serialization
|
|
{
|
|
partial class MotionClip
|
|
{
|
|
#region Variables
|
|
|
|
private MoveModel _model;
|
|
|
|
#endregion
|
|
|
|
#region constructor
|
|
|
|
public MotionClip()
|
|
{
|
|
_motionPlatformSpecifics.ItemChanged += MotionPlatformSpecifics_ItemChanged;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
[Browsable(true)]
|
|
[Category("Move")]
|
|
[PropertyEditor("MoveModelEditor")]
|
|
public MoveModel Model
|
|
{
|
|
get { return _model; }
|
|
set
|
|
{
|
|
if (_model != value)
|
|
{
|
|
if (_model != null)
|
|
_model.PropertyChanged -= model_propertyChanged;
|
|
_model = value;
|
|
_model.PropertyChanged += model_propertyChanged;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public MotionClip MasterClip
|
|
{
|
|
get
|
|
{
|
|
if (Tape != null)
|
|
{
|
|
for (var i = (int)CoachId_Enum.COACH_0; i < (int)CoachId; i++)
|
|
{
|
|
var masterClip = Tape.Clips.OfType<MotionClip>().FirstOrDefault(x =>
|
|
(int) x.CoachId == i &&
|
|
x.StartBeat.AlmostEquals(StartBeat) &&
|
|
x.BeatDuration.AlmostEquals(BeatDuration) &&
|
|
x.Model == Model);
|
|
|
|
if (masterClip != null)
|
|
return masterClip;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private void RefreshModel()
|
|
{
|
|
if (Tape != null && ClassifierPath != null)
|
|
{
|
|
var duration = Duration;
|
|
Model = Tape.GetOrCreateMoveModel(ClassifierPath);
|
|
Duration = duration;
|
|
}
|
|
}
|
|
|
|
protected override void OnPropertyChanged([CallerMemberName]string propertyName = "")
|
|
{
|
|
base.OnPropertyChanged(propertyName);
|
|
|
|
if (propertyName == nameof(Tape) || propertyName == nameof(ClassifierPath))
|
|
{
|
|
RefreshModel();
|
|
}
|
|
|
|
if (Model != null)
|
|
{
|
|
switch (propertyName)
|
|
{
|
|
case nameof(Duration):
|
|
Model.BeatDuration = BeatDuration;
|
|
break;
|
|
case nameof(Color):
|
|
Model.Color = Color;
|
|
break;
|
|
case nameof(MoveType):
|
|
Model.MoveType = MoveType;
|
|
break;
|
|
case nameof(Model):
|
|
BeatDuration = Model.BeatDuration;
|
|
Color = Model.Color;
|
|
MoveType = Model.MoveType;
|
|
ClassifierPath = Model.ClassifierPath;
|
|
MotionPlatformSpecifics.GetOrCreate(Platform.X360).CopyFrom(Model.Camera_Xbox360);
|
|
MotionPlatformSpecifics.GetOrCreate(Platform.DURANGO).CopyFrom(Model.Camera_XboxOne);
|
|
MotionPlatformSpecifics.GetOrCreate(Platform.ORBIS).CopyFrom(Model.Camera_PS4);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void model_propertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
switch (e.PropertyName)
|
|
{
|
|
case "BeatDuration":
|
|
BeatDuration = Model.BeatDuration;
|
|
break;
|
|
case "Color":
|
|
Color = Model.Color;
|
|
break;
|
|
case "MoveType":
|
|
MoveType = Model.MoveType;
|
|
break;
|
|
case "ClassifierPath":
|
|
ClassifierPath = Model.ClassifierPath;
|
|
break;
|
|
case "Camera_Xbox360":
|
|
MotionPlatformSpecifics.GetOrCreate(Platform.X360).CopyFrom(Model.Camera_Xbox360);
|
|
OnPropertyChanged(nameof(Model));
|
|
break;
|
|
case "Camera_XboxOne":
|
|
MotionPlatformSpecifics.GetOrCreate(Platform.DURANGO).CopyFrom(Model.Camera_XboxOne);
|
|
OnPropertyChanged(nameof(Model));
|
|
break;
|
|
case "Camera_PS4":
|
|
MotionPlatformSpecifics.GetOrCreate(Platform.ORBIS).CopyFrom(Model.Camera_PS4);
|
|
OnPropertyChanged(nameof(Model));
|
|
break;
|
|
default:
|
|
OnPropertyChanged(e.PropertyName);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void MotionPlatformSpecifics_ItemChanged(object sender, ItemChangedEventArgs<KeyValuePair<Platform, MotionPlatformSpecific>> args)
|
|
{
|
|
var platform = args.Item.Key;
|
|
if (platform == null)
|
|
return;
|
|
|
|
if (Model == null)
|
|
return;
|
|
|
|
if (platform.Equals(Platform.X360))
|
|
{
|
|
Model.Camera_Xbox360.CopyFrom(MotionPlatformSpecifics[platform]);
|
|
}
|
|
else if (platform.Equals(Platform.DURANGO))
|
|
{
|
|
Model.Camera_XboxOne.CopyFrom(MotionPlatformSpecifics[platform]);
|
|
}
|
|
else if (platform.Equals(Platform.ORBIS))
|
|
{
|
|
Model.Camera_PS4.CopyFrom(MotionPlatformSpecifics[platform]);
|
|
}
|
|
OnPropertyChanged(nameof(MotionPlatformSpecifics));
|
|
}
|
|
|
|
public override Clip ConvertToFit(TapeTrack track)
|
|
{
|
|
var clip = base.ConvertToFit(track);
|
|
if (track is PictoTrack)
|
|
{
|
|
var picto = (PictogramClip)clip;
|
|
picto.Model = Tape.GetOrCreatePictogramModel(Model.Name);
|
|
}
|
|
else if (track is MoveTrack)
|
|
{
|
|
var moveTrack = (MoveTrack)track;
|
|
var motionClip = (MotionClip)clip;
|
|
motionClip.CoachId = moveTrack.CoachId;
|
|
if (moveTrack.MoveType != motionClip.MoveType)
|
|
{
|
|
bool newModelCreated;
|
|
var moveModel = track.Tape.GetOrCreateMoveModel(motionClip.Model.Name, moveTrack.MoveType, out newModelCreated);
|
|
if (newModelCreated)
|
|
{
|
|
moveModel.BeatDuration = motionClip.Model.BeatDuration;
|
|
moveModel.Color = motionClip.Model.Color;
|
|
}
|
|
motionClip.Model = moveModel;
|
|
}
|
|
}
|
|
return clip;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region MotionPlatformSpecific
|
|
|
|
partial class MotionPlatformSpecific
|
|
{
|
|
public override string ToString()
|
|
{
|
|
return $"[ {_scoreScale} ; {_scoreSmoothing} ] [ {_lowThreshold} --> {_highThreshold} ]";
|
|
}
|
|
|
|
public void CopyFrom(MotionPlatformSpecific other)
|
|
{
|
|
if (other != null)
|
|
{
|
|
_scoreScale = other.ScoreScale;
|
|
_scoreSmoothing = other.ScoreSmoothing;
|
|
_lowThreshold = other.LowThreshold;
|
|
_highThreshold = other.HighThreshold;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public static class MotionClipExtensions
|
|
{
|
|
public delegate void TweakParametersChangedDelegate(MotionClip clip);
|
|
public static TweakParametersChangedDelegate TweakParametersChanged;
|
|
|
|
public static MotionClip InstantiateMotionClip(this TapeTrack track, string modelName, int startFrame)
|
|
{
|
|
if (string.IsNullOrEmpty(modelName))
|
|
return null;
|
|
|
|
var moveTrack = track as MoveTrack;
|
|
if (moveTrack == null)
|
|
{
|
|
throw new ArgumentException("The track should be of type MoveTrack");
|
|
}
|
|
var newClip = (MotionClip)Clip.Instantiate(typeof(MotionClip), moveTrack, startFrame);
|
|
newClip.CoachId = moveTrack.CoachId;
|
|
newClip.Model = moveTrack.Tape.GetOrCreateMoveModel(modelName, moveTrack.MoveType);
|
|
return newClip;
|
|
}
|
|
|
|
public static void MotionPlatformSpecificsChanged(this MotionClip clip, object sender, PropertyChangedEventArgs e)
|
|
{
|
|
if (e.PropertyName == "ScoreScale" || e.PropertyName == "ScoreSmoothing" || e.PropertyName == "LowThreshold" || e.PropertyName == "HighThreshold")
|
|
{
|
|
TweakParametersChanged?.Invoke(clip);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|