Skip to content

Commit

Permalink
Twist logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Dec 24, 2024
1 parent 3f4f668 commit d2f983a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 52 deletions.
11 changes: 0 additions & 11 deletions plugins/board/miniboard/moveto/MoveTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ class MoveTo extends TickTask {
return this;
}

moveAlongLine(startX, startY, endX, endY) {
if (startX !== undefined) {
this.parent.x = startX;
}
if (startY !== undefined) {
this.parent.y = startY;
}
this.moveToTask.moveTo(endX, endY);
return this;
};

update(time, delta) {
if ((!this.isRunning) || (!this.enable)) {
return this;
Expand Down
40 changes: 3 additions & 37 deletions plugins/board/moveto/MoveTo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import TickTask from '../../utils/componentbase/SceneUpdateTickTask.js';
import Methods from './Methods.js';
import MoveToTask from '../../behaviors/moveto/MoveTo.js';
import MoveToTask from './movetotask/MoveToTask.js';
import MoveNextLine from './movetotask/MoveNextLine.js';
import GetChessData from '../chess/GetChessData.js';
import GetValue from '../../utils/object/GetValue.js';

Expand Down Expand Up @@ -153,41 +154,6 @@ class MoveTo extends TickTask {
return this;
}

moveAlongLine(startX, startY, endX, endY) {
if (startX !== undefined) {
this.parent.x = startX;
}
if (startY !== undefined) {
this.parent.y = startY;
}
this.moveToTask.moveTo(endX, endY);
return this;
};

addMoveLine(startX, startY, endX, endY) {
if (!this.moveToTask.hasOwnProperty('nextlines')) {
this.moveToTask.nextlines = [];
}
this.moveToTask.nextlines.push(
[startX, startY, endX, endY]
);
return this;
};

moveNextLine() {
var nextlines = this.moveToTask.nextlines;
if (!nextlines) {
return false;
}
if (nextlines.length === 0) {
return false;
}
// has next line
this.moveAlongLine.apply(this, nextlines[0]);
nextlines.length = 0;
return true;
}

update(time, delta) {
if ((!this.isRunning) || (!this.enable)) {
return this;
Expand All @@ -196,7 +162,7 @@ class MoveTo extends TickTask {
var moveToTask = this.moveToTask;
moveToTask.update(time, delta);
if (!moveToTask.isRunning) {
if (!this.moveNextLine()) {
if (!MoveNextLine.call(this)) {
this.complete();
}
return this;
Expand Down
10 changes: 6 additions & 4 deletions plugins/board/moveto/MoveToTile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import GetValue from '../../utils/object/GetValue.js';
import GetSneakTileZ from './GetSneakTileZ.js';
import MoveAloneLine from './movetotask/MoveAloneLine.js';
import AddMoveLine from './movetotask/AddMoveLine.js';

var MoveToTile = function (tileX, tileY, direction) {
var board = this.chessData.board;
Expand Down Expand Up @@ -55,7 +57,7 @@ var MoveToTile = function (tileX, tileY, direction) {
if ((neighborTileXY.x === tileX) && (neighborTileXY.y === tileY)) {
// not a wrapped neighbor
var out = board.tileXYToWorldXY(tileX, tileY, true);
this.moveAlongLine(undefined, undefined, out.x, out.y);
MoveAloneLine.call(this, undefined, undefined, out.x, out.y);
} else {
// wrapped neighbor
// line 0
Expand All @@ -67,7 +69,7 @@ var MoveToTile = function (tileX, tileY, direction) {
var startY = out.y;
var endX = (startX + originNeighborWorldX) / 2;
var endY = (startY + originNeighborWorldY) / 2;
this.moveAlongLine(undefined, undefined, endX, endY);
MoveAloneLine.call(this, undefined, undefined, endX, endY);
// line 1
var oppositeDirection = board.getOppositeDirection(tileX, tileY, direction);
board.grid.getNeighborTileXY(tileX, tileY, oppositeDirection, neighborTileXY);
Expand All @@ -79,11 +81,11 @@ var MoveToTile = function (tileX, tileY, direction) {
endY = out.y;
startX = (originNeighborWorldX + endX) / 2;
startY = (originNeighborWorldY + endY) / 2;
this.addMoveLine(startX, startY, endX, endY);
AddMoveLine.call(this, startX, startY, endX, endY);
}
} else {
var out = board.tileXYToWorldXY(tileX, tileY, true);
this.moveAlongLine(undefined, undefined, out.x, out.y);
MoveAloneLine.call(this, undefined, undefined, out.x, out.y);
}

var tileZ = myTileXYZ.z;
Expand Down
11 changes: 11 additions & 0 deletions plugins/board/moveto/movetotask/AddMoveLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var AddMoveLine = function (startX, startY, endX, endY) {
if (!this.moveToTask.hasOwnProperty('nextlines')) {
this.moveToTask.nextlines = [];
}
this.moveToTask.nextlines.push(
[startX, startY, endX, endY]
);
return this;
};

export default AddMoveLine;
12 changes: 12 additions & 0 deletions plugins/board/moveto/movetotask/MoveAloneLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var MoveAloneLine = function (startX, startY, endX, endY) {
if (startX !== undefined) {
this.parent.x = startX;
}
if (startY !== undefined) {
this.parent.y = startY;
}
this.moveToTask.moveTo(endX, endY);
return this;
};

export default MoveAloneLine;
17 changes: 17 additions & 0 deletions plugins/board/moveto/movetotask/MoveNextLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import MoveAloneLine from './MoveAloneLine.js';

var MoveNextLine = function () {
var nextlines = this.moveToTask.nextlines;
if (!nextlines) {
return false;
}
if (nextlines.length === 0) {
return false;
}
// has next line
MoveAloneLine.apply(this, nextlines[0]);
nextlines.length = 0;
return true;
}

export default MoveNextLine;
2 changes: 2 additions & 0 deletions plugins/board/moveto/movetotask/MoveToTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import MoveToTask from '../../../behaviors/moveto/MoveTo.js';
export default MoveToTask;

0 comments on commit d2f983a

Please sign in to comment.