@luceosports/play-rendering 2.1.5 → 2.2.1
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.
|
@@ -30,10 +30,18 @@ export type PlayModelOptions = {
|
|
|
30
30
|
legacyPrintStyle: boolean;
|
|
31
31
|
showHalfCourtCircle: boolean;
|
|
32
32
|
playersMap: PlayersMapItem[];
|
|
33
|
-
labelsOverrideType: 'Headshot' | null;
|
|
33
|
+
labelsOverrideType: 'Initials' | 'Jersey number' | 'Headshot' | null;
|
|
34
34
|
inDrawingState: boolean;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export type TeamPlayer = {
|
|
38
|
+
id: string;
|
|
39
|
+
User_Name: string;
|
|
40
|
+
Initials: string;
|
|
41
|
+
jersey_number: number;
|
|
42
|
+
headshotUrl?: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
37
45
|
export class PlayModel {
|
|
38
46
|
name: string;
|
|
39
47
|
playData: PlayData;
|
|
@@ -42,7 +50,7 @@ export class PlayModel {
|
|
|
42
50
|
static init({ teamLogoPath }?: {
|
|
43
51
|
teamLogoPath?: string;
|
|
44
52
|
}): Promise<void>;
|
|
45
|
-
static
|
|
53
|
+
static setTeamPlayers(data: TeamPlayer[]): Promise<void>
|
|
46
54
|
get totalPhasesCount(): number;
|
|
47
55
|
get scale(): number;
|
|
48
56
|
get width(): number;
|
package/package.json
CHANGED
|
@@ -102,8 +102,9 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
102
102
|
setPlayerLabel(player: PlayerModel) {
|
|
103
103
|
const { x, y } = player.location;
|
|
104
104
|
|
|
105
|
+
const playerMapItem = this.options.playersMap.find(item => item.position === player.position);
|
|
106
|
+
|
|
105
107
|
if (this.staticData.playerHeadshots && this.options.labelsOverrideType === 'Headshot') {
|
|
106
|
-
const playerMapItem = this.options.playersMap.find(item => item.position === player.position);
|
|
107
108
|
const headshotImage = this.staticData.playerHeadshots.find(item => item.id === playerMapItem?.teamPlayerId);
|
|
108
109
|
|
|
109
110
|
this.ctx.save();
|
|
@@ -148,13 +149,33 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
148
149
|
if (headshotImage) return;
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
let playerTextLabel = player.textLabel;
|
|
153
|
+
if (playerMapItem) {
|
|
154
|
+
if (playerMapItem.textOverride) {
|
|
155
|
+
playerTextLabel = playerMapItem.textOverride;
|
|
156
|
+
}
|
|
157
|
+
if (playerMapItem.teamPlayerId) {
|
|
158
|
+
const teamPlayer = this.staticData.teamPlayers.find(p => p.id === playerMapItem.teamPlayerId);
|
|
159
|
+
if (teamPlayer) {
|
|
160
|
+
const fallbackLabel = teamPlayer.User_Name.split(' ')
|
|
161
|
+
.map(n => n[0])
|
|
162
|
+
.join('')
|
|
163
|
+
.slice(0, 2);
|
|
164
|
+
playerTextLabel = teamPlayer.Initials || fallbackLabel;
|
|
165
|
+
if (this.options.labelsOverrideType === 'Jersey number' && teamPlayer.jersey_number) {
|
|
166
|
+
playerTextLabel = `${teamPlayer.jersey_number}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
151
172
|
const { alpha } = player.color;
|
|
152
173
|
|
|
153
|
-
const fontSizeLength = 3 -
|
|
174
|
+
const fontSizeLength = 3 - playerTextLabel.length * 0.5;
|
|
154
175
|
const fontSizeMultiplier = this.options.legacyPrintStyle ? 1.3 : 1;
|
|
155
176
|
const fontSize = fontSizeLength * fontSizeMultiplier * this.playerScale;
|
|
156
177
|
|
|
157
|
-
const textVOffsetLength = 1 -
|
|
178
|
+
const textVOffsetLength = 1 - playerTextLabel.length * 0.15;
|
|
158
179
|
const textVOffsetMultiplier = this.options.legacyPrintStyle ? 1.4 : 1;
|
|
159
180
|
const textVerticalOffset = textVOffsetLength * textVOffsetMultiplier * this.playerScale;
|
|
160
181
|
|
|
@@ -181,7 +202,7 @@ export default class PlayerLayer extends BaseLayer {
|
|
|
181
202
|
this.ctx.rotate(Math.PI); // 180
|
|
182
203
|
}
|
|
183
204
|
|
|
184
|
-
this.ctx.fillText(
|
|
205
|
+
this.ctx.fillText(playerTextLabel, px, py + textVerticalOffset);
|
|
185
206
|
|
|
186
207
|
if (this.options.flipPlayerLabels) {
|
|
187
208
|
this.ctx.restore();
|
package/src/models/PlayModel.ts
CHANGED
|
@@ -42,6 +42,7 @@ export type PlayStaticData = {
|
|
|
42
42
|
playerHats: readonly ImageConfigItem[];
|
|
43
43
|
shapes: readonly ImageConfigItem[];
|
|
44
44
|
playerHeadshots: typeof PlayModel.playerHeadshots;
|
|
45
|
+
teamPlayers: typeof PlayModel.teamPlayers;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
export type PlayersMapItem = {
|
|
@@ -51,6 +52,14 @@ export type PlayersMapItem = {
|
|
|
51
52
|
playerHatKey?: string | null;
|
|
52
53
|
};
|
|
53
54
|
|
|
55
|
+
export type TeamPlayer = {
|
|
56
|
+
id: string;
|
|
57
|
+
User_Name: string;
|
|
58
|
+
Initials: string;
|
|
59
|
+
jersey_number: number;
|
|
60
|
+
headshotUrl?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
54
63
|
export type PlayModelOptions = {
|
|
55
64
|
width: number;
|
|
56
65
|
lineColor: string;
|
|
@@ -73,7 +82,7 @@ export type PlayModelOptions = {
|
|
|
73
82
|
legacyPrintStyle: boolean;
|
|
74
83
|
showHalfCourtCircle: boolean;
|
|
75
84
|
playersMap: PlayersMapItem[];
|
|
76
|
-
labelsOverrideType: 'Headshot' | null;
|
|
85
|
+
labelsOverrideType: 'Initials' | 'Jersey number' | 'Headshot' | null;
|
|
77
86
|
inDrawingState: boolean;
|
|
78
87
|
};
|
|
79
88
|
|
|
@@ -81,6 +90,7 @@ export default class PlayModel {
|
|
|
81
90
|
public name: string;
|
|
82
91
|
public playData: PlayData;
|
|
83
92
|
public options: PlayModelOptions;
|
|
93
|
+
public static teamPlayers: TeamPlayer[] = [];
|
|
84
94
|
public static playerHeadshots: PlayerHeadshotItem[] = [];
|
|
85
95
|
public static playerHats: readonly ImageConfigItem[];
|
|
86
96
|
public static shapes: readonly ImageConfigItem[];
|
|
@@ -120,7 +130,8 @@ export default class PlayModel {
|
|
|
120
130
|
};
|
|
121
131
|
}
|
|
122
132
|
|
|
123
|
-
static async
|
|
133
|
+
static async setTeamPlayers(data: TeamPlayer[]) {
|
|
134
|
+
PlayModel.teamPlayers = data;
|
|
124
135
|
await Promise.all(
|
|
125
136
|
data.map(async ({ id, headshotUrl }) => {
|
|
126
137
|
try {
|
|
@@ -159,7 +170,8 @@ export default class PlayModel {
|
|
|
159
170
|
watermark: PlayModel.watermark,
|
|
160
171
|
playerHats: PlayModel.playerHats,
|
|
161
172
|
shapes: PlayModel.shapes,
|
|
162
|
-
playerHeadshots: PlayModel.playerHeadshots
|
|
173
|
+
playerHeadshots: PlayModel.playerHeadshots,
|
|
174
|
+
teamPlayers: PlayModel.teamPlayers
|
|
163
175
|
};
|
|
164
176
|
}
|
|
165
177
|
|