From 4e50dd9209cd998739f9ae019bb9bb6a8b15e7d8 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Thu, 14 Jul 2022 09:04:10 +0300 Subject: [PATCH] fix warnings in PitAnimator --- src/animation/PitAnimator.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/animation/PitAnimator.ts b/src/animation/PitAnimator.ts index b6168b7..b657833 100644 --- a/src/animation/PitAnimator.ts +++ b/src/animation/PitAnimator.ts @@ -19,14 +19,14 @@ const animationUpdateInterval = 300; export default class PitAnimator { context: Context; - game: MancalaGame; - oldGame: MancalaGame; + game: MancalaGame | undefined; + oldGame: MancalaGame | undefined; currentIntervalID: number; onBoardViewModelUpdate: (boardViewModel: BoardViewModel) => void; - boardViewModel: BoardViewModel; - oldBoardViewModel: BoardViewModel; + boardViewModel: BoardViewModel | undefined; + oldBoardViewModel: BoardViewModel | undefined; animationIndex: number = 0; - currentHistoryItem: HistoryItem; + currentHistoryItem: HistoryItem | undefined; constructor( context: Context, @@ -55,7 +55,7 @@ export default class PitAnimator { onGameMoveAnimationStart() { this.stopCurrentAnimation(); - if (this.game.history.length > 0) { + if (this.game && this.oldGame && this.game.history.length > 0) { const lastHistoryItem = this.game.history[this.game.history.length - 1]; if (lastHistoryItem.gameSteps.length > 0) { this.animationIndex = 0; @@ -68,6 +68,7 @@ export default class PitAnimator { } onAnimate() { + if(!this.currentHistoryItem || !this.game || !this.oldBoardViewModel) return; if (this.animationIndex === this.currentHistoryItem.gameSteps.length) { this.clearCurrentInterval(); this.onBoardViewModelUpdate?.(this.getBoardViewModelFromGame(this.game)); @@ -91,9 +92,10 @@ export default class PitAnimator { boardViewModel: BoardViewModel, gameStep: GameStep ) { + if(!this.currentHistoryItem || !this.game) return; const pitViewModel = boardViewModel.pits[index]; if (this.animationIndex === 0) { - //This one stone move case, TODO : beautify it later + //This is one stone move case, TODO: beautify it later if (this.getGameMoveStepCount(this.currentHistoryItem) === 1) { const previousPitIndex = gameStep.index - 1; if (previousPitIndex > 0) { @@ -185,15 +187,15 @@ export default class PitAnimator { public resetAnimationState() { this.animationIndex = -1; - this.currentHistoryItem = null; - this.boardViewModel = null; - this.oldBoardViewModel = null; + this.currentHistoryItem = undefined; + this.boardViewModel = undefined; + this.oldBoardViewModel = undefined; } public reset() { this.resetAnimationState(); - this.game = null; - this.oldGame = null; + this.game = undefined; + this.oldGame = undefined; } public dispose() {