From 8bad63493571e3d3807ffc972efa00a97c3fe0ec Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 3 Jun 2015 15:26:00 -0700 Subject: [PATCH] callback in cell adds --- js/cells/DMACell.js | 2 +- js/lattice/CubeLattice.js | 6 ++++-- js/lattice/GIKLattice.js | 6 ++++-- js/lattice/KelvinLattice.js | 6 ++++-- js/lattice/Lattice.js | 21 +++++++++++++-------- js/lattice/OctaEdgeLattice.js | 6 ++++-- js/lattice/OctaFaceLattice.js | 10 ++++------ js/lattice/OctaRotEdgeLattice.js | 6 ++++-- js/lattice/OctaVertexLattice.js | 6 ++++-- js/lattice/TruncatedCubeLattice.js | 6 ++++-- js/main.js | 10 +++++----- 11 files changed, 51 insertions(+), 34 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index c233b4c5..a091d557 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -48,7 +48,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], DMACell.prototype.getIndex = function(){ var index = this.index.clone(); - console.log(index); +// console.log(index); index = this.getAbsoluteOrientation(index); if (this.superCell) index.add(this.superCell.getIndex()); return index; diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js index 222d5612..1fae3a4a 100644 --- a/js/lattice/CubeLattice.js +++ b/js/lattice/CubeLattice.js @@ -38,9 +38,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return 1+2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['cubeCell'], function(CubeCell){ - return new CubeCell(indices); + var cell = new CubeCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index 0acb937d..be5d8ff0 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -39,9 +39,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return 1.28*(1+2*cellSeparation); }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['gikSuperCell'], function(GIKSuperCell){ - return new GIKSuperCell(indices); + var cell = new GIKSuperCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js index 917af049..c67998c2 100644 --- a/js/lattice/KelvinLattice.js +++ b/js/lattice/KelvinLattice.js @@ -39,9 +39,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return 2*Math.sqrt(2)+2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['kelvinCell'], function(KelvinCell){ - return new KelvinCell(indices); + var cell = new KelvinCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 2b7bf1cb..b17a97d6 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -64,10 +64,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre for (var y=relativeMin.y;y<=relativeMax.y;y++){ for (var z=relativeMin.z;z<=relativeMax.z;z++){ if (!cells[x][y][z]) { - var cell = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin)); - cells[x][y][z] = cell; - newCells.push(cell); - this.set("numCells", this.get("numCells")+1); + var self = this; + var callback = function(cell){ + newCells.push(cell); + self.set("numCells", self.get("numCells")+1); + }; + cells[x][y][z] = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin), callback); } else console.warn("already a cell there"); } } @@ -79,13 +81,16 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre addCellAtIndex: function(indices, noRender, noCheck){//no render no check from fill var cells = this.get("cells"); - if (!noCheck) this.checkForMatrixExpansion(cells, indices, indices); + if (!noCheck || noCheck === undefined) this.checkForMatrixExpansion(cells, indices, indices); var index = this._subtract(indices, this.get("cellsMin")); if (!cells[index.x][index.y][index.z]) { - cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices); - this.set("numCells", this.get("numCells")+1); - if (!noRender || noRender === undefined) three.render(); + var self = this; + var callback = function(){ + self.set("numCells", self.get("numCells")+1); + if (!noRender || noRender === undefined) three.render(); + }; + cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, callback); } else console.warn("already a cell there"); }, diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js index 94f88b55..8dabb82f 100644 --- a/js/lattice/OctaEdgeLattice.js +++ b/js/lattice/OctaEdgeLattice.js @@ -64,9 +64,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return 2/Math.sqrt(6)+2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['octaEdgeCell'], function(OctaEdgeCell){ - return new OctaEdgeCell(indices); + var cell = new OctaEdgeCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js index b2667cd4..58203379 100644 --- a/js/lattice/OctaFaceLattice.js +++ b/js/lattice/OctaFaceLattice.js @@ -47,9 +47,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return 2/Math.sqrt(6)+2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['octaFaceCell'], function(OctaFaceCell){ - return new OctaFaceCell(indices); + var cell = new OctaFaceCell(indices); + if (callback) callback(cell); + return cell; }); }, @@ -61,9 +63,5 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th } }; - _.each(_.keys(OctaFaceLattice), function(key){ - console.log(key); - }); - return OctaFaceLattice; }); diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js index ed8a0cd5..7b5d359b 100644 --- a/js/lattice/OctaRotEdgeLattice.js +++ b/js/lattice/OctaRotEdgeLattice.js @@ -50,9 +50,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return Math.sqrt(2)/2 + 2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['octaRotEdgeCell'], function(OctaRotEdgeCell){ - return new OctaRotEdgeCell(indices); + var cell = new OctaRotEdgeCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js index a8f254f3..babdeecf 100644 --- a/js/lattice/OctaVertexLattice.js +++ b/js/lattice/OctaVertexLattice.js @@ -46,9 +46,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return Math.sqrt(2)+2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['octaVertexCell'], function(OctaVertexCell){ - return new OctaVertexCell(indices); + var cell = new OctaVertexCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js index 485507d5..7ba455af 100644 --- a/js/lattice/TruncatedCubeLattice.js +++ b/js/lattice/TruncatedCubeLattice.js @@ -39,9 +39,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th return Math.sqrt(2)+2*cellSeparation; }, - makeCellForLatticeType: function(indices){ + makeCellForLatticeType: function(indices, callback){ require(['truncatedCubeCell'], function(TruncatedCubeCell){ - return new TruncatedCubeCell(indices); + var cell = new TruncatedCubeCell(indices); + if (callback) callback(cell); + return cell; }); }, diff --git a/js/main.js b/js/main.js index eb0b60f7..1182e50b 100644 --- a/js/main.js +++ b/js/main.js @@ -102,11 +102,11 @@ require.config({ }); -require.onError = function (err) { - console.log(err.requireType); - console.log(err.requireModules); - throw err; -}; +//require.onError = function (err) { +// console.log(err.requireType); +// console.log(err.requireModules); +// throw err; +//}; //init stuff require(['appState', 'lattice', 'menuWrapper', 'navbar', 'ribbon', 'threeModel', 'threeView', 'flatUI'], -- GitLab