@luceosports/play-rendering 1.12.1 → 1.12.2
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/line/layers/DribbleLineLayer.js +15 -54
- package/src/layers/shape/layers/line/DribbleLineShapeLayer.js +6 -57
- package/src/layers/shape/layers/line/PassLineShapeLayer.js +17 -0
- package/src/models/ShapeModels/line/PassLineShape.js +5 -0
- package/src/traits/DribbleLineTrait.js +57 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const common = require('../../../helpers/common');
|
|
3
3
|
const ActionLineLayer = require('../base/ActionLineLayer');
|
|
4
|
-
const
|
|
4
|
+
const DribbleLineTrait = require('../../../traits/DribbleLineTrait');
|
|
5
5
|
|
|
6
6
|
class DribbleLineLayer extends ActionLineLayer {
|
|
7
7
|
drawLineCap() {
|
|
@@ -10,64 +10,25 @@ class DribbleLineLayer extends ActionLineLayer {
|
|
|
10
10
|
|
|
11
11
|
setLineOptions() {
|
|
12
12
|
const lineParts = [...this.line.getLineParts()];
|
|
13
|
+
const dribbleLineParts = this.convertLinePartsToDribble(lineParts);
|
|
13
14
|
this.line.setLinePartsAdjusted([]);
|
|
14
|
-
|
|
15
|
-
const controlPoints =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const step = 1 / bez.length;
|
|
24
|
-
while (index <= 1) {
|
|
25
|
-
bezVector.push({ x: bez.mx(index), y: bez.my(index), time: index }); // setting time for animation alpha processing
|
|
26
|
-
index += step;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const bezPathsArr = [];
|
|
30
|
-
let tempPath = [];
|
|
31
|
-
for (let i = 0; i < bezVector.length; i++) {
|
|
32
|
-
tempPath.push(bezVector[i]);
|
|
33
|
-
if (tempPath.length > 1) {
|
|
34
|
-
bezPathsArr.push(tempPath);
|
|
35
|
-
tempPath = [bezVector[i]];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const amplitudeCf = 1.2;
|
|
40
|
-
bezPathsArr.forEach(([firstPoint, lastPoint], ind) => {
|
|
41
|
-
const vector = { x: (lastPoint.x - firstPoint.x) * amplitudeCf, y: (lastPoint.y - firstPoint.y) * amplitudeCf };
|
|
42
|
-
|
|
43
|
-
const vectorMidPoint = { x: (firstPoint.x + lastPoint.x) / 2, y: (firstPoint.y + lastPoint.y) / 2 };
|
|
44
|
-
|
|
45
|
-
let perpVector = { x: -vector.y, y: vector.x };
|
|
46
|
-
if (ind % 2) {
|
|
47
|
-
perpVector = { x: vector.y, y: -vector.x };
|
|
48
|
-
}
|
|
49
|
-
const midPoint = { x: vectorMidPoint.x + perpVector.x, y: vectorMidPoint.y + perpVector.y };
|
|
50
|
-
|
|
51
|
-
let cp = [firstPoint, midPoint, lastPoint];
|
|
52
|
-
if (lineParts.length === 1 || lpIndex === lineParts.length - 1) {
|
|
53
|
-
if (ind === bezPathsArr.length - 1) {
|
|
54
|
-
cp = [firstPoint, lastPoint];
|
|
15
|
+
dribbleLineParts.forEach(lp => {
|
|
16
|
+
const { controlPoints, lpIndex } = lp;
|
|
17
|
+
const [firstPoint] = controlPoints;
|
|
18
|
+
let alpha = lineParts[lpIndex].alpha || this.line.color.alpha;
|
|
19
|
+
if (this.options.animationGlobalProgress) {
|
|
20
|
+
const [start, end] = this.line.animationKeyTimeChunks[lpIndex];
|
|
21
|
+
if (_.inRange(this.options.animationGlobalProgress, start, end)) {
|
|
22
|
+
if (common.animationProgress(this.options.animationGlobalProgress, start, end) > firstPoint.time) {
|
|
23
|
+
alpha = 0.1;
|
|
55
24
|
}
|
|
56
25
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (this.options.animationGlobalProgress) {
|
|
60
|
-
const [start, end] = this.line.animationKeyTimeChunks[lpIndex];
|
|
61
|
-
if (_.inRange(this.options.animationGlobalProgress, start, end)) {
|
|
62
|
-
if (common.animationProgress(this.options.animationGlobalProgress, start, end) > firstPoint.time) {
|
|
63
|
-
alpha = 0.1;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
this.line.addLinePartAdjusted({ ...lp, controlPoints: cp, alpha });
|
|
68
|
-
});
|
|
26
|
+
}
|
|
27
|
+
this.line.addLinePartAdjusted({ ...lp, controlPoints, alpha });
|
|
69
28
|
});
|
|
70
29
|
}
|
|
71
30
|
}
|
|
72
31
|
|
|
32
|
+
Object.assign(DribbleLineLayer.prototype, DribbleLineTrait);
|
|
33
|
+
|
|
73
34
|
module.exports = DribbleLineLayer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const InternalLineShapeLayer = require('./base/InternalLineShapeLayer');
|
|
2
|
-
const
|
|
2
|
+
const DribbleLineTrait = require('../../../../traits/DribbleLineTrait');
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class DribbleLineShapeLayer extends InternalLineShapeLayer {
|
|
5
5
|
drawLine() {
|
|
6
6
|
this.drawLineFromControlPoints();
|
|
7
7
|
}
|
|
@@ -10,62 +10,11 @@ class CutLineShapeLayer extends InternalLineShapeLayer {
|
|
|
10
10
|
this.drawArrowLineCap();
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
// TODO remove duplicated here and similar inside DribbleLineLayer
|
|
14
13
|
getProcessedLinePaths() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const processedLineParts = [];
|
|
18
|
-
|
|
19
|
-
lineParts.forEach((lp, lpIndex) => {
|
|
20
|
-
const controlPoints = Array(4);
|
|
21
|
-
lp.controlPoints.forEach((cp, index) => {
|
|
22
|
-
controlPoints[index] = cp;
|
|
23
|
-
});
|
|
24
|
-
const bez = new Bezier.Bezier(controlPoints[0], controlPoints[1], controlPoints[2], controlPoints[3]);
|
|
25
|
-
|
|
26
|
-
const bezVector = [];
|
|
27
|
-
let index = 0;
|
|
28
|
-
const step = 1 / bez.length;
|
|
29
|
-
while (index <= 1) {
|
|
30
|
-
bezVector.push({ x: bez.mx(index), y: bez.my(index), time: index }); // setting time for animation alpha processing
|
|
31
|
-
index += step;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const bezPathsArr = [];
|
|
35
|
-
let tempPath = [];
|
|
36
|
-
for (let i = 0; i < bezVector.length; i++) {
|
|
37
|
-
tempPath.push(bezVector[i]);
|
|
38
|
-
if (tempPath.length > 1) {
|
|
39
|
-
bezPathsArr.push(tempPath);
|
|
40
|
-
tempPath = [bezVector[i]];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const amplitudeCf = 1.2;
|
|
45
|
-
bezPathsArr.forEach(([firstPoint, lastPoint], ind) => {
|
|
46
|
-
const vector = { x: (lastPoint.x - firstPoint.x) * amplitudeCf, y: (lastPoint.y - firstPoint.y) * amplitudeCf };
|
|
47
|
-
|
|
48
|
-
const vectorMidPoint = { x: (firstPoint.x + lastPoint.x) / 2, y: (firstPoint.y + lastPoint.y) / 2 };
|
|
49
|
-
|
|
50
|
-
let perpVector = { x: -vector.y, y: vector.x };
|
|
51
|
-
if (ind % 2) {
|
|
52
|
-
perpVector = { x: vector.y, y: -vector.x };
|
|
53
|
-
}
|
|
54
|
-
const midPoint = { x: vectorMidPoint.x + perpVector.x, y: vectorMidPoint.y + perpVector.y };
|
|
55
|
-
|
|
56
|
-
let cp = [firstPoint, midPoint, lastPoint];
|
|
57
|
-
if (lineParts.length === 1 || lpIndex === lineParts.length - 1) {
|
|
58
|
-
if (ind === bezPathsArr.length - 1) {
|
|
59
|
-
cp = [firstPoint, lastPoint];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
processedLineParts.push({ controlPoints: cp });
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return processedLineParts;
|
|
14
|
+
return this.convertLinePartsToDribble([this.shape.linePart]);
|
|
68
15
|
}
|
|
69
16
|
}
|
|
70
17
|
|
|
71
|
-
|
|
18
|
+
Object.assign(DribbleLineShapeLayer.prototype, DribbleLineTrait);
|
|
19
|
+
|
|
20
|
+
module.exports = DribbleLineShapeLayer;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const InternalLineShapeLayer = require('./base/InternalLineShapeLayer');
|
|
2
|
+
|
|
3
|
+
class PassLineShapeLayer extends InternalLineShapeLayer {
|
|
4
|
+
drawLine() {
|
|
5
|
+
this.drawLineFromControlPoints();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
drawLineCap() {
|
|
9
|
+
this.drawArrowLineCap();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
setLineOptions() {
|
|
13
|
+
this.ctx.setLineDash([1, 0.5]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = PassLineShapeLayer;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const Bezier = require('../math/Bezier');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
convertLinePartsToDribble(lineParts) {
|
|
5
|
+
const processedLineParts = [];
|
|
6
|
+
|
|
7
|
+
lineParts.forEach((lp, lpIndex) => {
|
|
8
|
+
const bezierPoints = Array(4);
|
|
9
|
+
lp.controlPoints.forEach((cp, index) => {
|
|
10
|
+
bezierPoints[index] = cp;
|
|
11
|
+
});
|
|
12
|
+
const bez = new Bezier.Bezier(bezierPoints[0], bezierPoints[1], bezierPoints[2], bezierPoints[3]);
|
|
13
|
+
|
|
14
|
+
const bezVector = [];
|
|
15
|
+
let index = 0;
|
|
16
|
+
const step = 1 / bez.length;
|
|
17
|
+
while (index <= 1) {
|
|
18
|
+
bezVector.push({ x: bez.mx(index), y: bez.my(index), time: index }); // setting time for animation alpha processing
|
|
19
|
+
index += step;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const bezPathsArr = [];
|
|
23
|
+
let tempPath = [];
|
|
24
|
+
for (let i = 0; i < bezVector.length; i++) {
|
|
25
|
+
tempPath.push(bezVector[i]);
|
|
26
|
+
if (tempPath.length > 1) {
|
|
27
|
+
bezPathsArr.push(tempPath);
|
|
28
|
+
tempPath = [bezVector[i]];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const amplitudeCf = 1.2;
|
|
33
|
+
bezPathsArr.forEach(([firstPoint, lastPoint], ind) => {
|
|
34
|
+
const vector = { x: (lastPoint.x - firstPoint.x) * amplitudeCf, y: (lastPoint.y - firstPoint.y) * amplitudeCf };
|
|
35
|
+
|
|
36
|
+
const vectorMidPoint = { x: (firstPoint.x + lastPoint.x) / 2, y: (firstPoint.y + lastPoint.y) / 2 };
|
|
37
|
+
|
|
38
|
+
let perpVector = { x: -vector.y, y: vector.x };
|
|
39
|
+
if (ind % 2) {
|
|
40
|
+
perpVector = { x: vector.y, y: -vector.x };
|
|
41
|
+
}
|
|
42
|
+
const midPoint = { x: vectorMidPoint.x + perpVector.x, y: vectorMidPoint.y + perpVector.y };
|
|
43
|
+
|
|
44
|
+
let controlPoints = [firstPoint, midPoint, lastPoint];
|
|
45
|
+
if (lineParts.length === 1 || lpIndex === lineParts.length - 1) {
|
|
46
|
+
if (ind === bezPathsArr.length - 1) {
|
|
47
|
+
controlPoints = [firstPoint, lastPoint];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
processedLineParts.push({ controlPoints, lpIndex });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return processedLineParts;
|
|
56
|
+
}
|
|
57
|
+
};
|