Bläddra i källkod

fixing actionqueue action tween handling; adding additional filtering to checkForMatches; removing matched tiles once they finish

Justin Gilman 1 år sedan
förälder
incheckning
51efdb7bfb
2 ändrade filer med 23 tillägg och 14 borttagningar
  1. 11 11
      js/libraries/ActionQueue.js
  2. 12 3
      js/libraries/components/matchthree/Board.js

+ 11 - 11
js/libraries/ActionQueue.js

@@ -29,7 +29,7 @@ export class SwapTileAction {
     constructor(firstTile, otherTile) {
         this.firstTile = firstTile
         this.otherTile = otherTile
-        this.tween = []
+        this.tweens = []
     }
 
     execute(isAllowedCallback = () => true) {
@@ -41,10 +41,10 @@ export class SwapTileAction {
             this.tweens = [
                 AsyncTween.create(this.firstTile.position, this.otherTile.position, 500, Easing.Elastic.EaseOut),
                 AsyncTween.create(this.otherTile.position, this.firstTile.position, 500, Easing.Elastic.EaseOut)]
-            Promise.all(this.tweens.map((tween) => tween.promise))
-                .then(() => {
-                    resolve()
-                })
+            Promise.all(this.tweens.map((tween) => tween.promise)).then(() => {
+                resolve()
+                this.tweens = []
+            })
         })
     }
 }
@@ -52,7 +52,7 @@ export class SwapTileAction {
 export class MatchTilesAction {
     constructor(tilesToMatch) {
         this.tilesToMatch = tilesToMatch
-        this.tween = []
+        this.tweens = []
     }
 
     execute(isAllowedCallback = () => true) {
@@ -63,12 +63,12 @@ export class MatchTilesAction {
             }
             this.tweens = []
             this.tilesToMatch.forEach((tile) => {
-                this.tween.push(AsyncTween.create(tile, {scale: 0}, 500, Easing.Quadratic.EaseInOut))
+                this.tweens.push(AsyncTween.create(tile, {scale: 0}, 500, Easing.Quadratic.EaseInOut))
+            })
+            Promise.all(this.tweens.map((tween) => tween.promise)).then(() => {
+                resolve()
+                this.tweens = []
             })
-            Promise.all(this.tweens.map((tween) => tween.promise))
-                .then(() => {
-                    resolve()
-                })
         })
     }
 }

+ 12 - 3
js/libraries/components/matchthree/Board.js

@@ -146,10 +146,11 @@ class Board {
             if(tilesToPop.includes(tile)) {
                 return
             }
-            const validTiles = this.tiles.filter((checkedTile) => tile.type == checkedTile.type && checkedTile.position.y == tile.position.y && (checkedTile.position.x == tile.position.x + 1 || checkedTile.position.x == tile.position.x - 1))
+            const validTiles = this.tiles.filter((checkedTile) => tile != checkedTile && tile.type == checkedTile.type && checkedTile.position.y == tile.position.y && (checkedTile.position.x == tile.position.x + 1 || checkedTile.position.x == tile.position.x - 1))
             if(validTiles.length == 2) {
                 tilesToPop.push(tile, ...validTiles)
                 this.actionQueue.push(new MatchTilesAction([tile, ...validTiles]))
+                return
             }
         })
         //three in a row vertical
@@ -157,10 +158,11 @@ class Board {
             if(tilesToPop.includes(tile)) {
                 return
             }
-            const validTiles = this.tiles.filter((checkedTile) => tile.type == checkedTile.type && checkedTile.position.x == tile.position.x && (checkedTile.position.y == tile.position.y + 1 || checkedTile.position.y == tile.position.y - 1))
+            const validTiles = this.tiles.filter((checkedTile) => tile != checkedTile && tile.type == checkedTile.type && checkedTile.position.x == tile.position.x && (checkedTile.position.y == tile.position.y + 1 || checkedTile.position.y == tile.position.y - 1))
             if(validTiles.length == 2) {
                 tilesToPop.push(tile, ...validTiles)
                 this.actionQueue.push(new MatchTilesAction([tile, ...validTiles]))
+                return
             }
         })
 
@@ -168,11 +170,18 @@ class Board {
             tile.isSelected = true
         })
 
-        this.actionQueue.execute(MatchTilesAction)
+        this.actionQueue.execute(MatchTilesAction).then(() => {
+            this.cascade()
+            this.tiles = this.tiles.filter((tile) => !tilesToPop.includes(tile))
+        })
         //push matches into poplist
 
         // this.popAndCascade(tilesToPop)
     }
+
+    cascade() {
+
+    }
 }
 
 Board.TILE_PADDING = 4