@luceosports/play-rendering 1.18.4 → 1.18.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luceosports/play-rendering",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/play-rendering.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@commitlint/cli": "^13.2.0",
|
|
27
27
|
"@commitlint/config-angular": "^13.2.0",
|
|
28
28
|
"babel-loader": "^8.1.0",
|
|
29
|
-
"canvas": "^2.
|
|
29
|
+
"canvas": "^2.11.2",
|
|
30
30
|
"eslint": "^6.8.0",
|
|
31
31
|
"eslint-config-airbnb-base": "^14.1.0",
|
|
32
32
|
"eslint-config-node": "^4.0.0",
|
|
@@ -3,20 +3,19 @@ const ActionLineLayer = require('../base/ActionLineLayer');
|
|
|
3
3
|
class ShotLineLayer extends ActionLineLayer {
|
|
4
4
|
drawLineCap() {
|
|
5
5
|
if (this.allowDrawLineCap()) {
|
|
6
|
-
const
|
|
7
|
-
const cp2 = this.line.lastLinePartControlPoint;
|
|
6
|
+
const lastPoint = this.line.lastLinePartControlPoint;
|
|
8
7
|
|
|
9
8
|
// Make arrow tip point a bit longer by adding small vector
|
|
10
9
|
const addVector = { x: 0.6, y: 0 };
|
|
11
|
-
const alpha = this.
|
|
10
|
+
const alpha = this.angleBetweenLastTwoPoints();
|
|
12
11
|
const sameAngleAddVector = {
|
|
13
12
|
x: Math.cos(alpha) * addVector.x - Math.sin(alpha) * addVector.y,
|
|
14
13
|
y: Math.sin(alpha) * addVector.x - Math.cos(alpha) * addVector.y
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
const courtArrowTipPoint = {
|
|
18
|
-
x:
|
|
19
|
-
y:
|
|
17
|
+
x: lastPoint.x + sameAngleAddVector.x,
|
|
18
|
+
y: lastPoint.y + sameAngleAddVector.y
|
|
20
19
|
};
|
|
21
20
|
this.drawArrowLineCap(courtArrowTipPoint);
|
|
22
21
|
}
|
|
@@ -24,32 +23,65 @@ class ShotLineLayer extends ActionLineLayer {
|
|
|
24
23
|
|
|
25
24
|
setLineOptions() {
|
|
26
25
|
this.ctx.lineWidth = this.lineWidth * 0.7;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
drawLineFromControlPoints() {
|
|
29
|
+
this.ctx.save();
|
|
30
|
+
|
|
31
|
+
this.setLineOptions();
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
this.ctx.lineJoin = 'round';
|
|
29
34
|
|
|
30
|
-
this.
|
|
35
|
+
this.getProcessedLinePaths().forEach(linePart => {
|
|
36
|
+
this.ctx.save();
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
if (linePart.alpha) {
|
|
39
|
+
this.setColor(linePart.alpha); // setting color for each line path (animation)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.ctx.beginPath();
|
|
43
|
+
|
|
44
|
+
const cp = linePart.controlPoints;
|
|
34
45
|
|
|
35
46
|
const offsets = [-0.3, 0.3];
|
|
36
47
|
offsets.forEach(offset => {
|
|
37
|
-
const [dx, dy] = [cp[0].x - cp[1].x, cp[0].y - cp[1].y];
|
|
48
|
+
const [dx, dy] = [cp[0].x - cp[cp.length - 1].x, cp[0].y - cp[cp.length - 1].y];
|
|
38
49
|
const scale = offset / (dx * dx + dy * dy) ** 0.5;
|
|
39
50
|
const [ox, oy] = [-dy * scale, dx * scale];
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
controlPoints: [
|
|
47
|
-
{ x: cp[0].x + ox, y: cp[0].y + oy },
|
|
48
|
-
{ x: cp[1].x + ox, y: cp[1].y + oy }
|
|
49
|
-
]
|
|
52
|
+
const cpProcessed = cp.map(point => {
|
|
53
|
+
return {
|
|
54
|
+
x: point.x + ox,
|
|
55
|
+
y: point.y + oy
|
|
56
|
+
};
|
|
50
57
|
});
|
|
58
|
+
|
|
59
|
+
this.ctx.moveTo(cpProcessed[0].x, cpProcessed[0].y);
|
|
60
|
+
|
|
61
|
+
if (cp.length === 2) {
|
|
62
|
+
this.ctx.lineTo(cpProcessed[1].x, cpProcessed[1].y);
|
|
63
|
+
}
|
|
64
|
+
if (cp.length === 3) {
|
|
65
|
+
this.ctx.quadraticCurveTo(cpProcessed[1].x, cpProcessed[1].y, cpProcessed[2].x, cpProcessed[2].y);
|
|
66
|
+
}
|
|
67
|
+
if (cp.length === 4) {
|
|
68
|
+
this.ctx.bezierCurveTo(
|
|
69
|
+
cpProcessed[1].x,
|
|
70
|
+
cpProcessed[1].y,
|
|
71
|
+
cpProcessed[2].x,
|
|
72
|
+
cpProcessed[2].y,
|
|
73
|
+
cpProcessed[3].x,
|
|
74
|
+
cpProcessed[3].y
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.ctx.stroke();
|
|
51
79
|
});
|
|
80
|
+
|
|
81
|
+
this.ctx.restore();
|
|
52
82
|
});
|
|
83
|
+
|
|
84
|
+
this.ctx.restore();
|
|
53
85
|
}
|
|
54
86
|
}
|
|
55
87
|
|