@luceosports/play-rendering 2.5.7 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import _ from 'lodash';
2
2
  import Model from './Base/InternalFrameModel';
3
- import { Line as LineData, LinePart, Player } from '../types';
3
+ import { AnimationMode, Line as LineData, LinePart } from '../types';
4
4
 
5
5
  export type CourtPointAdjusted = { x: number; y: number; time?: number };
6
- export type LineAdjusted = LineData & { animationKeyTimeChunks: [number, number][] };
6
+ export type LineAdjusted = LineData;
7
7
  export type LinePartAdjusted = {
8
8
  controlPoints:
9
9
  | [CourtPointAdjusted, CourtPointAdjusted]
@@ -54,29 +54,6 @@ export default class LineModel extends Model<LineData, LineAdjusted> {
54
54
  }
55
55
  }
56
56
 
57
- setAnimationKeyTimesChunked(linePlayer: Player) {
58
- let keyTimesChunks: [number, number][] = [];
59
- this.animations[0].keyTimes.forEach((value, index) => {
60
- if (index) keyTimesChunks.push([this.animations[0].keyTimes[index - 1], value]);
61
- });
62
-
63
- if (keyTimesChunks.length !== this.getLineParts().length) {
64
- const [[start, end]] = keyTimesChunks;
65
- const [animation] = linePlayer.animations;
66
- const playerAnimStartIndex = animation.keyTimes.indexOf(start);
67
- const playerAnimEndIndex = animation.keyTimes.indexOf(end);
68
- if (playerAnimStartIndex >= 0 && playerAnimEndIndex >= 0) {
69
- const lineKeyTimes = animation.keyTimes.slice(playerAnimStartIndex, playerAnimEndIndex + 1);
70
- keyTimesChunks = [];
71
- lineKeyTimes.forEach((value, index) => {
72
- if (index) keyTimesChunks.push([lineKeyTimes[index - 1], value]);
73
- });
74
- }
75
- }
76
-
77
- this.animationKeyTimeChunks = keyTimesChunks;
78
- }
79
-
80
57
  addLinePartAdjusted(data: LinePartAdjusted) {
81
58
  this.linePartsAdjusted.push(data);
82
59
  }
@@ -132,20 +109,14 @@ export default class LineModel extends Model<LineData, LineAdjusted> {
132
109
  return this._getAttr('animations');
133
110
  }
134
111
 
