@luceosports/play-rendering 1.17.0 → 1.18.0

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.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "",
5
5
  "main": "dist/play-rendering.js",
6
6
  "scripts": {
@@ -28,6 +28,12 @@ class InternalCourtLayer extends InternalBaseLayer {
28
28
  this.ctx.scale(1, -1);
29
29
  this.ctx.translate(0, -Math.abs(verticalTranslationDist));
30
30
  }
31
+
32
+ setColor(color) {
33
+ const style = this.options.lineColor === 'transparent' ? 'transparent' : color;
34
+ this.ctx.strokeStyle = style;
35
+ this.ctx.fillStyle = style;
36
+ }
31
37
  }
32
38
 
33
39
  module.exports = InternalCourtLayer;
@@ -1,7 +1,7 @@
1
1
  module.exports = Object.freeze({
2
2
  COURT_LINE_WIDTH: 0.1667,
3
3
  PLAYER_TOKEN_RADIUS: 1.5,
4
- PLAYER_TOKEN_SCALE: 1,
5
- LINE_WIDTH: 0.33,
4
+ PLAYER_TOKEN_SCALE: 2,
5
+ LINE_WIDTH: 0.55,
6
6
  LINE_MASKING: true
7
7
  });
@@ -6,7 +6,7 @@ class GoaCreaseLayer extends InternalCourtLayer {
6
6
  }
7
7
 
