-
Notifications
You must be signed in to change notification settings - Fork 136
/
processPlayerNewLeague.ts
82 lines (73 loc) · 2.01 KB
/
processPlayerNewLeague.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { draft, player } from "..";
import { PLAYER } from "../../../common";
import type { PlayerWithoutKey } from "../../../common/types";
import { g } from "../../util";
import type { PreProcessParams } from "./createStream";
const processPlayerNewLeague = async ({
p,
activeTids,
hasRookieContracts,
noStartingInjuries,
realPlayerPhotos,
scoutingRank,
version,
}: {
p: any;
} & Pick<
PreProcessParams,
| "activeTids"
| "hasRookieContracts"
| "noStartingInjuries"
| "realPlayerPhotos"
| "scoutingRank"
| "version"
>) => {
if (realPlayerPhotos) {
// Do this before augment so it doesn't need to create a face
if (p.srID) {
if (realPlayerPhotos[p.srID] !== undefined) {
p.imgURL = realPlayerPhotos[p.srID];
} else {
const name = p.name ?? `${p.firstName} ${p.lastName}`;
// Keep in sync with bbgm-rosters
const key = `dp_${p.draft.year}_${name
.replace(/ /g, "_")
.toLowerCase()}`;
if (realPlayerPhotos[key] !== undefined) {
p.imgURL = realPlayerPhotos[key];
}
}
}
}
const p2: PlayerWithoutKey = await player.augmentPartialPlayer(
{ ...p },
scoutingRank,
version,
true,
);
if (!p.contract) {
p2.contract.temp = true;
if (!p.salaries) {
p2.salaries = [];
}
}
// Impute rookie contract status if there is no contract for this player, or if the entire league file has no rookie contracts. Don't check draftPickAutoContract here because we want all rookie contracts to be labeled as such, not just rookie scale contracts.
if (p2.tid >= 0 && (!p.contract || !hasRookieContracts)) {
const rookieContractLength = draft.getRookieContractLength(p2.draft.round);
const rookieContractExp = p2.draft.year + rookieContractLength;
if (rookieContractExp >= g.get("season")) {
(p2 as any).rookieContract = true;
}
}
if (p2.tid >= 0 && !activeTids.includes(p2.tid)) {
p2.tid = PLAYER.FREE_AGENT;
}
if (noStartingInjuries && p.injury) {
p2.injury = {
type: "Healthy",
gamesRemaining: 0,
};
}
return p2;
};
export default processPlayerNewLeague;