1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.objects;
|
21
|
|
22
|
import org.distorted.library.main.DistortedEffects;
|
23
|
import org.distorted.library.main.DistortedTexture;
|
24
|
import org.distorted.library.mesh.MeshRectangles;
|
25
|
import org.distorted.library.type.Static4D;
|
26
|
import org.distorted.main.R;
|
27
|
|
28
|
import java.lang.reflect.Field;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
|
32
|
public enum RubikObjectList
|
33
|
{
|
34
|
CUBE (
|
35
|
new int[][] {
|
36
|
{2 , 12, R.drawable.cube2} ,
|
37
|
{3 , 16, R.drawable.cube3} ,
|
38
|
{4 , 20, R.drawable.cube4} ,
|
39
|
{5 , 24, R.drawable.cube5}
|
40
|
},
|
41
|
RubikCube.class,
|
42
|
new RubikCubeMovement()
|
43
|
),
|
44
|
|
45
|
PYRA (
|
46
|
new int[][] {
|
47
|
{3 , 10, R.drawable.pyra3} ,
|
48
|
{4 , 15, R.drawable.pyra4} ,
|
49
|
{5 , 20, R.drawable.pyra5}
|
50
|
},
|
51
|
RubikPyraminx.class,
|
52
|
new RubikPyraminxMovement()
|
53
|
),
|
54
|
;
|
55
|
|
56
|
public static final int NUM_OBJECTS = values().length;
|
57
|
public static final int MAX_SIZE;
|
58
|
public static final int MAX_LEVEL;
|
59
|
|
60
|
private final int[] mObjectSizes, mMaxLevels, mIconIDs;
|
61
|
private final Class<? extends RubikObject> mObjectClass;
|
62
|
private final RubikObjectMovement mObjectMovementClass;
|
63
|
private static final RubikObjectList[] objects;
|
64
|
private static int mNumAll;
|
65
|
|
66
|
static
|
67
|
{
|
68
|
mNumAll = 0;
|
69
|
int size, i = 0;
|
70
|
objects = new RubikObjectList[NUM_OBJECTS];
|
71
|
int maxSize = Integer.MIN_VALUE;
|
72
|
int maxLevel = Integer.MIN_VALUE;
|
73
|
|
74
|
for(RubikObjectList object: RubikObjectList.values())
|
75
|
{
|
76
|
objects[i] = object;
|
77
|
i++;
|
78
|
size = object.mObjectSizes.length;
|
79
|
mNumAll += size;
|
80
|
if( size> maxSize ) maxSize = size;
|
81
|
|
82
|
for(int j=0; j<size; j++)
|
83
|
{
|
84
|
if( object.mMaxLevels[j] > maxLevel ) maxLevel = object.mMaxLevels[j];
|
85
|
}
|
86
|
}
|
87
|
|
88
|
MAX_SIZE = maxSize;
|
89
|
MAX_LEVEL= maxLevel;
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public static RubikObjectList getObject(int ordinal)
|
95
|
{
|
96
|
return objects[ordinal];
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public static int pack(int object, int sizeIndex)
|
102
|
{
|
103
|
int ret = 0;
|
104
|
for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
|
105
|
|
106
|
return ret+sizeIndex;
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
public static int unpackSizeIndex(int number)
|
112
|
{
|
113
|
int num;
|
114
|
|
115
|
for(int i=0; i<NUM_OBJECTS; i++)
|
116
|
{
|
117
|
num = objects[i].mObjectSizes.length;
|
118
|
if( number<num ) return number;
|
119
|
number -= num;
|
120
|
}
|
121
|
|
122
|
return -1;
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
public static int unpackObject(int number)
|
128
|
{
|
129
|
int num;
|
130
|
|
131
|
for(int i=0; i<NUM_OBJECTS; i++)
|
132
|
{
|
133
|
num = objects[i].mObjectSizes.length;
|
134
|
if( number<num ) return i;
|
135
|
number -= num;
|
136
|
}
|
137
|
|
138
|
return -1;
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
public static int unpackObjectFromString(String obj)
|
144
|
{
|
145
|
int u = obj.indexOf('_');
|
146
|
int l = obj.length();
|
147
|
|
148
|
if( u>0 )
|
149
|
{
|
150
|
String name = obj.substring(0,u);
|
151
|
int size = Integer.parseInt( obj.substring(u+1,l) );
|
152
|
|
153
|
for(int i=0; i<NUM_OBJECTS; i++)
|
154
|
{
|
155
|
if( objects[i].name().equals(name) )
|
156
|
{
|
157
|
int sizeIndex = getSizeIndex(i,size);
|
158
|
return pack(i,sizeIndex);
|
159
|
}
|
160
|
}
|
161
|
}
|
162
|
|
163
|
return -1;
|
164
|
}
|
165
|
|
166
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167
|
|
168
|
public static String getObjectList()
|
169
|
{
|
170
|
String name;
|
171
|
StringBuilder list = new StringBuilder();
|
172
|
int len;
|
173
|
int[] sizes;
|
174
|
|
175
|
for(int i=0; i<NUM_OBJECTS; i++)
|
176
|
{
|
177
|
sizes = objects[i].mObjectSizes;
|
178
|
len = sizes.length;
|
179
|
name = objects[i].name();
|
180
|
|
181
|
for(int j=0; j<len; j++)
|
182
|
{
|
183
|
if( i>0 || j>0 ) list.append(',');
|
184
|
list.append(name);
|
185
|
list.append('_');
|
186
|
list.append(sizes[j]);
|
187
|
}
|
188
|
}
|
189
|
|
190
|
return list.toString();
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
public static int getTotal()
|
196
|
{
|
197
|
return mNumAll;
|
198
|
}
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
public static int getMaxLevel(int ordinal, int sizeIndex)
|
203
|
{
|
204
|
if( ordinal>=0 && ordinal<NUM_OBJECTS )
|
205
|
{
|
206
|
int num = objects[ordinal].mObjectSizes.length;
|
207
|
return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mMaxLevels[sizeIndex] : 0;
|
208
|
}
|
209
|
|
210
|
return 0;
|
211
|
}
|
212
|
|
213
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214
|
|
215
|
public static int getOrdinal(String name)
|
216
|
{
|
217
|
for(int i=0; i<NUM_OBJECTS; i++)
|
218
|
{
|
219
|
if(objects[i].name().equals(name)) return i;
|
220
|
}
|
221
|
|
222
|
return -1;
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
public static int getSizeIndex(int ordinal, int size)
|
228
|
{
|
229
|
int[] sizes = objects[ordinal].getSizes();
|
230
|
int len = sizes.length;
|
231
|
|
232
|
for(int i=0; i<len; i++)
|
233
|
{
|
234
|
if( sizes[i]==size ) return i;
|
235
|
}
|
236
|
|
237
|
return -1;
|
238
|
}
|
239
|
|
240
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
241
|
|
242
|
public static int[] retFaceColors(RubikObjectList object)
|
243
|
{
|
244
|
Field field;
|
245
|
int[] faceColors=null;
|
246
|
|
247
|
try
|
248
|
{
|
249
|
field = object.mObjectClass.getDeclaredField("FACE_COLORS");
|
250
|
field.setAccessible(true);
|
251
|
Object obj = field.get(null);
|
252
|
faceColors = (int[]) obj;
|
253
|
}
|
254
|
catch(NoSuchFieldException ex)
|
255
|
{
|
256
|
android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": no such field exception getting field: "+ex.getMessage());
|
257
|
}
|
258
|
catch(IllegalAccessException ex)
|
259
|
{
|
260
|
android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": illegal access exception getting field: "+ex.getMessage());
|
261
|
}
|
262
|
|
263
|
return faceColors;
|
264
|
}
|
265
|
|
266
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267
|
|
268
|
RubikObjectList(int[][] info, Class<? extends RubikObject> object , RubikObjectMovement movement)
|
269
|
{
|
270
|
int length = info.length;
|
271
|
|
272
|
mObjectSizes= new int[length];
|
273
|
mMaxLevels = new int[length];
|
274
|
mIconIDs = new int[length];
|
275
|
|
276
|
for(int i=0; i<length; i++)
|
277
|
{
|
278
|
mObjectSizes[i] = info[i][0];
|
279
|
mMaxLevels[i] = info[i][1];
|
280
|
mIconIDs[i] = info[i][2];
|
281
|
}
|
282
|
|
283
|
mObjectClass = object;
|
284
|
mObjectMovementClass = movement;
|
285
|
}
|
286
|
|
287
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
288
|
|
289
|
public int[] getSizes()
|
290
|
{
|
291
|
return mObjectSizes;
|
292
|
}
|
293
|
|
294
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
295
|
|
296
|
public int[] getMaxLevels()
|
297
|
{
|
298
|
return mMaxLevels;
|
299
|
}
|
300
|
|
301
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
302
|
|
303
|
public int[] getIconIDs()
|
304
|
{
|
305
|
return mIconIDs;
|
306
|
}
|
307
|
|
308
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
309
|
|
310
|
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, int[][] moves)
|
311
|
{
|
312
|
DistortedTexture texture = new DistortedTexture();
|
313
|
DistortedEffects effects = new DistortedEffects();
|
314
|
MeshRectangles mesh = new MeshRectangles(20,20); // mesh of the node, not of the cubits
|
315
|
|
316
|
switch(ordinal())
|
317
|
{
|
318
|
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects, moves);
|
319
|
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects, moves);
|
320
|
}
|
321
|
|
322
|
return null;
|
323
|
}
|
324
|
|
325
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
326
|
|
327
|
public RubikObjectMovement getObjectMovementClass()
|
328
|
{
|
329
|
return mObjectMovementClass;
|
330
|
}
|
331
|
}
|