X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=blobdiff_plain;f=Model.pde;h=264dff15ab10619e0c24e92e73afd8f04e0e856b;hp=33762464c3c4ed4eaa50cfa225fea6befac50021;hb=bffb6a80f723b2795e47e56a7d8eb3d65e9324a5;hpb=30624e974f88224b0a8719b11bd649578eb97ab6 diff --git a/Model.pde b/Model.pde index 3376246..264dff1 100644 --- a/Model.pde +++ b/Model.pde @@ -22,6 +22,8 @@ public static class Model extends LXModel { public final List cubes; public final List faces; public final List strips; + + public final Map cubeTable; private final Cube[] _cubes; @@ -35,8 +37,10 @@ public static class Model extends LXModel { List cubeList = new ArrayList(); List faceList = new ArrayList(); List stripList = new ArrayList(); + Map _cubeTable = new HashMap(); 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 cubes) { + public Tower(String id, List cubes) { super(cubes.toArray(new Cube[] {})); + this.id = id; + List cubeList = new ArrayList(); List faceList = new ArrayList(); List stripList = new ArrayList(); @@ -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;