Browse Source

spawning and collapsing at the same time

Justin Gilman 1 year ago
parent
commit
e269b91942
1 changed files with 20 additions and 14 deletions
  1. 20 14
      js/libraries/components/matchthree/Board.js

+ 20 - 14
js/libraries/components/matchthree/Board.js

@@ -193,27 +193,33 @@ class Board {
             }
         }
 
-        this.actionQueue.execute(SpawnTileAction, (x, y) => this.spawnTile(x, y)).then(() => {
-            for (let x = 0; x < this.boardSize.x; x++) {
-                const columnTiles = this.tiles.filter((tile) => tile.position.x == x).sort((tileA, tileB) => tileA.position.y < tileB.position.y)
+        this.collapse()
 
-                let bottom = this.boardSize.y
-                columnTiles.forEach((tile, index) => {
-                    if (tile.position.y < bottom) {
-                        bottom -= 1
-                        this.actionQueue.push(new TileFallAction(tile, bottom))
-
-                    }
-                })
-            }
-
-            this.actionQueue.execute(TileFallAction).then(() => {
+        this.actionQueue.execute(SpawnTileAction, (x, y) => this.spawnTile(x, y)).then(() => {
+            this.collapse().then(() => {
                 this.checkForMatches()
             })
         })
        
 
     }
+
+    collapse() {
+        for (let x = 0; x < this.boardSize.x; x++) {
+            const columnTiles = this.tiles.filter((tile) => tile.position.x == x).sort((tileA, tileB) => tileA.position.y < tileB.position.y)
+
+            let bottom = this.boardSize.y
+            columnTiles.forEach((tile, index) => {
+                if (tile.position.y < bottom) {
+                    bottom -= 1
+                    this.actionQueue.push(new TileFallAction(tile, bottom))
+
+                }
+            })
+        }
+
+        return this.actionQueue.execute(TileFallAction)
+    }
 }
 
 Board.TILE_PADDING = 4