@luceosports/play-rendering 1.9.35 → 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.35",
3
+ "version": "1.9.36",
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;