@luceosports/play-rendering 2.0.3 → 2.0.4
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
|
@@ -106,14 +106,31 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
106
106
|
const playerMapItem = this.options.playersMap.find(item => item.position === player.position);
|
|
107
107
|
const headshotImage = this.staticData.playerHeadshots.find(item => item.id === playerMapItem?.teamPlayerId);
|
|
108
108
|
if (headshotImage) {
|
|
109
|
+
const imageVertical = headshotImage.image.width < headshotImage.image.height;
|
|
110
|
+
const imageHorizontal = headshotImage.image.height < headshotImage.image.width;
|
|
111
|
+
|
|
112
|
+
const imageScale = imageVertical
|
|
113
|
+
? headshotImage.image.height / headshotImage.image.width
|
|
114
|
+
: imageHorizontal
|
|
115
|
+
? headshotImage.image.width / headshotImage.image.height
|
|
116
|
+
: 1;
|
|
117
|
+
|
|
118
|
+
const dw =
|
|
119
|
+
this.radius * 2 * (imageVertical ? headshotImage.image.width / headshotImage.image.height : 1) * imageScale;
|
|
120
|
+
const dh =
|
|
121
|
+
this.radius * 2 * (imageHorizontal ? headshotImage.image.height / headshotImage.image.width : 1) * imageScale;
|
|
122
|
+
|
|
123
|
+
const topLeftX = 0 - (imageHorizontal ? dw / 2 : this.radius);
|
|
124
|
+
const topLeftY = 0 - (imageVertical ? dh / 2 : this.radius);
|
|
125
|
+
|
|
109
126
|
this.ctx.save();
|
|
110
127
|
this.ctx.translate(x, y);
|
|
111
|
-
if (this.options.flipPlayerLabels
|
|
128
|
+
if (this.options.flipPlayerLabels) {
|
|
112
129
|
this.ctx.rotate(Math.PI);
|
|
113
130
|
}
|
|
114
131
|
this.ctx.arc(0, 0, this.radius, 0, Math.PI * 2, true);
|
|
115
132
|
this.ctx.clip();
|
|
116
|
-
this.ctx.drawImage(headshotImage.image,
|
|
133
|
+
this.ctx.drawImage(headshotImage.image, topLeftX, topLeftY, dw, dh);
|
|
117
134
|
this.ctx.restore();
|
|
118
135
|
return;
|
|
119
136
|
}
|
|
@@ -135,7 +152,7 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
135
152
|
this.ctx.textAlign = 'center';
|
|
136
153
|
this.ctx.font = `${fontSize}px Helvetica`;
|
|
137
154
|
|
|
138
|
-
if (this.options.mirror
|
|
155
|
+
if (this.options.mirror) {
|
|
139
156
|
this.ctx.save();
|
|
140
157
|
this.ctx.translate(x * 2, 0);
|
|
141
158
|
this.ctx.scale(-1, 1);
|
|
@@ -144,7 +161,7 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
144
161
|
let px = x;
|
|
145
162
|
let py = y;
|
|
146
163
|
|
|
147
|
-
if (this.options.flipPlayerLabels
|
|
164
|
+
if (this.options.flipPlayerLabels) {
|
|
148
165
|
px = 0;
|
|
149
166
|
py = 0;
|
|
150
167
|
this.ctx.save();
|
|
@@ -154,11 +171,11 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
154
171
|
|
|
155
172
|
this.ctx.fillText(player.textLabel, px, py + textVerticalOffset);
|
|
156
173
|
|
|
157
|
-
if (this.options.flipPlayerLabels
|
|
174
|
+
if (this.options.flipPlayerLabels) {
|
|
158
175
|
this.ctx.restore();
|
|
159
176
|
}
|
|
160
177
|
|
|
161
|
-
if (this.options.mirror
|
|
178
|
+
if (this.options.mirror) {
|
|
162
179
|
this.ctx.restore();
|
|
163
180
|
}
|
|
164
181
|
}
|