@luceosports/play-rendering 2.5.5 → 2.5.6
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.
- package/dist/play-rendering.js +4 -4
- package/dist/play-rendering.js.map +1 -1
- package/dist/types/models/AnimationModel.d.ts +1 -0
- package/dist/types/models/LineModel.d.ts +1 -0
- package/dist/types/models/PlayModel.d.ts +4 -0
- package/package.json +1 -1
- package/src/assets/balls/baseball.svg +2 -0
- package/src/assets/balls/basketball.svg +2 -0
- package/src/assets/balls/football.svg +2 -0
- package/src/assets/balls/hockey.svg +13 -0
- package/src/assets/balls/lacrosse.svg +21 -0
- package/src/assets/balls/soccer.svg +34 -0
- package/src/assets/balls/volleyball.svg +37 -0
- package/src/ballConfig.ts +44 -0
- package/src/helpers/draw.ts +47 -0
- package/src/layers/LineLayer.ts +1 -0
- package/src/layers/PlayerLayer.ts +27 -1
- package/src/layers/line/base/InternalLineLayer.ts +17 -2
- package/src/layers/line/layers/DribbleLineLayer.ts +13 -3
- package/src/layers/line/layers/ShotLineLayer.ts +13 -2
- package/src/models/AnimationModel.ts +19 -0
- package/src/models/FrameModel.ts +15 -3
- package/src/models/LineModel.ts +12 -1
- package/src/models/Play/Options.ts +4 -0
- package/src/models/PlayModel.ts +9 -0
- package/src/traits/LineDrawOperationsTrait.ts +58 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { CourtPoint, LinePart } from '../types';
|
|
1
|
+
import { CourtPoint, LinePart, PlayData } from '../types';
|
|
2
2
|
import LineModel, { LinePartAdjusted } from '../models/LineModel';
|
|
3
3
|
import ShapeModel from '../models/ShapeModel';
|
|
4
|
+
import { FrameDataOptions } from '../models/FrameModel';
|
|
5
|
+
import { drawBallObject } from '../helpers/draw';
|
|
4
6
|
|
|
5
7
|
interface InheritedPropsAndMethods {
|
|
6
8
|
ctx: CanvasRenderingContext2D;
|
|
@@ -8,6 +10,13 @@ interface InheritedPropsAndMethods {
|
|
|
8
10
|
setColor: (alpha?: number) => void;
|
|
9
11
|
line?: LineModel;
|
|
10
12
|
shape?: ShapeModel;
|
|
13
|
+
// below present on layers using this trait (InternalBaseLayer)
|
|
14
|
+
options: FrameDataOptions;
|
|
15
|
+
playData: PlayData;
|
|
16
|
+
courtTypeConstants?: {
|
|
17
|
+
PLAYER_TOKEN_SCALE: number;
|
|
18
|
+
PLAYER_TOKEN_RADIUS: number;
|
|
19
|
+
};
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
interface LineDrawOperationsTrait extends InheritedPropsAndMethods {
|
|
@@ -21,9 +30,44 @@ interface LineDrawOperationsTrait extends InheritedPropsAndMethods {
|
|
|
21
30
|
angleBetweenTwoPoints: (cpFrom: CourtPoint, cpTo: CourtPoint) => number;
|
|
22
31
|
arrowTipPoint: () => CourtPoint;
|
|
23
32
|
setLineOptions: () => void;
|
|
33
|
+
maybeDrawBallAtStartPoint: (params: {
|
|
34
|
+
linePart: Pick<LinePartAdjusted, 'animationSegment'>;
|
|
35
|
+
controlPoints: CourtPoint[];
|
|
36
|
+
alreadyDrawn: boolean;
|
|
37
|
+
}) => boolean;
|
|
24
38
|
}
|
|
25
39
|
|
|
26
40
|
export default {
|
|
41
|
+
maybeDrawBallAtStartPoint(params: {
|
|
42
|
+
linePart: Pick<LinePartAdjusted, 'animationSegment'>;
|
|
43
|
+
controlPoints: CourtPoint[];
|
|
44
|
+
alreadyDrawn: boolean;
|
|
45
|
+
}): boolean {
|
|
46
|
+
const { linePart, controlPoints, alreadyDrawn } = params;
|
|
47
|
+
|
|
48
|
+
if (!this.options?.showBallMode) return alreadyDrawn;
|
|
49
|
+
if (alreadyDrawn) return true;
|
|
50
|
+
if (linePart.animationSegment !== 'active') return false;
|
|
51
|
+
if (!this.line?.isBallTransferLine) return false;
|
|
52
|
+
|
|
53
|
+
const startPoint = controlPoints[0];
|
|
54
|
+
if (!startPoint || !this.courtTypeConstants) return false;
|
|
55
|
+
|
|
56
|
+
const playerScale = this.courtTypeConstants.PLAYER_TOKEN_SCALE * (this.options?.playerTokenScale ?? 1);
|
|
57
|
+
const puckRadiusBase = this.courtTypeConstants.PLAYER_TOKEN_RADIUS * playerScale;
|
|
58
|
+
const radiusMultiplier = this.options?.legacyPrintStyle ? 1.2 : 1;
|
|
59
|
+
const puckRadius = radiusMultiplier * puckRadiusBase;
|
|
60
|
+
|
|
61
|
+
return drawBallObject({
|
|
62
|
+
sport: this.playData.sport,
|
|
63
|
+
ctx: this.ctx,
|
|
64
|
+
staticData: this.options?.staticData,
|
|
65
|
+
center: { x: startPoint.x, y: startPoint.y },
|
|
66
|
+
puckRadius,
|
|
67
|
+
placement: 'center'
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
|
|
27
71
|
drawLineFromControlPoints() {
|
|
28
72
|
this.ctx.save();
|
|
29
73
|
|
|
@@ -31,11 +75,13 @@ export default {
|
|
|
31
75
|
|
|
32
76
|
this.ctx.lineJoin = 'round';
|
|
33
77
|
|
|
78
|
+
let isBallDrawn = false;
|
|
79
|
+
|
|
34
80
|
this.getProcessedLinePaths().forEach(linePart => {
|
|
35
81
|
this.ctx.save();
|
|
36
82
|
|
|
37
|
-
if (linePart.
|
|
38
|
-
this.setColor(
|
|
83
|
+
if (linePart.animationSegment === 'processed') {
|
|
84
|
+
this.setColor(0.1); // processed segment (before animation progress)
|
|
39
85
|
}
|
|
40
86
|
|
|
41
87
|
this.ctx.beginPath();
|
|
@@ -57,6 +103,15 @@ export default {
|
|
|
57
103
|
|
|
58
104
|
this.ctx.stroke();
|
|
59
105
|
|
|
106
|
+
// Draw the ball AFTER the stroke so it overlaps the line.
|
|
107
|
+
if (!isBallDrawn) {
|
|
108
|
+
isBallDrawn = this.maybeDrawBallAtStartPoint({
|
|
109
|
+
linePart,
|
|
110
|
+
controlPoints: cp,
|
|
111
|
+
alreadyDrawn: isBallDrawn
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
60
115
|
this.ctx.restore();
|
|
61
116
|
});
|
|
62
117
|
|