Revision 4888e97c
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/object/RubikObjectList.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
public enum RubikObjectList |
31 | 31 |
{ |
32 |
CUBE2 ( 2, R.drawable.cube2, RubikCube.class, RubikCubeMovement.class), |
|
33 |
CUBE3 ( 3, R.drawable.cube3, RubikCube.class, RubikCubeMovement.class), |
|
34 |
CUBE4 ( 4, R.drawable.cube4, RubikCube.class, RubikCubeMovement.class), |
|
35 |
CUBE5 ( 5, R.drawable.cube5, RubikCube.class, RubikCubeMovement.class), |
|
32 |
CUBE ( new int[] {2,3,4}, |
|
33 |
new int[] {R.drawable.cube2,R.drawable.cube3,R.drawable.cube4}, |
|
34 |
new RubikCubeMovement() ), |
|
35 |
PYRAMINX ( new int[] {3,4}, |
|
36 |
new int[] {R.drawable.pyra3,R.drawable.pyra4}, |
|
37 |
new RubikPyraminxMovement() ), |
|
36 | 38 |
; |
37 | 39 |
|
38 |
public static final int LENGTH = values().length; |
|
39 |
private final int mObjectSize, mIconID; |
|
40 |
final Class<? extends RubikObject> mObjectClass; |
|
41 |
final Class<? extends RubikObjectMovement> mObjectMovementClass; |
|
40 |
public static final int NUM_OBJECTS = values().length; |
|
41 |
public static final int MAX_SIZE; |
|
42 |
|
|
43 |
private final int[] mObjectSizes, mIconIDs; |
|
44 |
final RubikObjectMovement mObjectMovementClass; |
|
42 | 45 |
private static final RubikObjectList[] objects; |
46 |
private static int mNumAll; |
|
43 | 47 |
|
44 | 48 |
static |
45 | 49 |
{ |
46 |
int i = 0; |
|
47 |
objects = new RubikObjectList[LENGTH]; |
|
50 |
mNumAll = 0; |
|
51 |
int size, i = 0; |
|
52 |
objects = new RubikObjectList[NUM_OBJECTS]; |
|
53 |
int maxsize = Integer.MIN_VALUE; |
|
48 | 54 |
|
49 |
for(RubikObjectList size: RubikObjectList.values())
|
|
55 |
for(RubikObjectList object: RubikObjectList.values())
|
|
50 | 56 |
{ |
51 |
objects[i] = size;
|
|
57 |
objects[i] = object;
|
|
52 | 58 |
i++; |
59 |
size = object.mObjectSizes.length; |
|
60 |
mNumAll += size; |
|
61 |
if( size> maxsize ) maxsize = size; |
|
53 | 62 |
} |
63 |
|
|
64 |
MAX_SIZE = maxsize; |
|
54 | 65 |
} |
55 | 66 |
|
56 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
62 | 73 |
|
63 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 75 |
|
65 |
RubikObjectList(int size, int iconID, Class<? extends RubikObject > object, Class<? extends RubikObjectMovement> movement) |
|
76 |
public static int pack(int object, int size) |
|
77 |
{ |
|
78 |
int ret = 0; |
|
79 |
for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length; |
|
80 |
|
|
81 |
return ret+size; |
|
82 |
} |
|
83 |
|
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
public static int unpackSize(int number) |
|
87 |
{ |
|
88 |
int num; |
|
89 |
|
|
90 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
91 |
{ |
|
92 |
num = objects[i].mObjectSizes.length; |
|
93 |
if( number<num ) return number; |
|
94 |
number -= num; |
|
95 |
} |
|
96 |
|
|
97 |
return -1; |
|
98 |
} |
|
99 |
|
|
100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 |
|
|
102 |
public static int unpackObject(int number) |
|
66 | 103 |
{ |
67 |
mObjectSize = size; |
|
68 |
mIconID = iconID; |
|
69 |
mObjectClass= object; |
|
104 |
int num; |
|
105 |
|
|
106 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
107 |
{ |
|
108 |
num = objects[i].mObjectSizes.length; |
|
109 |
if( number<num ) return i; |
|
110 |
number -= num; |
|
111 |
} |
|
112 |
|
|
113 |
return -1; |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
public static int getTotal() |
|
119 |
{ |
|
120 |
return mNumAll; |
|
121 |
} |
|
122 |
|
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
RubikObjectList(int[] sizes, int[] iconIDs, RubikObjectMovement movement) |
|
126 |
{ |
|
127 |
mObjectSizes= sizes; |
|
128 |
mIconIDs = iconIDs; |
|
70 | 129 |
mObjectMovementClass = movement; |
71 | 130 |
} |
72 | 131 |
|
73 | 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
74 | 133 |
|
75 |
public int getIconID()
|
|
134 |
public int[] getIconIDs()
|
|
76 | 135 |
{ |
77 |
return mIconID; |
|
136 |
return mIconIDs;
|
|
78 | 137 |
} |
79 | 138 |
|
80 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
81 |
// TODO - currently all objects in the list are RubikCubes of various sizes |
|
82 | 140 |
|
83 |
public RubikObject create(Static4D quatCur, Static4D quatAcc) |
|
141 |
public int[] getSizes() |
|
142 |
{ |
|
143 |
return mObjectSizes; |
|
144 |
} |
|
145 |
|
|
146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 |
|
|
148 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc) |
|
84 | 149 |
{ |
85 | 150 |
DistortedTexture texture = new DistortedTexture(); |
86 | 151 |
DistortedEffects effects = new DistortedEffects(); |
87 | 152 |
MeshRectangles mesh = new MeshRectangles(20,20); // mesh of the node, not of the cubits |
88 | 153 |
|
89 |
return new RubikPyraminx(mObjectSize, quatCur, quatAcc, texture, mesh, effects); |
|
154 |
switch(ordinal()) |
|
155 |
{ |
|
156 |
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects); |
|
157 |
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects); |
|
158 |
} |
|
159 |
|
|
160 |
return null; |
|
90 | 161 |
} |
91 | 162 |
|
92 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
93 |
// TODO - currently all objects in the list are RubikCubes of various sizes |
|
94 | 164 |
|
95 | 165 |
public RubikObjectMovement getObjectMovementClass() |
96 | 166 |
{ |
97 |
return new RubikPyraminxMovement();
|
|
167 |
return mObjectMovementClass;
|
|
98 | 168 |
} |
99 | 169 |
} |
Also available in: Unified diff
Major restructuring around making it possible to include different kinds of RubikObjects in the UI.