public TrackCompetitorStoryboard(IActiveTrackRaceViewModel race, IDistanceDisciplineCalculator calculator) { if (race == null) { throw new ArgumentNullException(nameof(race)); } this.race = race; this.calculator = calculator; }
private void OnSkaterChanged(PairsRaceColor color, IActiveTrackRaceViewModel oldRace, IActiveTrackRaceViewModel newRace, Style style) { if (Distance == null || PathProvider == null || canvas == null) { return; } TrackCompetitorStoryboard storyboard; if (storyboards.TryGetValue(color, out storyboard)) { storyboard.DetachAndStop(); storyboards.Remove(color); } Shape shape; if (skaters.TryGetValue(color, out shape)) { canvas.Children.Remove(shape); skaters.Remove(color); } if (oldRace != null) { oldRace.TimeInvalidReasonChanged -= RaceTimeInvalidReasonChanged; } if (newRace == null) { return; } newRace.TimeInvalidReasonChanged += RaceTimeInvalidReasonChanged; if (newRace.TimeInvalidReason != null) { return; } var path = PathProvider.CreatePath(Distance, newRace.Lane); if (path == null) { return; } var ellipse = new EllipseGeometry(path.Figures[0].StartPoint, 2, 2); var ball = new Path { Data = ellipse, Style = style }; Panel.SetZIndex(ball, 4 - newRace.Color); NameScope.SetNameScope(ball, new NameScope()); ball.RegisterName("Ellipse", ellipse); canvas.Children.Add(ball); var animation = new PointAnimationUsingPath { Duration = TimeSpan.FromSeconds(PathProvider.Calculator.Length(Distance)), PathGeometry = path }; Storyboard.SetTargetName(animation, "Ellipse"); Storyboard.SetTargetProperty(animation, new PropertyPath(EllipseGeometry.CenterProperty)); storyboard = new TrackCompetitorStoryboard(newRace, PathProvider.Calculator); storyboard.Children.Add(animation); storyboard.AttachAndBegin(ball); skaters[color] = ball; storyboards[color] = storyboard; }