Pandaboard support for new 15-cubes in tandem with Grizzly
[SugarCubes.git] / Model.pde
index 33762464c3c4ed4eaa50cfa225fea6befac50021..264dff15ab10619e0c24e92e73afd8f04e0e856b 100644 (file)
--- a/Model.pde
+++ b/Model.pde
@@ -22,6 +22,8 @@ public static class Model extends LXModel {
   public final List<Cube> cubes;
   public final List<Face> faces;
   public final List<Strip> strips;
+  
+  public final Map<String, Cube> cubeTable;
 
   private final Cube[] _cubes;
 
@@ -35,8 +37,10 @@ public static class Model extends LXModel {
     List<Cube> cubeList = new ArrayList<Cube>();
     List<Face> faceList = new ArrayList<Face>();
     List<Strip> stripList = new ArrayList<Strip>();
+    Map<String, Cube> _cubeTable = new HashMap<String, Cube>();
     for (Cube cube : _cubes) {
       if (cube != null) {
+        _cubeTable.put(cube.id, cube);
         cubeList.add(cube);
         for (Face face : cube.faces) {
           faceList.add(face);
@@ -51,6 +55,7 @@ public static class Model extends LXModel {
     this.cubes = Collections.unmodifiableList(cubeList);
     this.faces = Collections.unmodifiableList(faceList);
     this.strips = Collections.unmodifiableList(stripList);
+    this.cubeTable = Collections.unmodifiableMap(_cubeTable);
   }
 
   private static class Fixture extends LXAbstractFixture {
@@ -75,12 +80,22 @@ public static class Model extends LXModel {
   public Cube getCubeByRawIndex(int index) {
     return _cubes[index];
   }
+  
+  public Cube getCubeById(String id) {
+    return this.cubeTable.get(id);
+  }
 }
 
 /**
  * Model of a set of cubes stacked in a tower
  */
 public static class Tower extends LXModel {
+  
+  /**
+   * Tower id
+   */
+  public final String id;
+  
   /**
    * Immutable list of cubes
    */
@@ -101,9 +116,11 @@ public static class Tower extends LXModel {
    * 
    * @param cubes Array of cubes
    */
-  public Tower(List<Cube> cubes) {
+  public Tower(String id, List<Cube> cubes) {
     super(cubes.toArray(new Cube[] {}));
 
+    this.id = id;
+
     List<Cube> cubeList = new ArrayList<Cube>();
     List<Face> faceList = new ArrayList<Face>();
     List<Strip> stripList = new ArrayList<Strip>();
@@ -150,6 +167,8 @@ public static class Cube extends LXModel {
     new Strip.Metrics(EDGE_HEIGHT, POINTS_PER_STRIP)
   );
 
+  public final String id;
+
   /**
    * Immutable list of all cube faces
    */
@@ -190,14 +209,12 @@ public static class Cube extends LXModel {
    */
   public final float rz;
 
-  public Cube(double x, double y, double z, double rx, double ry, double rz) {
-    this((float) x, (float) y, (float) z, (float) rx, (float) ry, (float) rz);
-  }
-
-  public Cube(float x, float y, float z, float rx, float ry, float rz) {
+  public Cube(String id, float x, float y, float z, float rx, float ry, float rz) {
     super(new Fixture(x, y, z, rx, ry, rz));
     Fixture fixture = (Fixture) this.fixtures.get(0);
 
+    this.id = id;
+
     while (rx < 0) rx += 360;
     while (ry < 0) ry += 360;
     while (rz < 0) rz += 360;