diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-05 09:30:42 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:57 +0200 |
| commit | 42778e8be409b97059fa519b53c303cdba502e01 (patch) | |
| tree | 23d03a1f8a9f8d137bf723c72086a6d79406874f /src/util/tile-calculations.js | |
| parent | 6f3afd0317a8e549f77ad6764f6dbe4d4953b67c (diff) | |
Implement rack creation
Diffstat (limited to 'src/util/tile-calculations.js')
| -rw-r--r-- | src/util/tile-calculations.js | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/util/tile-calculations.js b/src/util/tile-calculations.js index 4d81dd31..71442941 100644 --- a/src/util/tile-calculations.js +++ b/src/util/tile-calculations.js @@ -164,31 +164,25 @@ export function deriveValidNextTilePositions(rooms, selectedTiles) { } export function findPositionInPositions(positions, positionX, positionY) { - let index = -1; - for (let i = 0; i < positions.length; i++) { const position = positions[i]; if (positionX === position.x && positionY === position.y) { - index = i; - break; + return i; } } - return index; + return -1; } export function findPositionInRooms(rooms, positionX, positionY) { - let index = -1; - for (let i = 0; i < rooms.length; i++) { const room = rooms[i]; if (findPositionInTiles(room.tiles, positionX, positionY) !== -1) { - index = i; - break; + return i; } } - return index; + return -1; } function findPositionInTiles(tiles, positionX, positionY) { @@ -204,3 +198,13 @@ function findPositionInTiles(tiles, positionX, positionY) { return index; } + +export function findTileWithPosition(tiles, positionX, positionY) { + for (let i = 0; i < tiles.length; i++) { + if (tiles[i].positionX === positionX && tiles[i].positionY === positionY) { + return tiles[i]; + } + } + + return null; +} |
