Fixed a bug in boxa() drone method which caused chessboard() to fail (since move to async)
This commit is contained in:
parent
12ff59f2e5
commit
e874ba3ff6
1 changed files with 76 additions and 68 deletions
|
@ -692,6 +692,10 @@ Drone.processQueue = function(){
|
||||||
process();
|
process();
|
||||||
} catch( e ) {
|
} catch( e ) {
|
||||||
console.log('Drone build error: %s', e);
|
console.log('Drone build error: %s', e);
|
||||||
|
if (process.name){
|
||||||
|
console.log('while processing function ' + process.name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -715,6 +719,9 @@ addUnloadHandler( function() {
|
||||||
Drone.extend = function( name, func ) {
|
Drone.extend = function( name, func ) {
|
||||||
if (arguments.length == 1){
|
if (arguments.length == 1){
|
||||||
func = name;
|
func = name;
|
||||||
|
if ( !func.name ){
|
||||||
|
throw 'A Drone extension function must have a name!';
|
||||||
|
}
|
||||||
name = func.name;
|
name = func.name;
|
||||||
}
|
}
|
||||||
Drone.prototype[ '_' + name ] = func;
|
Drone.prototype[ '_' + name ] = func;
|
||||||
|
@ -808,12 +815,10 @@ Drone.prototype.times = function( numTimes, commands ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Drone.prototype._checkpoints = {};
|
Drone.prototype._checkpoints = {};
|
||||||
|
Drone.extend(function chkpt( name ) {
|
||||||
Drone.extend( 'chkpt', function( name ) {
|
|
||||||
this._checkpoints[ name ] = { x:this.x, y:this.y, z:this.z, dir:this.dir };
|
this._checkpoints[ name ] = { x:this.x, y:this.y, z:this.z, dir:this.dir };
|
||||||
});
|
});
|
||||||
|
Drone.extend(function move( ) {
|
||||||
Drone.extend( 'move', function( ) {
|
|
||||||
if ( arguments[0] instanceof bkLocation ) {
|
if ( arguments[0] instanceof bkLocation ) {
|
||||||
this.x = arguments[0].x;
|
this.x = arguments[0].x;
|
||||||
this.y = arguments[0].y;
|
this.y = arguments[0].y;
|
||||||
|
@ -843,7 +848,7 @@ Drone.extend( 'move', function( ) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Drone.extend( 'turn', function ( n ) {
|
Drone.extend( function turn( n ) {
|
||||||
if ( typeof n == 'undefined' ) {
|
if ( typeof n == 'undefined' ) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
|
@ -851,42 +856,42 @@ Drone.extend( 'turn', function ( n ) {
|
||||||
this.dir %=4;
|
this.dir %=4;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
Drone.extend( 'right', function( n ) {
|
Drone.extend( function right( n ) {
|
||||||
if ( typeof n == 'undefined' ) {
|
if ( typeof n == 'undefined' ) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
_movements[ this.dir ].right( this, n );
|
_movements[ this.dir ].right( this, n );
|
||||||
});
|
});
|
||||||
|
|
||||||
Drone.extend( 'left', function( n ) {
|
Drone.extend( function left( n ) {
|
||||||
if ( typeof n == 'undefined') {
|
if ( typeof n == 'undefined') {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
_movements[ this.dir ].left( this, n );
|
_movements[ this.dir ].left( this, n );
|
||||||
});
|
});
|
||||||
|
|
||||||
Drone.extend( 'fwd', function( n ) {
|
Drone.extend( function fwd( n ) {
|
||||||
if ( typeof n == 'undefined' ) {
|
if ( typeof n == 'undefined' ) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
_movements[ this.dir ].fwd( this, n );
|
_movements[ this.dir ].fwd( this, n );
|
||||||
});
|
});
|
||||||
|
|
||||||
Drone.extend( 'back', function( n ) {
|
Drone.extend( function back( n ) {
|
||||||
if ( typeof n == 'undefined' ) {
|
if ( typeof n == 'undefined' ) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
_movements[ this.dir ].back( this, n );
|
_movements[ this.dir ].back( this, n );
|
||||||
});
|
});
|
||||||
|
|
||||||
Drone.extend( 'up', function( n ) {
|
Drone.extend( function up( n ) {
|
||||||
if ( typeof n == 'undefined' ) {
|
if ( typeof n == 'undefined' ) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
this.y+= n;
|
this.y+= n;
|
||||||
});
|
});
|
||||||
|
|
||||||
Drone.extend( 'down', function( n ) {
|
Drone.extend( function down( n ) {
|
||||||
if ( typeof n == 'undefined' ) {
|
if ( typeof n == 'undefined' ) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
|
@ -901,7 +906,7 @@ Drone.prototype.getLocation = function( ) {
|
||||||
//
|
//
|
||||||
// building
|
// building
|
||||||
//
|
//
|
||||||
Drone.extend( 'sign', function( message, block ) {
|
Drone.extend( function sign( message, block ) {
|
||||||
if ( message.constructor != Array ) {
|
if ( message.constructor != Array ) {
|
||||||
message = [message];
|
message = [message];
|
||||||
}
|
}
|
||||||
|
@ -955,16 +960,20 @@ function getAllQueues() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite, immediate ) {
|
Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite, immediate ) {
|
||||||
|
//
|
||||||
var len = blocks.length,
|
// wph 20140823 make a copy because don't want to modify array in background
|
||||||
|
//
|
||||||
|
var blocksForBuild = blocks.slice();
|
||||||
|
var len = blocksForBuild.length,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if ( !immediate ) {
|
if ( !immediate ) {
|
||||||
for ( ; i < len; i++ ) {
|
for ( ; i < len; i++ ) {
|
||||||
blocks[i] = this._getBlockIdAndMeta( blocks[ i ] );
|
blocksForBuild[i] = this._getBlockIdAndMeta( blocksForBuild[ i ] );
|
||||||
}
|
}
|
||||||
var clone = Drone.clone(this);
|
var clone = Drone.clone(this);
|
||||||
getQueue(this).push(this.cuboida.bind(clone, blocks, w, h, d, overwrite, true) );
|
var impl = this.cuboida.bind(clone, blocksForBuild, w, h, d, overwrite, true);
|
||||||
|
getQueue(this).push( function cuboida(){ impl(); });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if ( typeof overwrite == 'undefined' ) {
|
if ( typeof overwrite == 'undefined' ) {
|
||||||
|
@ -982,11 +991,11 @@ Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite, immed
|
||||||
var that = this;
|
var that = this;
|
||||||
var dir = this.dir;
|
var dir = this.dir;
|
||||||
var bi = 0;
|
var bi = 0;
|
||||||
_traverse[dir].depth( that, d, function( ) {
|
_traverse[dir].depth( that, d, function traverseDepthCallback( ) {
|
||||||
_traverseHeight( that, h, function( ) {
|
traverseHeight( that, h, function traverseHeightCallback( ) {
|
||||||
_traverse[dir].width( that, w, function( ) {
|
_traverse[dir].width( that, w, function traverseWidthCallback( ) {
|
||||||
var block = that.world.getBlockAt( that.x, that.y, that.z );
|
var block = that.world.getBlockAt( that.x, that.y, that.z );
|
||||||
var properBlock = blocks[ bi % len ];
|
var properBlock = blocksForBuild[ bi % len ];
|
||||||
if (overwrite || block.type.equals(bkMaterial.AIR) ) {
|
if (overwrite || block.type.equals(bkMaterial.AIR) ) {
|
||||||
block.setTypeIdAndData( properBlock[0], properBlock[1], false );
|
block.setTypeIdAndData( properBlock[0], properBlock[1], false );
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1045,8 @@ Drone.prototype.cuboidX = function( blockType, meta, w, h, d, immediate ) {
|
||||||
|
|
||||||
if ( !immediate ) {
|
if ( !immediate ) {
|
||||||
var clone = Drone.clone(this);
|
var clone = Drone.clone(this);
|
||||||
getQueue(this).push(this.cuboidX.bind(clone, blockType, meta, w, h, d, true));
|
var impl = this.cuboidX.bind(clone, blockType, meta, w, h, d, true);
|
||||||
|
getQueue(this).push(function cuboidX(){ impl(); });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
var depthFunc = function( ) {
|
var depthFunc = function( ) {
|
||||||
|
@ -1052,7 +1062,7 @@ Drone.prototype.cuboidX = function( blockType, meta, w, h, d, immediate ) {
|
||||||
_traverse[dir].depth( that, d, depthFunc );
|
_traverse[dir].depth( that, d, depthFunc );
|
||||||
};
|
};
|
||||||
var widthFunc = function( ) {
|
var widthFunc = function( ) {
|
||||||
_traverseHeight( that, h, heightFunc );
|
traverseHeight( that, h, heightFunc );
|
||||||
};
|
};
|
||||||
_traverse[dir].width( that, w, widthFunc );
|
_traverse[dir].width( that, w, widthFunc );
|
||||||
return this;
|
return this;
|
||||||
|
@ -1080,7 +1090,7 @@ Drone.prototype.cuboid0 = function( block, w, h, d ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Drone.extend( 'door', function( doorMaterial ) {
|
Drone.extend( function door( doorMaterial ) {
|
||||||
if ( typeof doorMaterial == 'undefined' ) {
|
if ( typeof doorMaterial == 'undefined' ) {
|
||||||
doorMaterial = 64; // wood
|
doorMaterial = 64; // wood
|
||||||
} else {
|
} else {
|
||||||
|
@ -1092,14 +1102,14 @@ Drone.extend( 'door', function( doorMaterial ) {
|
||||||
.down( );
|
.down( );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
Drone.extend( 'door_iron', function( ) {
|
Drone.extend( function door_iron( ) {
|
||||||
this.cuboidX( 71, this.dir )
|
this.cuboidX( 71, this.dir )
|
||||||
.up( )
|
.up( )
|
||||||
.cuboidX( 71, 8 )
|
.cuboidX( 71, 8 )
|
||||||
.down( );
|
.down( );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
Drone.extend( 'door2' , function( doorMaterial ) {
|
Drone.extend( function door2( doorMaterial ) {
|
||||||
if ( typeof doorMaterial == 'undefined' ) {
|
if ( typeof doorMaterial == 'undefined' ) {
|
||||||
doorMaterial = 64;
|
doorMaterial = 64;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1111,7 +1121,7 @@ Drone.extend( 'door2' , function( doorMaterial ) {
|
||||||
.cuboidX( doorMaterial, 9 ).down( )
|
.cuboidX( doorMaterial, 9 ).down( )
|
||||||
.cuboidX( doorMaterial, this.dir ).left( );
|
.cuboidX( doorMaterial, this.dir ).left( );
|
||||||
} );
|
} );
|
||||||
Drone.extend( 'door2_iron' , function( ) {
|
Drone.extend( function door2_iron( ) {
|
||||||
this
|
this
|
||||||
.cuboidX( 71, this.dir ).up( )
|
.cuboidX( 71, this.dir ).up( )
|
||||||
.cuboidX( 71, 8 ).right( )
|
.cuboidX( 71, 8 ).right( )
|
||||||
|
@ -1141,7 +1151,7 @@ var _STAIRBLOCKS = {
|
||||||
//
|
//
|
||||||
// prism private implementation
|
// prism private implementation
|
||||||
//
|
//
|
||||||
var _prism = function( block, w, d ) {
|
function prism( block, w, d ) {
|
||||||
var stairEquiv = _STAIRBLOCKS[block];
|
var stairEquiv = _STAIRBLOCKS[block];
|
||||||
if ( stairEquiv ) {
|
if ( stairEquiv ) {
|
||||||
this.fwd( ).prism(stairEquiv,w,d-2 ).back( );
|
this.fwd( ).prism(stairEquiv,w,d-2 ).back( );
|
||||||
|
@ -1196,7 +1206,8 @@ var _prism = function( block, w, d ) {
|
||||||
//
|
//
|
||||||
// prism0 private implementation
|
// prism0 private implementation
|
||||||
//
|
//
|
||||||
var _prism0 = function( block,w,d ) {
|
;
|
||||||
|
Drone.extend( function prism0( block,w,d ) {
|
||||||
this.prism(block,w,d )
|
this.prism(block,w,d )
|
||||||
.fwd( ).right( )
|
.fwd( ).right( )
|
||||||
.prism(0,w-2,d-2 )
|
.prism(0,w-2,d-2 )
|
||||||
|
@ -1207,9 +1218,8 @@ var _prism0 = function( block,w,d ) {
|
||||||
var f = Math.floor(d/2 );
|
var f = Math.floor(d/2 );
|
||||||
this.fwd(f ).up(f ).cuboid(se,w ).down(f ).back(f );
|
this.fwd(f ).up(f ).cuboid(se,w ).down(f ).back(f );
|
||||||
}
|
}
|
||||||
};
|
} );
|
||||||
Drone.extend('prism0',_prism0 );
|
Drone.extend(prism);
|
||||||
Drone.extend('prism',_prism );
|
|
||||||
Drone.extend('box', Drone.prototype.cuboid );
|
Drone.extend('box', Drone.prototype.cuboid );
|
||||||
Drone.extend('box0',Drone.prototype.cuboid0 );
|
Drone.extend('box0',Drone.prototype.cuboid0 );
|
||||||
Drone.extend('boxa',Drone.prototype.cuboida );
|
Drone.extend('boxa',Drone.prototype.cuboida );
|
||||||
|
@ -1485,12 +1495,6 @@ var _cylinder1 = function( block,radius,height,exactParams ) {
|
||||||
};
|
};
|
||||||
var _paste = function( name, immediate )
|
var _paste = function( name, immediate )
|
||||||
{
|
{
|
||||||
/* if ( !immediate ) {
|
|
||||||
var clone = Drone.clone(this);
|
|
||||||
getQueue(this).push(this.paste.bind(clone, name, true) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
var ccContent = Drone.clipBoard[name];
|
var ccContent = Drone.clipBoard[name];
|
||||||
if (ccContent == undefined){
|
if (ccContent == undefined){
|
||||||
|
@ -1504,7 +1508,7 @@ var _paste = function( name, immediate )
|
||||||
|
|
||||||
_traverse[this.dir].width(that,srcBlocks.length,function( ww ) {
|
_traverse[this.dir].width(that,srcBlocks.length,function( ww ) {
|
||||||
var h = srcBlocks[ww].length;
|
var h = srcBlocks[ww].length;
|
||||||
_traverseHeight(that,h,function( hh ) {
|
traverseHeight(that,h,function( hh ) {
|
||||||
var d = srcBlocks[ww][hh].length;
|
var d = srcBlocks[ww][hh].length;
|
||||||
_traverse[that.dir].depth(that,d,function( dd ) {
|
_traverse[that.dir].depth(that,d,function( dd ) {
|
||||||
var b = srcBlocks[ww][hh][dd];
|
var b = srcBlocks[ww][hh][dd];
|
||||||
|
@ -1654,42 +1658,46 @@ _movements[3].fwd = _movements[0].left;
|
||||||
_movements[3].back = _movements[0].right;
|
_movements[3].back = _movements[0].right;
|
||||||
var _traverse = [{},{},{},{}];
|
var _traverse = [{},{},{},{}];
|
||||||
// east
|
// east
|
||||||
_traverse[0].width = function( that,n,callback ) {
|
function walkWidthEast( that,n,callback ) {
|
||||||
var s = that.z, e = s + n;
|
var s = that.z, e = s + n;
|
||||||
for ( ; that.z < e; that.z++ ) {
|
for ( ; that.z < e; that.z++ ) {
|
||||||
callback(that.z-s );
|
callback(that.z-s );
|
||||||
}
|
}
|
||||||
that.z = s;
|
that.z = s;
|
||||||
};
|
}
|
||||||
_traverse[0].depth = function( that,n,callback ) {
|
function walkDepthEast( that,n,callback ) {
|
||||||
var s = that.x, e = s+n;
|
var s = that.x, e = s+n;
|
||||||
for ( ;that.x < e;that.x++ ) {
|
for ( ;that.x < e;that.x++ ) {
|
||||||
callback(that.x-s );
|
callback(that.x-s );
|
||||||
}
|
}
|
||||||
that.x = s;
|
that.x = s;
|
||||||
};
|
}
|
||||||
// south
|
function walkWidthSouth( that,n,callback ) {
|
||||||
_traverse[1].width = function( that,n,callback ) {
|
|
||||||
var s = that.x, e = s-n;
|
var s = that.x, e = s-n;
|
||||||
for ( ;that.x > e;that.x-- ) {
|
for ( ;that.x > e;that.x-- ) {
|
||||||
callback(s-that.x );
|
callback(s-that.x );
|
||||||
}
|
}
|
||||||
that.x = s;
|
that.x = s;
|
||||||
};
|
}
|
||||||
_traverse[1].depth = _traverse[0].width;
|
function walkWidthWest( that,n,callback ) {
|
||||||
// west
|
|
||||||
_traverse[2].width = function( that,n,callback ) {
|
|
||||||
var s = that.z, e = s-n;
|
var s = that.z, e = s-n;
|
||||||
for ( ;that.z > e;that.z-- ) {
|
for ( ;that.z > e;that.z-- ) {
|
||||||
callback(s-that.z );
|
callback(s-that.z );
|
||||||
}
|
}
|
||||||
that.z = s;
|
that.z = s;
|
||||||
};
|
}
|
||||||
_traverse[2].depth = _traverse[1].width;
|
_traverse[0].width = walkWidthEast;
|
||||||
|
_traverse[0].depth = walkDepthEast;
|
||||||
|
// south
|
||||||
|
_traverse[1].width = walkWidthSouth;
|
||||||
|
_traverse[1].depth = walkWidthEast;
|
||||||
|
// west
|
||||||
|
_traverse[2].width = walkWidthWest;
|
||||||
|
_traverse[2].depth = walkWidthSouth;
|
||||||
// north
|
// north
|
||||||
_traverse[3].width = _traverse[0].depth;
|
_traverse[3].width = walkDepthEast;
|
||||||
_traverse[3].depth = _traverse[2].width;
|
_traverse[3].depth = walkWidthWest;
|
||||||
var _traverseHeight = function( that,n,callback ) {
|
function traverseHeight( that,n,callback ) {
|
||||||
var s = that.y, e = s + n;
|
var s = that.y, e = s + n;
|
||||||
for ( ; that.y < e; that.y++ ) {
|
for ( ; that.y < e; that.y++ ) {
|
||||||
callback(that.y-s );
|
callback(that.y-s );
|
||||||
|
@ -1699,7 +1707,7 @@ var _traverseHeight = function( that,n,callback ) {
|
||||||
//
|
//
|
||||||
// standard fisher-yates shuffle algorithm
|
// standard fisher-yates shuffle algorithm
|
||||||
//
|
//
|
||||||
var _fisherYates = function( myArray ) {
|
function fisherYates( myArray ) {
|
||||||
var i = myArray.length;
|
var i = myArray.length;
|
||||||
if ( i == 0 ) return false;
|
if ( i == 0 ) return false;
|
||||||
while ( --i ) {
|
while ( --i ) {
|
||||||
|
@ -1709,13 +1717,13 @@ var _fisherYates = function( myArray ) {
|
||||||
myArray[i] = tempj;
|
myArray[i] = tempj;
|
||||||
myArray[j] = tempi;
|
myArray[j] = tempi;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
var _copy = function( name, w, h, d ) {
|
var _copy = function( name, w, h, d ) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var ccContent = [];
|
var ccContent = [];
|
||||||
_traverse[this.dir].width(that,w,function( ww ) {
|
_traverse[this.dir].width(that,w,function( ww ) {
|
||||||
ccContent.push([] );
|
ccContent.push([] );
|
||||||
_traverseHeight(that,h,function( hh ) {
|
traverseHeight(that,h,function( hh ) {
|
||||||
ccContent[ww].push([] );
|
ccContent[ww].push([] );
|
||||||
_traverse[that.dir].depth(that,d,function( dd ) {
|
_traverse[that.dir].depth(that,d,function( dd ) {
|
||||||
var b = that.world.getBlockAt(that.x,that.y,that.z );
|
var b = that.world.getBlockAt(that.x,that.y,that.z );
|
||||||
|
@ -1768,7 +1776,7 @@ var _rand = function( blockDistribution ) {
|
||||||
// make array bigger so that it's more random
|
// make array bigger so that it's more random
|
||||||
blockDistribution = blockDistribution.concat(blockDistribution );
|
blockDistribution = blockDistribution.concat(blockDistribution );
|
||||||
}
|
}
|
||||||
_fisherYates(blockDistribution );
|
fisherYates(blockDistribution );
|
||||||
return blockDistribution;
|
return blockDistribution;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue