looks like maps are finally wrapping properly

This commit is contained in:
Gavin McDonald
2019-01-04 22:03:05 -05:00
parent c77f179ad3
commit d1b76727c8
3 changed files with 189 additions and 4 deletions

View File

@@ -8,6 +8,160 @@ import Point from './point.js';
const tilePointToHex = ({tilePoint, pixelPoint}) => ({tilePoint: new Hex(tilePoint), pixelPoint}); const tilePointToHex = ({tilePoint, pixelPoint}) => ({tilePoint: new Hex(tilePoint), pixelPoint});
window.debugged = -1;
const positive3x3 = [{
x: 0,
y: 0,
z: 0,
}, {
x: 1,
y: 0,
z: -1,
}, {
x: 2,
y: -1,
z: -1,
}, {
x: 0,
y: -1,
z: 1,
}, {
x: 1,
y: -1,
z: 0,
}, {
x: 2,
y: -2,
z: 0,
}, {
x: 0,
y: -2,
z: 2,
}, {
x: 1,
y: -2,
z: 1,
}, {
x: 2,
y: -3,
z: 1,
}];
const positiveEast3x3 = [{
x: 3,
y: -2,
z: -1,
}, {
x: 4,
y: -2,
z: -2,
}, {
x: 5,
y: -3,
z: -2,
}, {
x: 3,
y: -3,
z: 0,
}, {
x: 4,
y: -3,
z: -1,
}, {
x: 5,
y: -4,
z: -1,
}, {
x: 3,
y: -4,
z: 1,
}, {
x: 4,
y: -4,
z: 0,
}, {
x: 5,
y: -5,
z: 0,
}];
const positiveMiddleEast3x3 = [{
x: 6,
y: -4,
z: -2,
}, {
x: 7,
y: -4,
z: -3,
}, {
x: 8,
y: -5,
z: -3,
}, {
x: 6,
y: -5,
z: -1,
}, {
x: 7,
y: -5,
z: -2,
}, {
x: 8,
y: -6,
z: -2,
}, {
x: 6,
y: -6,
z: 0,
}, {
x: 7,
y: -6,
z: -1,
}, {
x: 8,
y: -7,
z: -1,
}];
const positiveFarEast3x3 = [{
x: 9,
y: -6,
z: -3,
}, {
x: 10,
y: -6,
z: -4,
}, {
x: 11,
y: -7,
z: -4,
}, {
x: 9,
y: -7,
z: -2,
}, {
x: 10,
y: -7,
z: -3,
}, {
x: 11,
y: -8,
z: -3,
}, {
x: 9,
y: -8,
z: -1,
}, {
x: 10,
y: -8,
z: -2,
}, {
x: 11,
y: -9,
z: -2,
}];
export default class CartographerFlatXYZ extends Cartographer { export default class CartographerFlatXYZ extends Cartographer {
constructor(settings) { constructor(settings) {
super(settings); super(settings);
@@ -106,6 +260,18 @@ export default class CartographerFlatXYZ extends Cartographer {
if (this.radius) { if (this.radius) {
} }
else { else {
// ensure odd-width maps wrap properly
if (this.width % 2) {
const offset = Math.floor(col / this.width);
let verticalAdjust = offset / 2;
verticalAdjust = offset % 2 === 0 ? verticalAdjust :
col % 2 ? Math.ceil(verticalAdjust) :
Math.floor(verticalAdjust);
row -= verticalAdjust;
}
const halfWidth = Math.floor(this.width / 2); const halfWidth = Math.floor(this.width / 2);
const halfHeight = Math.floor(this.height / 2); const halfHeight = Math.floor(this.height / 2);
@@ -157,6 +323,7 @@ export default class CartographerFlatXYZ extends Cartographer {
} }
boundingBox(upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) { boundingBox(upperLeftPoint, upperRightPoint, lowerLeftPoint, lowerRightPoint) {
window.debugged++;
const upperLeftTile = this._pixelToTile(upperLeftPoint); const upperLeftTile = this._pixelToTile(upperLeftPoint);
const lowerLeftTile = this._pixelToTile(lowerLeftPoint); const lowerLeftTile = this._pixelToTile(lowerLeftPoint);
const lowerRightTile = this._pixelToTile(lowerRightPoint); const lowerRightTile = this._pixelToTile(lowerRightPoint);
@@ -184,9 +351,27 @@ export default class CartographerFlatXYZ extends Cartographer {
.value(); .value();
}; };
// if (debugged < 1) {
//
// [positive3x3, positiveEast3x3, positiveMiddleEast3x3, positiveFarEast3x3].forEach(set => {
// set.forEach((input, index) => {
// const result = this.teleport(input, true);
//
// if (result.x === positive3x3[index].x && result.y === positive3x3[index].y && result.z === positive3x3[index].z) console.log(input, '->', positive3x3[index]);
// else console.log(input, '><', positive3x3[index], result);
// console.log('---------------------------------------------------');
// });
//
// console.log('-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
// });
// }
return funky.chain(columns) return funky.chain(columns)
.log(() => window.debugged < 1)
.map(processRow) .map(processRow)
.log(() => window.debugged < 1)
.flatten() .flatten()
.log(() => window.debugged < 1)
.value(); .value();
} }
} }

View File

@@ -1,7 +1,7 @@
export function chain (obj) { export function chain (obj) {
let chainInstance = { let chainInstance = {
log: function () { log: function (predicate = () => true) {
console.log(obj); if (predicate(obj)) console.log(obj);
return chainInstance; return chainInstance;
}, },

View File

@@ -134,7 +134,7 @@ class Demo {
if (this.map[key]) { if (this.map[key]) {
this.map[key].pips = Tessellate.utils.random(1, pipMax); this.map[key].pips = Tessellate.utils.random(1, pipMax);
console.log(key); console.log(`{${ x }, ${ y }${ z != null ? `, ${ z }` : ''}}`);
} }
else { else {
console.log('ERROR - no tile', key); console.log('ERROR - no tile', key);