135
- get animationsByEndTime() {
136
- return this._getAttr('animations').map(a => _.last(a.keyTimes));
137
- }
138
-
139
- get animationKeyTimeChunks() {
140
- return this._getAttr('animationKeyTimeChunks') || [];
141
- }
142
-
143
- set animationKeyTimeChunks(value) {
144
- this._setAttr('animationKeyTimeChunks', value);
112
+ animationsByEndTime(mode: AnimationMode) {
113
+ return this._getAttr('animations').map(a =>
114
+ _.last(mode === AnimationMode.SEQUENTIAL ? a.keyTimesSeq || a.keyTimes : a.keyTimes)
115
+ );
145
116
  }
146
117
 
147
- get lastAnimEndTime() {
148
- return _.max(this.animationsByEndTime);
118
+ lastAnimEndTime(mode: AnimationMode) {
119
+ return _.max(this.animationsByEndTime(mode));
149
120
  }
150
121
 
151
122
  get firstLinePartControlPoint() {
@@ -1,39 +1,41 @@
1
- import { PlayModelOptions } from '../PlayModel';
2
-
3
- export function useDefaults(options?: Partial<PlayModelOptions>): PlayModelOptions {
4
- const defaults = {
5
- width: 300,
6
- lineColor: '#fff', // courtBorderColor
7
- linesDisplay: 'VISIBLE' as const,
8
- linesDisplayOnMoveOnly: true,
9
- linesHiddenIds: [],
10
- linesHighlightedIds: [],
11
- linesSelectedIds: [],
12
- shapeSelectedId: null,
13
- noteSelectedId: null,
14
- playersHiddenPositions: [],
15
- background: '',
16
- watermark: null,
17
- mirror: false,
18
- speed: 1,
19
- position: null,
20
- huddleMode: false,
21
- magnetMode: false,
22
- flipPlayerLabels: false,
23
- legacyPrintStyle: false,
24
- playerTokenScale: 1,
25
- showBallMode: false,
26
- // showBallMode sub-options (defaults match current behavior)
27
- highlightPlayerPuck: true,
28
- showPassLinesDuringPlayback: true,
29
- // TODO: refactor NBA court type constants below
30
- showHalfCourtCircle: true,
31
- playersMap: [],
32
- labelsOverrideType: null,
33
- inDrawingState: false
34
- };
35
- return {
36
- ...defaults,
37
- ...(options || {})
38
- };
39
- }
1
+ import { PlayModelOptions } from '../PlayModel';
2
+ import { AnimationMode } from '../../types';
3
+
4
+ export function useDefaults(options?: Partial<PlayModelOptions>): PlayModelOptions {
5
+ const defaults = {
6
+ width: 300,
7
+ lineColor: '#fff', // courtBorderColor
8
+ linesDisplay: 'VISIBLE' as const,
9
+ linesDisplayOnMoveOnly: true,
10
+ linesHiddenIds: [],
11
+ linesHighlightedIds: [],
12
+ linesSelectedIds: [],
13
+ shapeSelectedId: null,
14
+ noteSelectedId: null,
15
+ playersHiddenPositions: [],
16
+ background: '',
17
+ watermark: null,
18
+ mirror: false,
19
+ speed: 1,
20
+ position: null,
21
+ huddleMode: false,
22
+ magnetMode: false,
23
+ flipPlayerLabels: false,
24
+ legacyPrintStyle: false,
25
+ playerTokenScale: 1,
26
+ animationMode: AnimationMode.PREDICTIVE,
27
+ showBallMode: false,
28
+ // showBallMode sub-options (defaults match current behavior)
29
+ highlightPlayerPuck: true,
30
+ showPassLinesDuringPlayback: true,
31
+ // TODO: refactor NBA court type constants below
32
+ showHalfCourtCircle: true,
33
+ playersMap: [],
34
+ labelsOverrideType: null,
35
+ inDrawingState: false
36
+ };
37
+ return {
38
+ ...defaults,
39
+ ...(options || {})
40
+ };
41
+ }
@@ -17,7 +17,7 @@ import {
17
17
  SPORT_TYPE_VOLLEYBALL
18
18
  } from '../constants';
19
19
 
20
- import { PlayConstructData, PlayData, Position, SportType } from '../types';
20
+ import { AnimationMode, PlayConstructData, PlayData, Position, SportType } from '../types';
21
21
 
22
22
  import hardwoodImageData from '../assets/wood_bg.png';
23
23
  import grassImageData from '../assets/grass_bg.png';
@@ -96,6 +96,7 @@ export type PlayModelOptions = {
96
96
  // sub-options for showBallMode
97
97
  highlightPlayerPuck: boolean;
98
98
  showPassLinesDuringPlayback: boolean;
99
+ animationMode: AnimationMode;
99
100
  };
100
101
 
101
102
  export default class PlayModel {
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash';
2
2
  import Model from './Base/InternalFrameModel';
3
- import { Line, Player as PlayerData } from '../types';
3
+ import { AnimationMode, Line, Player as PlayerData, PlayerAnimation } from '../types';
4
4
 
5
5
  export default class PlayerModel extends Model<PlayerData, PlayerData> {
6
6
  get id() {
@@ -51,12 +51,16 @@ export default class PlayerModel extends Model<PlayerData, PlayerData> {
51
51
  return this._getAttr('animations');
52
52
  }
53
53
 
54
- get animationsByEndTime() {
55
- return this._getAttr('animations').map(a => _.last(a.keyTimes));
54
+ private getAnimationKeyTimes(animation: PlayerAnimation, mode: AnimationMode) {
55
+ return mode === AnimationMode.SEQUENTIAL ? animation.keyTimesSeq || animation.keyTimes : animation.keyTimes;
56
56
  }
57
57
 
58
- get lastAnimEndTime() {
59
- return _.max(this.animationsByEndTime);
58
+ animationsByEndTime(mode: AnimationMode) {
59
+ return this._getAttr('animations').map(a => _.last(this.getAnimationKeyTimes(a, mode)));
60
+ }
61
+
62
+ lastAnimEndTime(mode: AnimationMode) {
63
+ return _.max(this.animationsByEndTime(mode));
60
64
  }
61
65
 
62
66
  get lastAnimation() {
@@ -0,0 +1,4 @@
1
+ export enum AnimationMode {
2
+ PREDICTIVE = 'PREDICTIVE',
3
+ SEQUENTIAL = 'SEQUENTIAL'
4
+ }
@@ -1,3 +1,5 @@
1
+ export { AnimationMode } from './enums';
2
+
1
3
  export type PlayerPosition = `${number}`;
2
4
 
3
5
  export type DefenderPosition = `x${number}`;
@@ -136,6 +138,7 @@ export type PlayerAnimationType = 'POSITION';
136
138
  export interface Animation {
137
139
  id: string;
138
140
  keyTimes: number[];
141
+ keyTimesSeq?: number[];
139
142
  }
140
143
 
141
144
  export interface PlayerAnimation extends Animation {
@@ -155,10 +158,8 @@ export interface Player {
155
158
 
156
159
  export type LineAnimationType = 'LINESTROKE';
157
160
 
158
- export interface LineAnimation {
159
- id: string;
161
+ export interface LineAnimation extends Animation {
160
162
  type: LineAnimationType;
161
- keyTimes: number[];
162
163
  strokeStartValues: [number, number, number];
163
164
  }
164
165