fix warnings in PitAnimator
This commit is contained in:
parent
f53617185c
commit
4e50dd9209
@ -19,14 +19,14 @@ const animationUpdateInterval = 300;
|
|||||||
|
|
||||||
export default class PitAnimator {
|
export default class PitAnimator {
|
||||||
context: Context;
|
context: Context;
|
||||||
game: MancalaGame;
|
game: MancalaGame | undefined;
|
||||||
oldGame: MancalaGame;
|
oldGame: MancalaGame | undefined;
|
||||||
currentIntervalID: number;
|
currentIntervalID: number;
|
||||||
onBoardViewModelUpdate: (boardViewModel: BoardViewModel) => void;
|
onBoardViewModelUpdate: (boardViewModel: BoardViewModel) => void;
|
||||||
boardViewModel: BoardViewModel;
|
boardViewModel: BoardViewModel | undefined;
|
||||||
oldBoardViewModel: BoardViewModel;
|
oldBoardViewModel: BoardViewModel | undefined;
|
||||||
animationIndex: number = 0;
|
animationIndex: number = 0;
|
||||||
currentHistoryItem: HistoryItem;
|
currentHistoryItem: HistoryItem | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
@ -55,7 +55,7 @@ export default class PitAnimator {
|
|||||||
|
|
||||||
onGameMoveAnimationStart() {
|
onGameMoveAnimationStart() {
|
||||||
this.stopCurrentAnimation();
|
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];
|
const lastHistoryItem = this.game.history[this.game.history.length - 1];
|
||||||
if (lastHistoryItem.gameSteps.length > 0) {
|
if (lastHistoryItem.gameSteps.length > 0) {
|
||||||
this.animationIndex = 0;
|
this.animationIndex = 0;
|
||||||
@ -68,6 +68,7 @@ export default class PitAnimator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAnimate() {
|
onAnimate() {
|
||||||
|
if(!this.currentHistoryItem || !this.game || !this.oldBoardViewModel) return;
|
||||||
if (this.animationIndex === this.currentHistoryItem.gameSteps.length) {
|
if (this.animationIndex === this.currentHistoryItem.gameSteps.length) {
|
||||||
this.clearCurrentInterval();
|
this.clearCurrentInterval();
|
||||||
this.onBoardViewModelUpdate?.(this.getBoardViewModelFromGame(this.game));
|
this.onBoardViewModelUpdate?.(this.getBoardViewModelFromGame(this.game));
|
||||||
@ -91,9 +92,10 @@ export default class PitAnimator {
|
|||||||
boardViewModel: BoardViewModel,
|
boardViewModel: BoardViewModel,
|
||||||
gameStep: GameStep
|
gameStep: GameStep
|
||||||
) {
|
) {
|
||||||
|
if(!this.currentHistoryItem || !this.game) return;
|
||||||
const pitViewModel = boardViewModel.pits[index];
|
const pitViewModel = boardViewModel.pits[index];
|
||||||
if (this.animationIndex === 0) {
|
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) {
|
if (this.getGameMoveStepCount(this.currentHistoryItem) === 1) {
|
||||||
const previousPitIndex = gameStep.index - 1;
|
const previousPitIndex = gameStep.index - 1;
|
||||||
if (previousPitIndex > 0) {
|
if (previousPitIndex > 0) {
|
||||||
@ -185,15 +187,15 @@ export default class PitAnimator {
|
|||||||
|
|
||||||
public resetAnimationState() {
|
public resetAnimationState() {
|
||||||
this.animationIndex = -1;
|
this.animationIndex = -1;
|
||||||
this.currentHistoryItem = null;
|
this.currentHistoryItem = undefined;
|
||||||
this.boardViewModel = null;
|
this.boardViewModel = undefined;
|
||||||
this.oldBoardViewModel = null;
|
this.oldBoardViewModel = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset() {
|
public reset() {
|
||||||
this.resetAnimationState();
|
this.resetAnimationState();
|
||||||
this.game = null;
|
this.game = undefined;
|
||||||
this.oldGame = null;
|
this.oldGame = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {
|
public dispose() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user