@luceosports/play-rendering 1.9.32 → 1.9.36

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.9.32",
3
+ "version": "1.9.36",
4
4
  "description": "",
5
5
  "main": "dist/play-rendering.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -4,7 +4,8 @@ module.exports = Object.freeze({
4
4
  COURT_RECT_WIDTH: 50.0,
5
5
  COURT_RECT_HEIGHT: 94.0,
6
6
  PLAYER_TOKEN_SCALE: 1,
7
- LINE_SCALE: 1
7
+ LINE_SCALE: 1,
8
+ LINE_MASKING: true
8
9
  },
9
10
  FOOTBALL: {
10
11
  COURT_LINE_WIDTH: 0.32,
@@ -12,6 +13,7 @@ module.exports = Object.freeze({
12
13
  COURT_RECT_HEIGHT: 360.0,
13
14
  END_ZONE_HEIGHT: 30,
14
15
  PLAYER_TOKEN_SCALE: 2,
15
- LINE_SCALE: 1.65
16
+ LINE_SCALE: 1.65,
17
+ LINE_MASKING: false
16
18
  }
17
19
  });
@@ -5,61 +5,33 @@ class PlayerLayer extends BaseLayer {
5
5
  return this.options.staticData;
6
6
  }
7
7
 
8
+ get playerScale() {
9
+ return this.courtTypeConstants.PLAYER_TOKEN_SCALE;
10
+ }
11
+
12
+ get radius() {
13
+ return 1.5 * this.playerScale;
14
+ }
15
+
8
16
  apply() {
9
17
  if (!this.playData.players.length) return;
10
18
 
11
- const playerScale = this.courtTypeConstants.PLAYER_TOKEN_SCALE;
12
- const radius = 1.5 * playerScale;
13
-
14
19
  this.ctx.save();
15
20
 
16
21
  this.playData.players.forEach(player => {
17
22
  if (this.options.playersHiddenPositions.findIndex(p => parseInt(p) === parseInt(player.position)) >= 0) return;
18
23
 
19
- const fontSize = (player.textLabel.length > 1 ? 2.0 : 2.5) * playerScale;
20
- const textVerticalOffset = (player.textLabel.length > 1 ? 0.7 : 0.85) * playerScale;
21
-
22
24
  const { x, y } = player.location;
23
25
 
24
- this.ctx.font = `${fontSize}px Helvetica`;
25
-
26
26
  this.setPlayerColor(player);
27
27
 
28
28
  this.ctx.beginPath();
29
29
  this.ctx.moveTo(x, y);
30
30
 
31
- this.ctx.arc(x, y, radius, 0, Math.PI * 2, true);
31
+ this.ctx.arc(x, y, this.radius, 0, Math.PI * 2, true);
32
32
  this.ctx.fill();
33
33
 
34
- this.ctx.fillStyle = '#ffffff';
35
- this.ctx.textAlign = 'center';
36
-
37
- let px = x;
38
- let py = y;
39
-
40
- if (this.options.mirror === true) {
41
- this.ctx.save();
42
- this.ctx.translate(x * 2, 0);
43
- this.ctx.scale(-1, 1);
44
- }
45
-
46
- if (this.options.flipPlayerLabels === true) {
47
- px = 0;
48
- py = 0;
49
- this.ctx.save();
50
- this.ctx.translate(x, y);
51
- this.ctx.rotate(Math.PI); // 180
52
- }
53
-
54
- this.ctx.fillText(player.textLabel, px, py + textVerticalOffset);
55
-
56
- if (this.options.flipPlayerLabels === true) {
57
- this.ctx.restore();
58
- }
59
-
60
- if (this.options.mirror === true) {
61
- this.ctx.restore();
62
- }
34
+ this.setPlayerLabel(player);
63
35
 
64
36
  if (this.staticData.playerHats && this.staticData.playerHats.length) {
65
37
  const playerHat = this.staticData.playerHats.find(hat => {
@@ -78,7 +50,7 @@ class PlayerLayer extends BaseLayer {
78
50
  this.ctx.drawImage(
79
51
  playerHat.image,
80
52
  x - (hatWidth / 2 - hatWidth * hatDX),
81
- y - (hatHeight / 2 + radius * 2 + hatHeight * hatDY),
53
+ y - (hatHeight / 2 + this.radius * 2 + hatHeight * hatDY),
82
54
  hatWidth,
83
55
  hatHeight
84
56
  );
@@ -93,21 +65,64 @@ class PlayerLayer extends BaseLayer {
93
65
  }
94
66
 
95
67
  setPlayerColor(player) {
96
- const payerInPosition = this.options.position && player.position === this.options.position;
97
-
98
68
  const { red, green, blue, alpha } = player.color;
99
69
 
70
+ const defaultInputColor = red === 0 && green === 0 && blue === 0 && alpha === 1;
71
+
72
+ const payerInPosition = this.options.position && player.position === this.options.position;
100
73
  const r = payerInPosition ? 0 : Math.ceil(red * 255);
101
74
  const g = payerInPosition ? 0 : Math.ceil(green * 255);
102
75
  const b = payerInPosition ? 255 : Math.ceil(blue * 255);
103
76
 
104
77
  let color = `rgba(${r}, ${g}, ${b}, ${alpha})`;
105
- if (!payerInPosition) {
106
- if (player.isDefender) color = '#bb271b';
78
+
79
+ if (player.isDefender && !payerInPosition && defaultInputColor) {
80
+ color = '#bb271b';
107
81
  }
108
- if (player.possession) color = '#ff8000';
82
+ if (player.possession && defaultInputColor) color = '#ff8000';
83
+
109
84
  this.ctx.fillStyle = color;
110
85
  }
86
+
87
+ setPlayerLabel(player) {
88
+ const { x, y } = player.location;
89
+ const { alpha } = player.color;
90
+ const fontSize = (player.textLabel.length > 1 ? 2.0 : 2.5) * this.playerScale;
91
+ const textVerticalOffset = (player.textLabel.length > 1 ? 0.7 : 0.85) * this.playerScale;
92
+
93
+ if (!alpha) return;
94
+
95
+ this.ctx.fillStyle = '#ffffff';
96
+ this.ctx.textAlign = 'center';
97
+ this.ctx.font = `${fontSize}px Helvetica`;
98
+
99
+ if (this.options.mirror === true) {
100
+ this.ctx.save();
101
+ this.ctx.translate(x * 2, 0);
102
+ this.ctx.scale(-1, 1);
103
+ }
104
+
105
+ let px = x;
106
+ let py = y;
107
+
108
+ if (this.options.flipPlayerLabels === true) {
109
+ px = 0;
110
+ py = 0;
111
+ this.ctx.save();
112
+ this.ctx.translate(x, y);
113
+ this.ctx.rotate(Math.PI); // 180
114
+ }
115
+
116
+ this.ctx.fillText(player.textLabel, px, py + textVerticalOffset);
117
+
118
+ if (this.options.flipPlayerLabels === true) {
119
+ this.ctx.restore();
120
+ }
121
+
122
+ if (this.options.mirror === true) {
123
+ this.ctx.restore();
124
+ }
125
+ }
111
126
  }
112
127
 
113
128
  module.exports = PlayerLayer;
@@ -12,7 +12,7 @@ class FieldNumberLayer extends InternalCourtLayer {
12
12
 
13
13
  const thinSpaceChar = String.fromCharCode(8202);
14
14
 
15
- this.ctx.fillStyle = '#ffffff';
15
+ this.ctx.fillStyle = this.options.lineColor;
16
16
  this.ctx.translate(x, y);
17
17
 
18
18
  for (let i = 1; i < 10; i++) {
@@ -36,10 +36,12 @@ class Big3Layer extends InternalCourtLayer {
36
36
  this.ctx.arc(point.x, point.y, radius, 0, Math.PI * 2, true);
37
37
  this.ctx.stroke();
38
38
 
39
- this.ctx.fillStyle = '#001c4f';
40
- this.ctx.fill();
39
+ if (this.options.lineColor !== 'transparent') {
40
+ this.ctx.fillStyle = '#001c4f';
41
+ this.ctx.fill();
42
+ }
41
43
 
42
- this.ctx.fillStyle = '#ffffff';
44
+ this.ctx.fillStyle = this.options.lineColor;
43
45
  this.ctx.fillText('4', point.x - textHorizontalOffset, point.y + textVerticalOffset);
44
46
  });
45
47
  }
@@ -9,10 +9,11 @@ class InternalLineLayer extends InternalBaseLayer {
9
9
  this.debugMasking = false;
10
10
  this.startMaskSettings = null;
11
11
  this.endMaskSettings = null;
12
+ this.courtTypeConstants = parentLineLayer.courtTypeConstants;
12
13
  }
13
14
 
14
15
  drawLogic() {
15
- if (!this.options.animationGlobalProgress) {
16
+ if (!this.options.animationGlobalProgress && this.courtTypeConstants.LINE_MASKING) {
16
17
  this.setLineMasking();
17
18
  this.applyMasking();
18
19
  }