@luceosports/play-rendering 1.11.21 → 1.12.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.
- package/dist/play-rendering.js +3 -3
- package/dist/play-rendering.js.map +1 -1
- package/package.json +1 -1
- package/src/layers/ShapeControlPointLayer.js +2 -2
- package/src/layers/ShapeLayer.js +4 -1
- package/src/layers/line/base/InternalLineLayer.js +28 -146
- package/src/layers/shape/base/InternalShapeLayer.js +5 -1
- package/src/layers/shape/index.js +7 -1
- package/src/layers/shape/layers/line/CutLineShapeLayer.js +13 -0
- package/src/layers/shape/layers/line/DribbleLineShapeLayer.js +71 -0
- package/src/layers/shape/layers/line/ScreenLineShapeLayer.js +13 -0
- package/src/layers/shape/layers/line/base/InternalLineShapeLayer.js +34 -0
- package/src/math/LineDrawingMath.js +96 -0
- package/src/models/Shape.js +13 -0
- package/src/models/ShapeModels/LineShape.js +20 -0
- package/src/models/ShapeModels/index.js +6 -0
- package/src/models/ShapeModels/line/CutLineShape.js +5 -0
- package/src/models/ShapeModels/line/DribbleLineShape.js +5 -0
- package/src/models/ShapeModels/line/ScreenLineShape.js +5 -0
- package/src/traits/LineDrawOperationsTrait.js +123 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
drawLineFromControlPoints() {
|
|
3
|
+
this.ctx.save();
|
|
4
|
+
|
|
5
|
+
this.setLineOptions();
|
|
6
|
+
|
|
7
|
+
this.ctx.lineJoin = 'round';
|
|
8
|
+
|
|
9
|
+
this.getProcessedLinePaths().forEach(linePart => {
|
|
10
|
+
this.ctx.save();
|
|
11
|
+
|
|
12
|
+
if (linePart.alpha) {
|
|
13
|
+
this.setColor(linePart.alpha); // setting color for each line path (animation)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.ctx.beginPath();
|
|
17
|
+
|
|
18
|
+
const cp = linePart.controlPoints;
|
|
19
|
+
this.ctx.moveTo(cp[0].x, cp[0].y);
|
|
20
|
+
|
|
21
|
+
if (cp.length === 2) {
|
|
22
|
+
// TODO refactor next line to avoid access to line/shape model
|
|
23
|
+
if ((this.line || this.shape).type === 'DRIBBLE') this.ctx.lineCap = 'round'; // fix last straight line cap segment
|
|
24
|
+
this.ctx.lineTo(cp[1].x, cp[1].y);
|
|
25
|
+
}
|
|
26
|
+
if (cp.length === 3) {
|
|
27
|
+
this.ctx.quadraticCurveTo(cp[1].x, cp[1].y, cp[2].x, cp[2].y);
|
|
28
|
+
}
|
|
29
|
+
if (cp.length === 4) {
|
|
30
|
+
this.ctx.bezierCurveTo(cp[1].x, cp[1].y, cp[2].x, cp[2].y, cp[3].x, cp[3].y);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.ctx.stroke();
|
|
34
|
+
|
|
35
|
+
this.ctx.restore();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.ctx.restore();
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
drawArrowLineCap() {
|
|
42
|
+
this.ctx.save();
|
|
43
|
+
|
|
44
|
+
const arrowTipLength = 1.4;
|
|
45
|
+
const angle = this.angleBetweenLastTwoPoints();
|
|
46
|
+
const courtArrowTipPoint = this.arrowTipPoint();
|
|
47
|
+
|
|
48
|
+
const courtLineEndPoint = { x: courtArrowTipPoint.x - arrowTipLength / 1.3, y: courtArrowTipPoint.y };
|
|
49
|
+
const courtArrowEdgePoint1 = {
|
|
50
|
+
x: courtArrowTipPoint.x - arrowTipLength - arrowTipLength / 6.0,
|
|
51
|
+
y: courtArrowTipPoint.y - arrowTipLength / 2.0
|
|
52
|
+
};
|
|
53
|
+
const courtArrowEdgePoint2 = {
|
|
54
|
+
x: courtArrowTipPoint.x - arrowTipLength - arrowTipLength / 6.0,
|
|
55
|
+
y: courtArrowTipPoint.y + arrowTipLength / 2.0
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
this.ctx.beginPath();
|
|
59
|
+
|
|
60
|
+
this.ctx.translate(courtArrowTipPoint.x, courtArrowTipPoint.y);
|
|
61
|
+
this.ctx.rotate(angle);
|
|
62
|
+
this.ctx.translate(-courtArrowTipPoint.x, -courtArrowTipPoint.y);
|
|
63
|
+
|
|
64
|
+
this.ctx.moveTo(courtLineEndPoint.x, courtLineEndPoint.y);
|
|
65
|
+
this.ctx.lineTo(courtArrowEdgePoint1.x, courtArrowEdgePoint1.y);
|
|
66
|
+
this.ctx.lineTo(courtArrowTipPoint.x, courtArrowTipPoint.y);
|
|
67
|
+
this.ctx.lineTo(courtArrowEdgePoint2.x, courtArrowEdgePoint2.y);
|
|
68
|
+
this.ctx.lineTo(courtLineEndPoint.x, courtLineEndPoint.y);
|
|
69
|
+
|
|
70
|
+
this.ctx.fill();
|
|
71
|
+
this.ctx.stroke();
|
|
72
|
+
|
|
73
|
+
this.ctx.restore();
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
drawPerpendicularLineCap() {
|
|
77
|
+
this.drawPerpendicularLineAtCourtPoint(this.arrowTipPoint(), this.angleBetweenLastTwoPoints());
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
drawPerpendicularLineAtCourtPoint(courtPoint, angle) {
|
|
81
|
+
this.ctx.save();
|
|
82
|
+
|
|
83
|
+
const lineCapLength = 3.0;
|
|
84
|
+
const lineCapStartPoint = { x: courtPoint.x, y: courtPoint.y - lineCapLength / 2.0 };
|
|
85
|
+
const lineCapEndPoint = { x: courtPoint.x, y: courtPoint.y + lineCapLength / 2.0 };
|
|
86
|
+
|
|
87
|
+
this.ctx.beginPath();
|
|
88
|
+
|
|
89
|
+
this.ctx.translate(courtPoint.x, courtPoint.y);
|
|
90
|
+
this.ctx.rotate(angle);
|
|
91
|
+
this.ctx.translate(-courtPoint.x, -courtPoint.y);
|
|
92
|
+
|
|
93
|
+
this.ctx.moveTo(lineCapStartPoint.x, lineCapStartPoint.y);
|
|
94
|
+
this.ctx.lineTo(lineCapEndPoint.x, lineCapEndPoint.y);
|
|
95
|
+
|
|
96
|
+
this.ctx.fill();
|
|
97
|
+
this.ctx.stroke();
|
|
98
|
+
|
|
99
|
+
this.ctx.restore();
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
angleBetweenLastTwoPoints() {
|
|
103
|
+
const lastLinePart = [...this.getProcessedLinePaths()].pop();
|
|
104
|
+
const cp = lastLinePart.controlPoints;
|
|
105
|
+
|
|
106
|
+
const cpTo = cp[cp.length - 1];
|
|
107
|
+
const cpFrom = cp[cp.length - 2];
|
|
108
|
+
|
|
109
|
+
const dx = cpTo.x - cpFrom.x;
|
|
110
|
+
const dy = cpTo.y - cpFrom.y;
|
|
111
|
+
return Math.atan2(dy, dx);
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
arrowTipPoint() {
|
|
115
|
+
const lastLinePart = [...this.getProcessedLinePaths()].pop();
|
|
116
|
+
const cp = lastLinePart.controlPoints;
|
|
117
|
+
return cp[cp.length - 1];
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
setLineOptions() {
|
|
121
|
+
// Override this method in a subclass
|
|
122
|
+
}
|
|
123
|
+
};
|