Skip to content

Commit 5de94c6

Browse files
committed
update
1 parent 5a28fc5 commit 5de94c6

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

dist/MLB.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ __webpack_require__.a(module, async (__webpack_handle_async_dependencies__) => {
4545

4646

4747

48-
const scriptVersion = 15;
48+
const scriptVersion = 16;
4949
const sourceRepo = "evandcoleman/scriptable";
5050
const scriptName = "MLB";
5151

@@ -271,22 +271,24 @@ async function createExpandedWidget() {
271271
}
272272
}
273273
namePitchesStack.addSpacer();
274-
} else if (isPostGame) {
274+
} else if (isPostGame && game.decisions) {
275275
const abTitleText = lowerStack.addText("Winning Pitcher:")
276276
abTitleText.font = Font.mediumSystemFont(11);
277277
abTitleText.textColor = Color.lightGray();
278278
const nameCountStack = lowerStack.addStack();
279279
nameCountStack.layoutHorizontally();
280280
nameCountStack.centerAlignContent();
281-
const playerNameText = nameCountStack.addText(game.decisions.winner.fullName);
281+
const playerNameText = nameCountStack.addText(game.decisions.winner?.fullName || "N/A");
282282
playerNameText.font = Font.regularSystemFont(12);
283283
playerNameText.textColor = Color.white();
284284
// playerNameText.minimumScaleFactor = 0.9;
285285
nameCountStack.addSpacer(4);
286-
const winnerStats = game.decisions.winner.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
287-
const countText = nameCountStack.addText(`(${winnerStats.wins}-${winnerStats.losses})`);
288-
countText.font = Font.regularSystemFont(10);
289-
countText.textColor = Color.lightGray();
286+
if (game.decisions.winner && game.decisions.winner.stats) {
287+
const winnerStats = game.decisions.winner.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
288+
const countText = nameCountStack.addText(`(${winnerStats.wins}-${winnerStats.losses})`);
289+
countText.font = Font.regularSystemFont(10);
290+
countText.textColor = Color.lightGray();
291+
}
290292
nameCountStack.addSpacer();
291293

292294
const pitcherTitleText = lowerStack.addText("Losing Pitcher:")
@@ -295,15 +297,17 @@ async function createExpandedWidget() {
295297
const namePitchesStack = lowerStack.addStack();
296298
namePitchesStack.layoutHorizontally();
297299
namePitchesStack.centerAlignContent();
298-
const pitcherNameText = namePitchesStack.addText(game.decisions.loser.fullName);
300+
const pitcherNameText = namePitchesStack.addText(game.decisions.loser?.fullName || "N/A");
299301
pitcherNameText.font = Font.regularSystemFont(12);
300302
pitcherNameText.textColor = Color.white();
301303
// pitcherNameText.minimumScaleFactor = 0.9;
302304
namePitchesStack.addSpacer(4);
303-
const loserStats = game.decisions.loser.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
304-
const pitchesThrownText = namePitchesStack.addText(`(${loserStats.wins}-${loserStats.losses})`);
305-
pitchesThrownText.font = Font.regularSystemFont(10);
306-
pitchesThrownText.textColor = Color.lightGray();
305+
if (game.decisions.loser && game.decisions.loser.stats) {
306+
const loserStats = game.decisions.loser.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
307+
const pitchesThrownText = namePitchesStack.addText(`(${loserStats.wins}-${loserStats.losses})`);
308+
pitchesThrownText.font = Font.regularSystemFont(10);
309+
pitchesThrownText.textColor = Color.lightGray();
310+
}
307311
namePitchesStack.addSpacer();
308312
}
309313

src/MLB.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Cache from './lib/cache';
3333
import Updater from './lib/updater';
3434
import * as http from './lib/http';
3535

36-
const scriptVersion = 15;
36+
const scriptVersion = 16;
3737
const sourceRepo = "evandcoleman/scriptable";
3838
const scriptName = "MLB";
3939

@@ -259,22 +259,24 @@ async function createExpandedWidget() {
259259
}
260260
}
261261
namePitchesStack.addSpacer();
262-
} else if (isPostGame) {
262+
} else if (isPostGame && game.decisions) {
263263
const abTitleText = lowerStack.addText("Winning Pitcher:")
264264
abTitleText.font = Font.mediumSystemFont(11);
265265
abTitleText.textColor = Color.lightGray();
266266
const nameCountStack = lowerStack.addStack();
267267
nameCountStack.layoutHorizontally();
268268
nameCountStack.centerAlignContent();
269-
const playerNameText = nameCountStack.addText(game.decisions.winner.fullName);
269+
const playerNameText = nameCountStack.addText(game.decisions.winner?.fullName || "N/A");
270270
playerNameText.font = Font.regularSystemFont(12);
271271
playerNameText.textColor = Color.white();
272272
// playerNameText.minimumScaleFactor = 0.9;
273273
nameCountStack.addSpacer(4);
274-
const winnerStats = game.decisions.winner.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
275-
const countText = nameCountStack.addText(`(${winnerStats.wins}-${winnerStats.losses})`);
276-
countText.font = Font.regularSystemFont(10);
277-
countText.textColor = Color.lightGray();
274+
if (game.decisions.winner && game.decisions.winner.stats) {
275+
const winnerStats = game.decisions.winner.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
276+
const countText = nameCountStack.addText(`(${winnerStats.wins}-${winnerStats.losses})`);
277+
countText.font = Font.regularSystemFont(10);
278+
countText.textColor = Color.lightGray();
279+
}
278280
nameCountStack.addSpacer();
279281

280282
const pitcherTitleText = lowerStack.addText("Losing Pitcher:")
@@ -283,15 +285,17 @@ async function createExpandedWidget() {
283285
const namePitchesStack = lowerStack.addStack();
284286
namePitchesStack.layoutHorizontally();
285287
namePitchesStack.centerAlignContent();
286-
const pitcherNameText = namePitchesStack.addText(game.decisions.loser.fullName);
288+
const pitcherNameText = namePitchesStack.addText(game.decisions.loser?.fullName || "N/A");
287289
pitcherNameText.font = Font.regularSystemFont(12);
288290
pitcherNameText.textColor = Color.white();
289291
// pitcherNameText.minimumScaleFactor = 0.9;
290292
namePitchesStack.addSpacer(4);
291-
const loserStats = game.decisions.loser.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
292-
const pitchesThrownText = namePitchesStack.addText(`(${loserStats.wins}-${loserStats.losses})`);
293-
pitchesThrownText.font = Font.regularSystemFont(10);
294-
pitchesThrownText.textColor = Color.lightGray();
293+
if (game.decisions.loser && game.decisions.loser.stats) {
294+
const loserStats = game.decisions.loser.stats.filter(stat => stat.type.displayName === 'statsSingleSeason' && stat.group.displayName === 'pitching')[0].stats;
295+
const pitchesThrownText = namePitchesStack.addText(`(${loserStats.wins}-${loserStats.losses})`);
296+
pitchesThrownText.font = Font.regularSystemFont(10);
297+
pitchesThrownText.textColor = Color.lightGray();
298+
}
295299
namePitchesStack.addSpacer();
296300
}
297301

0 commit comments

Comments
 (0)