make Drone.cuboida() async.

This commit is contained in:
walterhiggins 2014-03-11 21:35:59 +00:00
parent 7977dc0fb5
commit 7e435be565

View file

@ -1014,17 +1014,22 @@ Drone.extend( 'sign', function( message, block ) {
} }
}); });
Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite ) { Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite, immediate ) {
var len = blocks.length,
i = 0;
if ( !immediate ) {
for ( ; i < len; i++ ) {
blocks[i] = this._getBlockIdAndMeta( blocks[ i ] );
}
var clone = Drone.clone(this);
Drone.queue.push(this.cuboida.bind(clone, blocks, w, h, d, overwrite, true) );
return this;
}
if ( typeof overwrite == 'undefined' ) { if ( typeof overwrite == 'undefined' ) {
overwrite = true; overwrite = true;
} }
var properBlocks = [];
var len = blocks.length;
for ( var i = 0; i < len; i++ ) {
var bm = this._getBlockIdAndMeta( blocks[ i ] );
properBlocks.push( [ bm[0], bm[1] ] );
}
if ( typeof h == 'undefined' ) { if ( typeof h == 'undefined' ) {
h = 1; h = 1;
} }
@ -1037,14 +1042,11 @@ Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite ) {
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( ) {
_traverseHeight( that, h, function( ) { _traverseHeight( that, h, function( ) {
_traverse[dir].width( that, w, function( ) { _traverse[dir].width( that, w, function( ) {
var block = that.world.getBlockAt( that.x, that.y, that.z ); var block = that.world.getBlockAt( that.x, that.y, that.z );
var properBlock = properBlocks[ bi % len ]; var properBlock = blocks[ 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 );
} }
@ -1085,7 +1087,7 @@ Drone.prototype.cuboidX = function( blockType, meta, w, h, d, immediate ) {
if ( !immediate ) { if ( !immediate ) {
var clone = Drone.clone(this); var clone = Drone.clone(this);
Drone.queue.push(this.cuboidX.bind(clone, blockType, meta, w, h, d, true));; Drone.queue.push(this.cuboidX.bind(clone, blockType, meta, w, h, d, true));
return this; return this;
} }
var depthFunc = function( ) { var depthFunc = function( ) {
@ -1640,15 +1642,19 @@ var _getDirFromRotation = function( r ) {
return 1; // south return 1; // south
}; };
var _getBlockIdAndMeta = function( b ) { var _getBlockIdAndMeta = function( b ) {
var defaultMeta = 0; var defaultMeta = 0,
i = 0,
bs,
md,
sp;
if ( typeof b == 'string' ) { if ( typeof b == 'string' ) {
var bs = b; bs = b;
var sp = bs.indexOf(':' ); sp = bs.indexOf(':' );
if ( sp == -1 ) { if ( sp == -1 ) {
b = parseInt(bs ); b = parseInt(bs );
// wph 20130414 - use sensible defaults for certain blocks e.g. stairs // wph 20130414 - use sensible defaults for certain blocks e.g. stairs
// should face the drone. // should face the drone.
for ( var i in blocks.stairs ) { for ( i in blocks.stairs ) {
if ( blocks.stairs[i] === b ) { if ( blocks.stairs[i] === b ) {
defaultMeta = Drone.PLAYER_STAIRS_FACING[this.dir]; defaultMeta = Drone.PLAYER_STAIRS_FACING[this.dir];
break; break;
@ -1657,12 +1663,12 @@ var _getBlockIdAndMeta = function(b ) {
return [ b, defaultMeta ]; return [ b, defaultMeta ];
} }
b = parseInt(bs.substring(0,sp ) ); b = parseInt(bs.substring(0,sp ) );
var md = parseInt(bs.substring(sp+1,bs.length ) ); md = parseInt(bs.substring(sp+1,bs.length ) );
return [b,md]; return [b,md];
}else{ }else{
// wph 20130414 - use sensible defaults for certain blocks e.g. stairs // wph 20130414 - use sensible defaults for certain blocks e.g. stairs
// should face the drone. // should face the drone.
for ( var i in blocks.stairs ) { for ( i in blocks.stairs ) {
if ( blocks.stairs[i] === b ) { if ( blocks.stairs[i] === b ) {
defaultMeta = Drone.PLAYER_STAIRS_FACING[this.dir]; defaultMeta = Drone.PLAYER_STAIRS_FACING[this.dir];
break; break;