more straightforward approach to providing location data for wrapped maps

This commit is contained in:
Gavin McDonald
2019-01-12 22:50:36 -05:00
parent a5bcda516a
commit 064bf10e98
7 changed files with 132 additions and 101 deletions

View File

@@ -10,6 +10,8 @@ const DEFAULTS = {
tile: Tessellate.TILE_STYLES.HEX,
};
const keyTemplate = ({x, y, z}) => `${ x },${ z != null ? z : y }`;
const pressRipple = function() {
const sinStart = 2 * Math.PI;
const halfPi = Math.PI / 2;
@@ -125,16 +127,14 @@ class Demo {
}
tap(tap) {
const {x, y, z} = tap.tile.getPoint();
const key = `${ x },${ z != null ? z : y }`;
const key = keyTemplate(tap.mapTile);
const pipMax = this.settings.tile === Tessellate.TILE_STYLES.HEX ? 7 : 9;
if (this.map[key]) {
this.map[key].pips = Tessellate.utils.random(1, pipMax);
console.log(`{${ x }, ${ y }${ z != null ? `, ${ z }` : ''}}`);
console.log(tap.mapTile.getPoint());
}
else {
console.log('ERROR - no tile', key);
@@ -165,19 +165,18 @@ class Demo {
});
if (tap.event.mobile) {
this.togglemine(tap.tile)
this.togglemine(tap.mapTile)
}
}
press(tap) {
if (!tap.event.mobile) {
this.togglemine(tap.tile)
this.togglemine(tap.mapTile)
}
}
togglemine(tile) {
const {x, y, z} = tile.getPoint();
const key = `${ x },${ z != null ? z : y }`;
const key = keyTemplate(tile);
if (this.mines[key]) {
delete this.mines[key];
@@ -227,16 +226,16 @@ class Demo {
}
drawTile(pointGroup, context, scale) {
const {x, y, z} = pointGroup.tilePoint;
const pixelX = pointGroup.pixelPoint.getX();
const pixelY = pointGroup.pixelPoint.getY();
this.counts[0] += 1;
const key = `${ x },${ z != null ? z : y }`;
const key = keyTemplate(pointGroup.mapPoint);
this.map[key] = this.map[key] || this.createTile({
x, y,
x: pointGroup.mapPoint.x,
y: pointGroup.mapPoint.y,
drawStyle: this.settings.style,
tileStyle: this.settings.tile,
orientation: this.settings.orientation,
@@ -249,7 +248,7 @@ class Demo {
Tessellate.TILES[tile.tileStyle][tile.drawStyle](context, scale, pixelX, pixelY, tile);
if (this.mined) {
if (this.mined || this.mines[key]) {
this.counts[2] += 1;
Tessellate.Shapes.mine(context, scale, pixelX, pixelY);
}
@@ -284,7 +283,9 @@ class Demo {
blue: 128,
});
pointGroups.forEach(pointGroup => this.drawTile(pointGroup, context, scale));
pointGroups
.filter(pointGroup => pointGroup.mapPoint)
.forEach(pointGroup => this.drawTile(pointGroup, context, scale));
this.ripples.forEach(({timestamp, cell}) => {
const pressFactor = Math.min((now - timestamp) / PRESS_RIPPLE, 1);
@@ -292,21 +293,21 @@ class Demo {
Object.assign(cell, {scale: pressRipple(pressFactor)});
Object.assign(cell.color, {alpha: pressFade(pressFactor)});
const pixelPoint = this.tessellate.tileToPixel(cell.x, cell.y);
const pixelPoint = this.tessellate.tileToPixel(cell);
Tessellate.TILES[cell.tileStyle][cell.drawStyle](context, scale, pixelPoint.getX(), pixelPoint.getY(), cell);
});
this.ripples = this.ripples.filter(ripple => (ripple.timestamp + PRESS_RIPPLE) > now);
this.taps.forEach(cell => {
const pixelPoint = this.tessellate.tileToPixel(cell.x, cell.y);
const pixelPoint = this.tessellate.tileToPixel(cell);
Tessellate.TILES[cell.tileStyle][cell.drawStyle](context, scale, pixelPoint.getX(), pixelPoint.getY(), cell);
});
Tessellate.funky.forEach(this.mines, cell => {
this.counts[2] += 1;
const pixelPoint = this.tessellate.tileToPixel(cell.x, cell.y);
Tessellate.Shapes.mine(context, scale, pixelPoint.getX(), pixelPoint.getY());
});
// Tessellate.funky.forEach(this.mines, cell => {
// this.counts[2] += 1;
// const pixelPoint = this.tessellate.tileToPixel(cell);
// Tessellate.Shapes.mine(context, scale, pixelPoint.getX(), pixelPoint.getY());
// });
this.fps.frame(now, lastNow, this.counts);
}