8
8
  drawLogic() {
9
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_RED;
9
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
10
10
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 2;
11
11
 
12
12
  const goalLineY =
@@ -18,7 +18,7 @@ class GoaCreaseLayer extends InternalCourtLayer {
18
18
  this.ctx.stroke();
19
19
 
20
20
  // 2. Draw goal cage
21
- this.ctx.strokeStyle = '#000';
21
+ this.setColor('#000');
22
22
  this.ctx.beginPath();
23
23
  this.ctx.moveTo(this.courtCenter.x - this.courtTypeConstants.GOAL_CAGE_LENGTH / 2, goalLineY);
24
24
  this.ctx.lineTo(
@@ -6,7 +6,7 @@ class GoaCreaseLayer extends InternalCourtLayer {
6
6
  }
7
7
 
8
8
  drawLogic() {
9
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_RED;
9
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
10
10
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 2;
11
11
 
12
12
  const goalLineY =
@@ -27,7 +27,7 @@ class GoaCreaseLayer extends InternalCourtLayer {
27
27
  this.ctx.stroke();
28
28
 
29
29
  // 2. Draw goal cage
30
- this.ctx.strokeStyle = '#000';
30
+ this.setColor('#000');
31
31
  this.ctx.beginPath();
32
32
  this.ctx.moveTo(this.courtCenter.x - this.courtTypeConstants.GOAL_CAGE_LENGTH / 2, goalLineY);
33
33
  this.ctx.lineTo(
@@ -6,7 +6,7 @@ class BorderRinkLayer extends InternalCourtLayer {
6
6
  }
7
7
 
8
8
  drawLogic() {
9
- this.ctx.strokeStyle = '#000'; // #7c7c7c
9
+ this.setColor('#000');
10
10
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 4;
11
11
 
12
12
  const goalLineY =
@@ -4,7 +4,7 @@ const CENTER_CIRCLE_RADIUS = 15;
4
4
 
5
5
  class CenterCircleLayer extends InternalCourtLayer {
6
6
  drawLogic() {
7
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_BLUE;
7
+ this.setColor(this.courtTypeConstants.LINE_COLOR_BLUE);
8
8
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 2;
9
9
 
10
10
  this.ctx.beginPath();
@@ -2,7 +2,7 @@ const InternalCourtLayer = require('../../../base/InternalCourtLayer');
2
2
 
3
3
  class CenterLineLayer extends InternalCourtLayer {
4
4
  drawLogic() {
5
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_RED;
5
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
6
6
  this.ctx.setLineDash([2, 1]);
7
7
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 4;
8
8
 
@@ -3,7 +3,7 @@ const InternalCourtLayer = require('../../../base/InternalCourtLayer');
3
3
  const CENTER_SPOT_RADIUS = 1;
4
4
  class CenterSpotLayer extends InternalCourtLayer {
5
5
  drawLogic() {
6
- this.ctx.fillStyle = this.courtTypeConstants.LINE_COLOR_BLUE;
6
+ this.setColor(this.courtTypeConstants.LINE_COLOR_BLUE);
7
7
 
8
8
  this.ctx.beginPath();
9
9
  this.ctx.arc(this.courtCenter.x, this.courtCenter.y, CENTER_SPOT_RADIUS, 0, Math.PI * 2, true);
@@ -8,8 +8,7 @@ class EndZoneLayer extends InternalCourtLayer {
8
8
  }
9
9
 
10
10
  drawLogic() {
11
- this.ctx.fillStyle = this.courtTypeConstants.LINE_COLOR_RED;
12
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_RED;
11
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
13
12
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 2;
14
13
 
15
14
  const faceOffOffset =
@@ -6,7 +6,7 @@ class GoalLineLayer extends InternalCourtLayer {
6
6
  }
7
7
 
8
8
  drawLogic() {
9
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_RED;
9
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
10
10
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 2;
11
11
 
12
12
  const goalLineY =
@@ -9,7 +9,7 @@ class NeutralZoneLayer extends InternalCourtLayer {
9
9
 
10
10
  drawLogic() {
11
11
  // 1. Draw blue line
12
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_BLUE;
12
+ this.setColor(this.courtTypeConstants.LINE_COLOR_BLUE);
13
13
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 4;
14
14
 
15
15
  const blueLineOrigin = { x: 0.0, y: this.courtCenter.y - this.courtTypeConstants.NEUTRAL_ZONE_LENGTH };
@@ -24,7 +24,7 @@ class NeutralZoneLayer extends InternalCourtLayer {
24
24
  this.ctx.stroke();
25
25
 
26
26
  // 2. Draw face off spots
27
- this.ctx.fillStyle = this.courtTypeConstants.LINE_COLOR_RED;
27
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
28
28
 
29
29
  const faceOffOffset =
30
30
  (this.courtTypeConstants.COURT_RECT_WIDTH - this.courtTypeConstants.FACE_OFF_SPOTS_DISTANCE) / 2;
@@ -4,7 +4,7 @@ const REFEREE_CREASE_RADIUS = 10;
4
4
 
5
5
  class RefereeCreaseLayer extends InternalCourtLayer {
6
6
  drawLogic() {
7
- this.ctx.strokeStyle = this.courtTypeConstants.LINE_COLOR_RED;
7
+ this.setColor(this.courtTypeConstants.LINE_COLOR_RED);
8
8
  this.ctx.lineWidth = this.courtTypeConstants.COURT_LINE_WIDTH * 2;
9
9
 
10
10
  this.ctx.beginPath();
@@ -6,6 +6,7 @@ class InternalLineLayer extends InternalBaseLayer {
6
6
  constructor(parentLayer, line) {
7
7
  super(parentLayer);
8
8
  this.line = line;
9
+ this.lineWidth = parentLayer.lineWidth;
9
10
  this.debugMasking = false;
10
11
  this.startMaskSettings = null;
11
12
  this.endMaskSettings = null;
@@ -0,0 +1,56 @@
1
+ const ActionLineLayer = require('../base/ActionLineLayer');
2
+
3
+ class ShootLineLayer extends ActionLineLayer {
4
+ drawLineCap() {
5
+ if (this.allowDrawLineCap()) {
6
+ const cp1 = this.line.firstLinePartControlPoint;
7
+ const cp2 = this.line.lastLinePartControlPoint;
8
+
9
+ // Make arrow tip point a bit longer by adding small vector
10
+ const addVector = { x: 0.6, y: 0 };
11
+ const alpha = this.angleBetweenTwoPoints(cp1, cp2);
12
+ const sameAngleAddVector = {
13
+ x: Math.cos(alpha) * addVector.x - Math.sin(alpha) * addVector.y,
14
+ y: Math.sin(alpha) * addVector.x - Math.cos(alpha) * addVector.y
15
+ };
16
+
17
+ const courtArrowTipPoint = {
18
+ x: cp2.x + sameAngleAddVector.x,
19
+ y: cp2.y + sameAngleAddVector.y
20
+ };
21
+ this.drawArrowLineCap(courtArrowTipPoint);
22
+ }
23
+ }
24
+
25
+ setLineOptions() {
26
+ this.ctx.lineWidth = this.lineWidth * 0.7;
27
+
28
+ const lineParts = [...this.line.getLineParts()];
29
+
30
+ this.line.setLinePartsAdjusted([]);
31
+
32
+ lineParts.forEach(lp => {
33
+ const cp = lp.controlPoints;
34
+
35
+ const offsets = [-0.3, 0.3];
36
+ offsets.forEach(offset => {
37
+ const [dx, dy] = [cp[0].x - cp[1].x, cp[0].y - cp[1].y];
38
+ const scale = offset / (dx * dx + dy * dy) ** 0.5;
39
+ const [ox, oy] = [-dy * scale, dx * scale];
40
+
41
+ this.ctx.moveTo(ox + cp[0].x, oy + cp[0].y);
42
+ this.ctx.lineTo(ox + cp[1].x, oy + cp[1].y);
43
+
44
+ this.line.addLinePartAdjusted({
45
+ ...lp,
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
+ ]
50
+ });
51
+ });
52
+ });
53
+ }
54
+ }
55
+
56
+ module.exports = ShootLineLayer;
@@ -155,7 +155,7 @@ class Frame {
155
155
  }
156
156
 
157
157
  get animationProgressPlayers() {
158
- const passLines = this.prevAnimationLines.filter(l => ['PASS', 'HANDOFF'].includes(l.type));
158
+ const passLines = this.prevAnimationLines.filter(l => ['PASS', 'HANDOFF', 'SHOOT'].includes(l.type));
159
159
  return this.play.playData.players.map(p => {
160
160
  const player = new Player(p);
161
161
  player.setPossession(passLines);
@@ -19,8 +19,7 @@ module.exports = {
19
19
  this.ctx.moveTo(cp[0].x, cp[0].y);
20
20
 
21
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
22
+ this.ctx.lineCap = 'round'; // fix last straight line cap segment (needed for dribble lines)
24
23
  this.ctx.lineTo(cp[1].x, cp[1].y);
25
24
  }
26
25
  if (cp.length === 3) {
@@ -38,12 +37,12 @@ module.exports = {
38
37
  this.ctx.restore();
39
38
  },
40
39
 
41
- drawArrowLineCap() {
40
+ drawArrowLineCap(arrowTipPoint = this.arrowTipPoint()) {
42
41
  this.ctx.save();
43
42
 
44
43
  const arrowTipLength = 1.4;
45
44
  const angle = this.angleBetweenLastTwoPoints();
46
- const courtArrowTipPoint = this.arrowTipPoint();
45
+ const courtArrowTipPoint = arrowTipPoint;
47
46
 
48
47
  const courtLineEndPoint = { x: courtArrowTipPoint.x - arrowTipLength / 1.3, y: courtArrowTipPoint.y };
49
48
  const courtArrowEdgePoint1 = {
@@ -137,6 +136,10 @@ module.exports = {
137
136
  const cpTo = cp[cp.length - 1];
138
137
  const cpFrom = cp[cp.length - 2];
139
138
 
139
+ return this.angleBetweenTwoPoints(cpFrom, cpTo);
140
+ },
141
+
142
+ angleBetweenTwoPoints(cpFrom, cpTo) {
140
143
  const dx = cpTo.x - cpFrom.x;
141
144
  const dy = cpTo.y - cpFrom.y;
142
145
  return Math.atan2(dy, dx);