From 496e063b6afdfb3853c75433d3937064fab26886 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 10 Jun 2015 21:39:45 -0700
Subject: [PATCH] eod

---
 js/lattice/CompositeEditorLattice.js | 33 ++++++++++++++++++----------
 js/menus/CompositeMenu.js            |  2 ++
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js
index 732517ae..fa56e321 100644
--- a/js/lattice/CompositeEditorLattice.js
+++ b/js/lattice/CompositeEditorLattice.js
@@ -6,24 +6,25 @@
 define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'],
     function(_, Backbone, appState, lattice, globals, plist, THREE, three){
 
-    var defaults = {
-        compositeId: null,
-        compositeColor: makeRandomColor(),
-        numCompositeCells:0,
-        compositeCellsMin: null,
-        compositeCellsMax: null
-    };
-
     function makeRandomColor(){
         return '#' + Math.floor(Math.random()*16777215).toString(16);
     }
 
-    var CompositeEditorLattice = {
-
+    var defaults = {};
+    var compositeId = 0;
 
+    var CompositeEditorLattice = {
 
         _initCompositeEditor: function(id, data){
 
+            _.extend(defaults, {
+                compositeId: "composite" + compositeId++,//todo real unique id
+                compositeColor: makeRandomColor(),
+                numCompositeCells:0,
+                compositeCellsMin: null,
+                compositeCellsMax: null
+            });
+
             var self = this;
             _.each(_.keys(defaults), function(key){
                 self.set(key, defaults[key], {silent:true});
@@ -34,7 +35,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
                 _.each(_.keys(data), function(key){
                     self.set(key, defaults[key], {silent:true});
                 });
-                this.compositeCells = data.cells;//todo
+                this.compositeCells = data.cells;//todo parse cells
                 this.set("compositeId", id, {silent:true});
             }
         },
@@ -43,13 +44,20 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
             this.set("compositeColor", makeRandomColor());
         },
 
-        _makeNewCompositeMaterial: function(name){
+        makeNewCompositeMaterial: function(name){
+            if (this.get("numCompositeCells") == 0) {
+                console.warn("no cells in this composite");
+                return;
+            }
             var id = this.get("compositeId");
             var data = {
                 name: name,
                 color: this.get("compositeColor"),
                 altColor: this.get("compositeColor"),
                 numCells: this.get("numCompositeCells"),
+                cells: JSON.stringify(this.get("compositeCells")),
+                cellsMin: this.get("compositeCellsMin").clone(),
+                cellsMax: this.get("compositeCellsMax").clone(),
                 dimensions: new THREE.Vector3.subVectors(this.get("compositeCellsMax"), this.get("compositeCellsMin"))
             };
             globals.materials.id = data;//todo trigger change on all instances
@@ -65,6 +73,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
                 self.unset(key, {silent:true});
             });
             this.compositeCells = null;
+            console.log("done undo");
         }
     };
 
diff --git a/js/menus/CompositeMenu.js b/js/menus/CompositeMenu.js
index 0557449a..00854a77 100644
--- a/js/menus/CompositeMenu.js
+++ b/js/menus/CompositeMenu.js
@@ -31,6 +31,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _
 
         _finishComposite: function(e){
             e.preventDefault();
+            console.log("here");
+            lattice.makeNewCompositeMaterial();
             this.model.set("currentNav", "navDesign");
         },
 
-- 
GitLab