@luceosports/play-rendering 2.0.3 → 2.0.5
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
|
@@ -90,8 +90,12 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
90
90
|
|
|
91
91
|
drawPlayerPuck(player: PlayerModel) {
|
|
92
92
|
const { x, y } = player.location;
|
|
93
|
+
const radius =
|
|
94
|
+
this.staticData.playerHeadshots && this.options.labelsOverrideType === 'Headshot'
|
|
95
|
+
? this.radius + this.courtTypeConstants.LINE_WIDTH / 2
|
|
96
|
+
: this.radius;
|
|
93
97
|
this.ctx.beginPath();
|
|
94
|
-
this.ctx.arc(x, y,
|
|
98
|
+
this.ctx.arc(x, y, radius, 0, Math.PI * 2, true);
|
|
95
99
|
if (this.options.legacyPrintStyle) {
|
|
96
100
|
if (player.possession) this.ctx.stroke();
|
|
97
101
|
return;
|
|
@@ -105,18 +109,45 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
105
109
|
if (this.staticData.playerHeadshots && this.options.labelsOverrideType === 'Headshot') {
|
|
106
110
|
const playerMapItem = this.options.playersMap.find(item => item.position === player.position);
|
|
107
111
|
const headshotImage = this.staticData.playerHeadshots.find(item => item.id === playerMapItem?.teamPlayerId);
|
|
112
|
+
|
|
113
|
+
this.ctx.save();
|
|
114
|
+
|
|
115
|
+
this.ctx.translate(x, y);
|
|
116
|
+
|
|
108
117
|
if (headshotImage) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
const imageVertical = headshotImage.image.width < headshotImage.image.height;
|
|
119
|
+
const imageHorizontal = headshotImage.image.height < headshotImage.image.width;
|
|
120
|
+
|
|
121
|
+
const imageScale = imageVertical
|
|
122
|
+
? headshotImage.image.height / headshotImage.image.width
|
|
123
|
+
: imageHorizontal
|
|
124
|
+
? headshotImage.image.width / headshotImage.image.height
|
|
125
|
+
: 1;
|
|
126
|
+
|
|
127
|
+
const dw =
|
|
128
|
+
this.radius * 2 * (imageVertical ? headshotImage.image.width / headshotImage.image.height : 1) * imageScale;
|
|
129
|
+
const dh =
|
|
130
|
+
this.radius * 2 * (imageHorizontal ? headshotImage.image.height / headshotImage.image.width : 1) * imageScale;
|
|
131
|
+
|
|
132
|
+
const topLeftX = 0 - (imageHorizontal ? dw / 2 : this.radius);
|
|
133
|
+
const topLeftY = 0 - (imageVertical ? dh / 2 : this.radius);
|
|
134
|
+
|
|
135
|
+
if (this.options.flipPlayerLabels) {
|
|
112
136
|
this.ctx.rotate(Math.PI);
|
|
113
137
|
}
|
|
114
138
|
this.ctx.arc(0, 0, this.radius, 0, Math.PI * 2, true);
|
|
115
139
|
this.ctx.clip();
|
|
116
|
-
this.ctx.drawImage(headshotImage.image,
|
|
117
|
-
this.ctx.restore();
|
|
118
|
-
return;
|
|
140
|
+
this.ctx.drawImage(headshotImage.image, topLeftX, topLeftY, dw, dh);
|
|
119
141
|
}
|
|
142
|
+
|
|
143
|
+
this.ctx.beginPath();
|
|
144
|
+
this.ctx.lineWidth = this.courtTypeConstants.LINE_WIDTH;
|
|
145
|
+
this.ctx.arc(0, 0, this.radius, 0, Math.PI * 2, true);
|
|
146
|
+
this.ctx.stroke();
|
|
147
|
+
|
|
148
|
+
this.ctx.restore();
|
|
149
|
+
|
|
150
|
+
if (headshotImage) return;
|
|
120
151
|
}
|
|
121
152
|
|
|
122
153
|
const { alpha } = player.color;
|
|
@@ -135,7 +166,7 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
135
166
|
this.ctx.textAlign = 'center';
|
|
136
167
|
this.ctx.font = `${fontSize}px Helvetica`;
|
|
137
168
|
|
|
138
|
-
if (this.options.mirror
|
|
169
|
+
if (this.options.mirror) {
|
|
139
170
|
this.ctx.save();
|
|
140
171
|
this.ctx.translate(x * 2, 0);
|
|
141
172
|
this.ctx.scale(-1, 1);
|
|
@@ -144,7 +175,7 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
144
175
|
let px = x;
|
|
145
176
|
let py = y;
|
|
146
177
|
|
|
147
|
-
if (this.options.flipPlayerLabels
|
|
178
|
+
if (this.options.flipPlayerLabels) {
|
|
148
179
|
px = 0;
|
|
149
180
|
py = 0;
|
|
150
181
|
this.ctx.save();
|
|
@@ -154,11 +185,11 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
154
185
|
|
|
155
186
|
this.ctx.fillText(player.textLabel, px, py + textVerticalOffset);
|
|
156
187
|
|
|
157
|
-
if (this.options.flipPlayerLabels
|
|
188
|
+
if (this.options.flipPlayerLabels) {
|
|
158
189
|
this.ctx.restore();
|
|
159
190
|
}
|
|
160
191
|
|
|
161
|
-
if (this.options.mirror
|
|
192
|
+
if (this.options.mirror) {
|
|
162
193
|
this.ctx.restore();
|
|
163
194
|
}
|
|
164
195
|
}
|