From b6118e686def7cda2fbce94c7601c4f37cd692d5 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Thu, 10 Sep 2020 08:16:52 -0500 Subject: [PATCH] Add ability to refresh view to game service (#3) --- src/services/GameState.service.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/services/GameState.service.js b/src/services/GameState.service.js index 64e1652..547101f 100644 --- a/src/services/GameState.service.js +++ b/src/services/GameState.service.js @@ -314,7 +314,7 @@ export class GameStateService { } this.current_turn_had_missile_attempt = false - this.game_state_change_listeners.forEach(fn => fn(this.current_state)) + this.game_state_change_listeners.forEach(fn => fn(this.current_state, false)) } /** @@ -422,6 +422,9 @@ export class GameStateService { this.get_covered_cells(coords_one, coords_two).some(([row_i, col_i]) => { this._set_cell_state(this.current_player, row_i, col_i, GridCellState.Ship) }) + + // refresh the view + this._trigger_view_update() } /** @@ -627,6 +630,14 @@ export class GameStateService { _get_cell_state(player, row_i, col_i) { return this.player_x_game_board[player][row_i][col_i] } + + /** + * Force a view update without changing the current state. + * @private + */ + _trigger_view_update() { + this.game_state_change_listeners.forEach(fn => fn(this.current_state, true)) + } } // Export a single instance, so it can be shared by all files