@luceosports/play-rendering 1.9.35 → 1.9.38

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.35",
3
+ "version": "1.9.38",
4
4
  "description": "",
5
5
  "main": "dist/play-rendering.js",
6
6
  "scripts": {
@@ -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
  );
@@ -111,6 +83,46 @@ class PlayerLayer extends BaseLayer {
111
83
 
112
84
  this.ctx.fillStyle = color;
113
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
+ }
114
126
  }
115
127
 
116
128
  module.exports = PlayerLayer;
@@ -139,9 +139,9 @@ class InternalLineLayer extends InternalBaseLayer {
139
139
 
140
140
  this.ctx.beginPath();
141
141
 
142
- this.ctx.translate(Math.abs(courtArrowTipPoint.x), Math.abs(courtArrowTipPoint.y));
142
+ this.ctx.translate(courtArrowTipPoint.x, courtArrowTipPoint.y);
143
143
  this.ctx.rotate(angle);
144
- this.ctx.translate(-Math.abs(courtArrowTipPoint.x), -Math.abs(courtArrowTipPoint.y));
144
+ this.ctx.translate(-courtArrowTipPoint.x, -courtArrowTipPoint.y);
145
145
 
146
146
  this.ctx.moveTo(courtLineEndPoint.x, courtLineEndPoint.y);
147
147
  this.ctx.lineTo(courtArrowEdgePoint1.x, courtArrowEdgePoint1.y);
@@ -168,9 +168,9 @@ class InternalLineLayer extends InternalBaseLayer {
168
168
 
169
169
  this.ctx.beginPath();
170
170
 
171
- this.ctx.translate(Math.abs(courtPoint.x), Math.abs(courtPoint.y));
171
+ this.ctx.translate(courtPoint.x, courtPoint.y);
172
172
  this.ctx.rotate(angle);
173
- this.ctx.translate(-Math.abs(courtPoint.x), -Math.abs(courtPoint.y));
173
+ this.ctx.translate(-courtPoint.x, -courtPoint.y);
174
174
 
175
175
  this.ctx.moveTo(lineCapStartPoint.x, lineCapStartPoint.y);
176
176
  this.ctx.lineTo(lineCapEndPoint.x, lineCapEndPoint.y);
@@ -205,17 +205,17 @@ class InternalLineLayer extends InternalBaseLayer {
205
205
  if (this.line.playerPositionOrigin) {
206
206
  const positionOrigin = this.line.playerPositionOrigin;
207
207
  const lineSequence = this.line.playerLineSequence;
208
- const player = this.playData.players.find(p => p.position === positionOrigin);
209
- if (!player) return;
210
- // console.log('player: ', player);
211
208
 
212
209
  if (lineSequence === 0) {
213
- // For simple lines without sequence we use player.location for startMaskSettings
214
- let radius = player.possession ? 1.5 : 1.0;
215
- if (this.line.type === 'HANDOFF' && !player.possession) {
216
- radius = 0.7;
210
+ const player = this.playData.players.find(p => p.position === positionOrigin);
211
+ if (player) {
212
+ // For simple lines without sequence we use player.location for startMaskSettings
213
+ let radius = player.possession ? 1.5 : 1.0;
214
+ if (this.line.type === 'HANDOFF' && !player.possession) {
215
+ radius = 0.7;
216
+ }
217
+ this.startMaskSettings = { centerPoint: player.location, radius: radius };
217
218
  }
218
- this.startMaskSettings = { centerPoint: player.location, radius: radius };
219
219
  } else if (positionOrigin) {
220
220
  // Find prev line in line sequence for player
221
221
  // and get last cp of last line part
@@ -1,11 +1,11 @@
1
- // require all modules on the path and with the pattern defined
2
- const req = require.context('./layers/', true, /.js$/);
3
-
4
- const modules = {};
5
-
6
- req.keys().forEach(key => {
7
- const mname = key.replace('./', '').replace('.js', '');
8
- modules[mname] = req(key);
9
- });
10
-
11
- module.exports = modules;
1
+ // require all modules on the path and with the pattern defined
2
+ const req = require.context('./layers/', true, /.js$/);
3
+
4
+ const modules = {};
5
+
6
+ req.keys().forEach(key => {
7
+ const mname = key.replace('./', '').replace('.js', '');
8
+ modules[mname] = req(key);
9
+ });
10
+
11
+ module.exports = modules;