@luceosports/play-rendering 1.12.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luceosports/play-rendering",
3
- "version": "1.12.0",
3
+ "version": "1.12.2",
4
4
  "description": "",
5
5
  "main": "dist/play-rendering.js",
6
6
  "scripts": {
@@ -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 Bezier = require('../../../math/Bezier');
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
- lineParts.forEach((lp, lpIndex) => {
15
- const controlPoints = Array(4);
16
- lp.controlPoints.forEach((cp, index) => {
17
- controlPoints[index] = cp;
18
- });
19
- const bez = new Bezier.Bezier(controlPoints[0], controlPoints[1], controlPoints[2], controlPoints[3]);
20
-
21
- const bezVector = [];
22
- let index = 0;
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
- let alpha = lp.alpha || this.line.color.alpha;
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,6 +1,7 @@
1
1
  const InternalLineShapeLayer = require('./base/InternalLineShapeLayer');
2
+ const DribbleLineTrait = require('../../../../traits/DribbleLineTrait');
2
3
 
3
- class CutLineShapeLayer extends InternalLineShapeLayer {
4
+ class DribbleLineShapeLayer extends InternalLineShapeLayer {
4
5
  drawLine() {
5
6
  this.drawLineFromControlPoints();
6
7
  }
@@ -8,6 +9,12 @@ class CutLineShapeLayer extends InternalLineShapeLayer {
8
9
  drawLineCap() {
9
10
  this.drawArrowLineCap();
10
11
  }
12
+
13
+ getProcessedLinePaths() {
14
+ return this.convertLinePartsToDribble([this.shape.linePart]);
15
+ }
11
16
  }
12
17
 
13
- module.exports = CutLineShapeLayer;
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,5 @@
1
+ const LineShape = require('../LineShape');
2
+
3
+ class PassLineShape extends LineShape {}
4
+
5
+ module.exports = PassLineShape;
@@ -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
+ };
@@ -19,7 +19,8 @@ module.exports = {
19
19
  this.ctx.moveTo(cp[0].x, cp[0].y);
20
20
 
21
21
  if (cp.length === 2) {
22
- if (this.line.type === 'DRIBBLE') this.ctx.lineCap = 'round'; // fix last straight line cap segment
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
23
24
  this.ctx.lineTo(cp[1].x, cp[1].y);
24
25
  }
25
26
  if (cp.length === 3) {