From b1d29cf888745c847e3332b938936464405404f7 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 14 Nov 2014 17:27:33 -0800 Subject: [PATCH] user data cleanup --- examples/entityScripts/chessPiece.js | 16 +++++----------- examples/playChess.js | 23 ++--------------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/examples/entityScripts/chessPiece.js b/examples/entityScripts/chessPiece.js index ebe2df7e55..f3e2c2aef3 100644 --- a/examples/entityScripts/chessPiece.js +++ b/examples/entityScripts/chessPiece.js @@ -1,8 +1,6 @@ (function(){ this.FIRST_TILE = null; // Global position of the first tile (1a) this.TILE_SIZE = null; // Size of one tile - this.whitesDeadPieces = null; - this.blacksDeadPieces = null; this.wantDebug = false; this.active = false; @@ -59,16 +57,11 @@ if (!(this.boardUserData && this.boardUserData.firstTile && - this.boardUserData.tileSize && - this.boardUserData.whitesDeadPieces && - this.boardUserData.blacksDeadPieces && - this.boardUserData.pieces)) { + this.boardUserData.tileSize)) { print("Incomplete boardUserData " + this.boardID.id); } else { this.FIRST_TILE = this.boardUserData.firstTile; this.TILE_SIZE = this.boardUserData.tileSize; - this.whitesDeadPieces = this.boardUserData.whitesDeadPieces; - this.blacksDeadPieces = this.boardUserData.blacksDeadPieces; this.active = true; } @@ -139,9 +132,10 @@ } this.moveDeadPiece = function() { var myPos = this.getIndexPosition(this.properties.position); - - for (var i = 0; i < this.boardUserData.pieces.length; i++) { - var piece = this.boardUserData.pieces[i]; + var others = Entities.findEntities(this.properties.position, this.properties.dimensions.y); + + for (var i = 0; i < others.length; i++) { + var piece = others[i]; if (piece.id != this.entityID.id) { var properties = Entities.getEntityProperties(piece); diff --git a/examples/playChess.js b/examples/playChess.js index 1b6882ed6e..57ed24f342 100644 --- a/examples/playChess.js +++ b/examples/playChess.js @@ -79,8 +79,7 @@ ChessGame.Board = (function(position, scale) { firstTile: this.tilePosition(1, 1), tileSize: this.tileSize, whitesDeadPieces: this.tilePosition(0,0), - blacksDeadPieces: this.tilePosition(9,9), - pieces: new Array() + blacksDeadPieces: this.tilePosition(9,9) } this.entityProperties = { type: "Model", @@ -242,25 +241,7 @@ ChessGame.update = function() { for(var j = 1; j <= 8; j++) { ChessGame.makePiece(ChessGame.PAWN, row - 1, j, isWhite); } - } - - if (ChessGame.pieces.length > 0) { - var unknown = 0; - ChessGame.board.userDataObject.pieces = new Array(); - for(var i = 0; i < ChessGame.pieces.length; i++) { - ChessGame.pieces[i].entity = Entities.identifyEntity(ChessGame.pieces[i].entity); - if (ChessGame.pieces[i].entity.isKnownID) { - ChessGame.board.userDataObject.pieces.push(ChessGame.pieces[i].entity) - } else { - unknown++; - } - } - ChessGame.board.updateUserData(); - - if (unknown === 0) { - print("Board complete"); - Script.update.disconnect(ChessGame.update); - } + Script.update.disconnect(ChessGame.update); } }