fix warnings in PitAnimator
This commit is contained in:
parent
f53617185c
commit
4e50dd9209
@ -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() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user