Web Dev Solutions

Catalin Mititiuc

From 556abf9bbf2e524f1fbe3c44d6fed24192ff4cce Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 22 May 2024 09:20:54 -0700 Subject: Use observable for showing hex distance count --- src/modules/gameboard.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/modules/gameboard.js') diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index 48a32bb..4b7d87b 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -3,7 +3,7 @@ import * as sightLine from './game/sight_line.js'; import * as soldier from './game/soldier.js'; import { Observable } from "./observable"; -let svg, distanceCallback, selected, +let svg, selected, placing = []; function getCellContents(cell) { @@ -89,7 +89,7 @@ function deselect() { function clearSightLine() { sightLine.setHexes([]); sightLine.clear(); - distanceCallback && distanceCallback(); + Observable.notify('distance'); } function updateSightLine(cell) { @@ -103,7 +103,7 @@ function updateSightLine(cell) { const hexes = svg.querySelectorAll(selector); sightLine.setHexes(hexes); sightLine.update(getCellPosition(cell)); - distanceCallback && distanceCallback(hexes.length - 1); + Observable.notify('distance', hexes.length - 1); } function drawSightLine(sourceCell, targetCell) { @@ -118,7 +118,7 @@ function drawSightLine(sourceCell, targetCell) { sightLine.setHexes(hexes); const line = sightLine.create(getCellPosition(sourceCell), getCellPosition(targetCell)); svg.querySelector('.gameboard').appendChild(line); - distanceCallback && distanceCallback(hexes.length - 1); + Observable.notify('distance', hexes.length - 1); } function moveBackOneStepInHistory(counter) { @@ -178,10 +178,6 @@ export function getUnits() { return soldier.getAllCounters(svg); } -export function setDistanceCallback(callback) { - distanceCallback = callback; -} - export function start(el) { svg = el; -- cgit v1.2.3