Skip to content

Commit

Permalink
Remove lastVistedColumn in favor of pendingChipColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Jul 11, 2019
1 parent 83024a3 commit 40b4a87
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions app/scripts/components/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class GridComponent extends Emitter {
// room or reloads the page
this.game.on('grid:align-pending-chip-initially', ({ column }) => {
this.pendingChipColumn = this.getChipWidth() * column;
this.lastVisitedColumn = this.pendingChipColumn;
m.redraw();
});
// Add a global listener here for all moves we will receive from the
Expand Down Expand Up @@ -60,17 +59,13 @@ class GridComponent extends Emitter {
reset() {
// The cached width of a single chip
this.resetCachedChipWidth();
// Current CSS position of the pending chip
this.pendingChipColumn = 0;
this.pendingChipRow = this.grid.rowCount;
// Booleans indicating when to transition the pending chip's movement in a
// particular direction (for example, the pending chip should never
// transition when resetting to its initial position after placing a chip)
this.transitionPendingChipX = false;
this.transitionPendingChipY = false;
// The current CSS position of the column where the user's cursor/finger
// last clicked/touched
this.lastVisitedColumn = 0;
}

resetCachedChipWidth() {
Expand Down Expand Up @@ -117,12 +112,11 @@ class GridComponent extends Emitter {
// The last visited column is the grid column nearest to the cursor at
// any given instant; keep track of the column's X position so the next
// pending chip can instantaneously appear there
if (column !== this.lastVisitedColumn) {
if (column !== this.pendingChipColumn) {
if (emit) {
this.emitAlignEvent({ column });
}
this.lastVisitedColumn = column;
this.pendingChipColumn = this.lastVisitedColumn;
this.pendingChipColumn = column;
this.pendingChipRow = this.grid.rowCount;
this.transitionPendingChipX = true;
this.transitionPendingChipY = false;
Expand Down Expand Up @@ -195,10 +189,6 @@ class GridComponent extends Emitter {
// Otherwise, chip is already aligned; drop chip into place on grid
this.transitionPendingChipX = false;
this.transitionPendingChipY = true;
// Keep track of where chip was dropped
this.lastVisitedColumn = column;
// Translate chip to the visual position on the grid corresponding to
// the above column and row
this.pendingChipColumn = column;
this.pendingChipRow = row;
// Perform insertion on internal game grid once transition has ended
Expand Down Expand Up @@ -236,9 +226,6 @@ class GridComponent extends Emitter {
this.game.placePendingChip({ column });
this.transitionPendingChipX = false;
this.transitionPendingChipY = false;
// Reset position of pending chip to the space directly above the last
// visited column
this.pendingChipColumn = this.lastVisitedColumn;
this.pendingChipRow = this.grid.rowCount;
this.resetCachedChipWidth();
m.redraw();
Expand Down

0 comments on commit 40b4a87

Please sign in to comment.