Skip to content

Commit

Permalink
Twist logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Dec 15, 2024
1 parent b0d1ec0 commit 97b60ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
5 changes: 0 additions & 5 deletions examples/board/boundaries.bat

This file was deleted.

5 changes: 5 additions & 0 deletions examples/board/edge-boundaries.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/board/edge-boundaries.js
cd ..
cd ..
npm run dev
24 changes: 10 additions & 14 deletions examples/board/boundaries.js → examples/board/edge-boundaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ class Demo extends Phaser.Scene {
height: 20
})

var lineManager = new Lines();
var edgeManager = new EdgeManager();
board
.forEachTileXY(function (tileXY, board) {
if (Math.random() < 0.5) {
var chess = this.rexBoard.add.shape(board, tileXY.x, tileXY.y, 0, 0x333333);
var points = board.getGridPoints(tileXY.x, tileXY.y, true);
for (var i = 0, cnt = points.length; i < cnt; i++) {
lineManager.add(points[i], points[(i + 1) % cnt]);
edgeManager.add(points[i], points[(i + 1) % cnt]);
}
}
}, this);

lineManager.draw(graphics, 2, 0xff0000, 1);
edgeManager.draw(graphics, 2, 0xff0000, 1);
}

update() { }
Expand Down Expand Up @@ -71,10 +71,9 @@ var getHexagonGrid = function (scene) {
return grid;
};

class Lines {
class EdgeManager {
constructor() {
this.lines = {};
this.duplicated = {};
this.edges = {};
}

add(p0, p1) {
Expand All @@ -88,23 +87,20 @@ class Lines {
}

var key = JSON.stringify(line);
if (key in this.duplicated) {
// Do nothing
} else if (key in this.lines) {
delete this.lines[key];
this.duplicated[key] = line;
if (key in this.edges) {
delete this.edges[key];
} else {
this.lines[key] = line;
this.edges[key] = line;
}

return this;
}

draw(graphics, lineWidth, color, alpha) {
for (var key in this.lines) {
for (var key in this.edges) {
graphics
.lineStyle(lineWidth, color, alpha)
.strokeLineShape(this.lines[key])
.strokeLineShape(this.edges[key])
}
return this;
}
Expand Down

0 comments on commit 97b60ef

Please sign in to comment.