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 android.content.res.Resources;
|
23
|
|
24
|
import org.distorted.library.main.DistortedEffects;
|
25
|
import org.distorted.library.main.DistortedTexture;
|
26
|
import org.distorted.library.mesh.MeshSquare;
|
27
|
import org.distorted.library.type.Static4D;
|
28
|
import org.distorted.main.R;
|
29
|
import org.distorted.main.RubikActivity;
|
30
|
|
31
|
import java.lang.reflect.Field;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public enum RubikObjectList
|
36
|
{
|
37
|
CUBE (
|
38
|
new int[][] {
|
39
|
{2 , 12, R.raw.cube2, R.drawable.ui_small_cube2, R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2} ,
|
40
|
{3 , 16, R.raw.cube3, R.drawable.ui_small_cube3, R.drawable.ui_medium_cube3, R.drawable.ui_big_cube3, R.drawable.ui_huge_cube3} ,
|
41
|
{4 , 20, R.raw.cube4, R.drawable.ui_small_cube4, R.drawable.ui_medium_cube4, R.drawable.ui_big_cube4, R.drawable.ui_huge_cube4} ,
|
42
|
{5 , 24, R.raw.cube5, R.drawable.ui_small_cube5, R.drawable.ui_medium_cube5, R.drawable.ui_big_cube5, R.drawable.ui_huge_cube5}
|
43
|
},
|
44
|
RubikCube.class,
|
45
|
new RubikMovementCube(),
|
46
|
0
|
47
|
),
|
48
|
|
49
|
PYRA (
|
50
|
new int[][] {
|
51
|
{3 , 10, R.raw.pyra3, R.drawable.ui_small_pyra3, R.drawable.ui_medium_pyra3, R.drawable.ui_big_pyra3, R.drawable.ui_huge_pyra3} ,
|
52
|
{4 , 15, R.raw.pyra4, R.drawable.ui_small_pyra4, R.drawable.ui_medium_pyra4, R.drawable.ui_big_pyra4, R.drawable.ui_huge_pyra4} ,
|
53
|
{5 , 20, R.raw.pyra5, R.drawable.ui_small_pyra5, R.drawable.ui_medium_pyra5, R.drawable.ui_big_pyra5, R.drawable.ui_huge_pyra5}
|
54
|
},
|
55
|
RubikPyraminx.class,
|
56
|
new RubikMovementPyraminx(),
|
57
|
1
|
58
|
),
|
59
|
|
60
|
DINO (
|
61
|
new int[][] {
|
62
|
{3 , 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
|
63
|
},
|
64
|
RubikDino.class,
|
65
|
new RubikMovementDino(),
|
66
|
2
|
67
|
),
|
68
|
|
69
|
SKEW (
|
70
|
new int[][] {
|
71
|
{2 , 11, R.raw.dino, R.drawable.ui_small_skewb, R.drawable.ui_medium_skewb, R.drawable.ui_big_skewb, R.drawable.ui_huge_skewb} ,
|
72
|
},
|
73
|
RubikSkewb.class,
|
74
|
new RubikMovementSkewb(),
|
75
|
2
|
76
|
),
|
77
|
;
|
78
|
|
79
|
public static final int NUM_OBJECTS = values().length;
|
80
|
public static final int MAX_NUM_OBJECTS;
|
81
|
public static final int MAX_LEVEL;
|
82
|
public static final int MAX_OBJECT_SIZE;
|
83
|
|
84
|
private final int[] mObjectSizes, mMaxLevels, mSmallIconIDs, mMediumIconIDs, mBigIconIDs, mHugeIconIDs, mResourceIDs;
|
85
|
private final Class<? extends RubikObject> mObjectClass;
|
86
|
private final RubikMovement mObjectMovementClass;
|
87
|
private final int mColumn, mNumSizes;
|
88
|
|
89
|
private static final RubikObjectList[] objects;
|
90
|
private static int mNumAll;
|
91
|
private static int[] mIndices;
|
92
|
private static int mColCount, mRowCount;
|
93
|
|
94
|
static
|
95
|
{
|
96
|
mNumAll = 0;
|
97
|
int num, i = 0;
|
98
|
objects = new RubikObjectList[NUM_OBJECTS];
|
99
|
int maxNum = Integer.MIN_VALUE;
|
100
|
int maxLevel= Integer.MIN_VALUE;
|
101
|
int maxSize = Integer.MIN_VALUE;
|
102
|
|
103
|
for(RubikObjectList object: RubikObjectList.values())
|
104
|
{
|
105
|
objects[i] = object;
|
106
|
i++;
|
107
|
num = object.mObjectSizes.length;
|
108
|
mNumAll += num;
|
109
|
if( num> maxNum ) maxNum = num;
|
110
|
|
111
|
for(int j=0; j<num; j++)
|
112
|
{
|
113
|
if( object.mMaxLevels[j] > maxLevel ) maxLevel = object.mMaxLevels[j];
|
114
|
if( object.mObjectSizes[j] > maxSize) maxSize = object.mObjectSizes[j];
|
115
|
}
|
116
|
}
|
117
|
|
118
|
MAX_NUM_OBJECTS = maxNum;
|
119
|
MAX_LEVEL = maxLevel;
|
120
|
MAX_OBJECT_SIZE = maxSize;
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
private static void setUpColAndRow()
|
126
|
{
|
127
|
mIndices = new int[NUM_OBJECTS];
|
128
|
mColCount= 0;
|
129
|
|
130
|
for(int obj=0; obj<NUM_OBJECTS; obj++)
|
131
|
{
|
132
|
mIndices[obj] = objects[obj].mColumn;
|
133
|
if( mIndices[obj]>=mColCount ) mColCount = mIndices[obj]+1;
|
134
|
}
|
135
|
|
136
|
mRowCount = 0;
|
137
|
|
138
|
for(int col=0; col<mColCount; col++)
|
139
|
{
|
140
|
int numObjects = computeNumObjectsInColumn(col);
|
141
|
if( numObjects>mRowCount ) mRowCount = numObjects;
|
142
|
}
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
private static int computeNumObjectsInColumn(int column)
|
148
|
{
|
149
|
int num=0;
|
150
|
|
151
|
for(int object=0; object<NUM_OBJECTS; object++)
|
152
|
{
|
153
|
if( objects[object].mColumn == column )
|
154
|
{
|
155
|
num += objects[object].mNumSizes;
|
156
|
}
|
157
|
}
|
158
|
|
159
|
return num;
|
160
|
}
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
|
164
|
public static int getColumnCount()
|
165
|
{
|
166
|
if( mIndices==null ) setUpColAndRow();
|
167
|
|
168
|
return mColCount;
|
169
|
}
|
170
|
|
171
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172
|
|
173
|
public static int getRowCount()
|
174
|
{
|
175
|
if( mIndices==null ) setUpColAndRow();
|
176
|
|
177
|
return mRowCount;
|
178
|
}
|
179
|
|
180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181
|
|
182
|
public static int[] getIndices()
|
183
|
{
|
184
|
if( mIndices==null ) setUpColAndRow();
|
185
|
|
186
|
return mIndices;
|
187
|
}
|
188
|
|
189
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190
|
|
191
|
public static RubikObjectList getObject(int ordinal)
|
192
|
{
|
193
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE;
|
194
|
}
|
195
|
|
196
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197
|
|
198
|
public static int pack(int object, int sizeIndex)
|
199
|
{
|
200
|
int ret = 0;
|
201
|
for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
|
202
|
|
203
|
return ret+sizeIndex;
|
204
|
}
|
205
|
|
206
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
207
|
|
208
|
public static int unpackSizeIndex(int number)
|
209
|
{
|
210
|
int num;
|
211
|
|
212
|
for(int i=0; i<NUM_OBJECTS; i++)
|
213
|
{
|
214
|
num = objects[i].mObjectSizes.length;
|
215
|
if( number<num ) return number;
|
216
|
number -= num;
|
217
|
}
|
218
|
|
219
|
return -1;
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
|
224
|
public static int unpackObject(int number)
|
225
|
{
|
226
|
int num;
|
227
|
|
228
|
for(int i=0; i<NUM_OBJECTS; i++)
|
229
|
{
|
230
|
num = objects[i].mObjectSizes.length;
|
231
|
if( number<num ) return i;
|
232
|
number -= num;
|
233
|
}
|
234
|
|
235
|
return -1;
|
236
|
}
|
237
|
|
238
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239
|
|
240
|
public static int unpackObjectFromString(String obj)
|
241
|
{
|
242
|
int u = obj.indexOf('_');
|
243
|
int l = obj.length();
|
244
|
|
245
|
if( u>0 )
|
246
|
{
|
247
|
String name = obj.substring(0,u);
|
248
|
int size = Integer.parseInt( obj.substring(u+1,l) );
|
249
|
|
250
|
for(int i=0; i<NUM_OBJECTS; i++)
|
251
|
{
|
252
|
if( objects[i].name().equals(name) )
|
253
|
{
|
254
|
int sizeIndex = getSizeIndex(i,size);
|
255
|
return pack(i,sizeIndex);
|
256
|
}
|
257
|
}
|
258
|
}
|
259
|
|
260
|
return -1;
|
261
|
}
|
262
|
|
263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264
|
|
265
|
public static String getObjectList()
|
266
|
{
|
267
|
String name;
|
268
|
StringBuilder list = new StringBuilder();
|
269
|
int len;
|
270
|
int[] sizes;
|
271
|
|
272
|
for(int i=0; i<NUM_OBJECTS; i++)
|
273
|
{
|
274
|
sizes = objects[i].mObjectSizes;
|
275
|
len = sizes.length;
|
276
|
name = objects[i].name();
|
277
|
|
278
|
for(int j=0; j<len; j++)
|
279
|
{
|
280
|
if( i>0 || j>0 ) list.append(',');
|
281
|
list.append(name);
|
282
|
list.append('_');
|
283
|
list.append(sizes[j]);
|
284
|
}
|
285
|
}
|
286
|
|
287
|
return list.toString();
|
288
|
}
|
289
|
|
290
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
291
|
|
292
|
public static int getTotal()
|
293
|
{
|
294
|
return mNumAll;
|
295
|
}
|
296
|
|
297
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
298
|
|
299
|
public static int getMaxLevel(int ordinal, int sizeIndex)
|
300
|
{
|
301
|
if( ordinal>=0 && ordinal<NUM_OBJECTS )
|
302
|
{
|
303
|
int num = objects[ordinal].mObjectSizes.length;
|
304
|
return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mMaxLevels[sizeIndex] : 0;
|
305
|
}
|
306
|
|
307
|
return 0;
|
308
|
}
|
309
|
|
310
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
311
|
|
312
|
public static int getOrdinal(String name)
|
313
|
{
|
314
|
for(int i=0; i<NUM_OBJECTS; i++)
|
315
|
{
|
316
|
if(objects[i].name().equals(name)) return i;
|
317
|
}
|
318
|
|
319
|
return -1;
|
320
|
}
|
321
|
|
322
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
323
|
|
324
|
public static int getSizeIndex(int ordinal, int size)
|
325
|
{
|
326
|
if( ordinal>=0 && ordinal<NUM_OBJECTS )
|
327
|
{
|
328
|
int[] sizes = objects[ordinal].getSizes();
|
329
|
int len = sizes.length;
|
330
|
|
331
|
for(int i=0; i<len; i++)
|
332
|
{
|
333
|
if( sizes[i]==size ) return i;
|
334
|
}
|
335
|
}
|
336
|
|
337
|
return -1;
|
338
|
}
|
339
|
|
340
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
341
|
|
342
|
public static int[] retFaceColors(RubikObjectList object)
|
343
|
{
|
344
|
Field field;
|
345
|
int[] faceColors=null;
|
346
|
|
347
|
try
|
348
|
{
|
349
|
field = object.mObjectClass.getDeclaredField("FACE_COLORS");
|
350
|
field.setAccessible(true);
|
351
|
Object obj = field.get(null);
|
352
|
faceColors = (int[]) obj;
|
353
|
}
|
354
|
catch(NoSuchFieldException ex)
|
355
|
{
|
356
|
android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": no such field exception getting field: "+ex.getMessage());
|
357
|
}
|
358
|
catch(IllegalAccessException ex)
|
359
|
{
|
360
|
android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": illegal access exception getting field: "+ex.getMessage());
|
361
|
}
|
362
|
|
363
|
return faceColors;
|
364
|
}
|
365
|
|
366
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
367
|
|
368
|
RubikObjectList(int[][] info, Class<? extends RubikObject> object , RubikMovement movement, int column)
|
369
|
{
|
370
|
mNumSizes = info.length;
|
371
|
|
372
|
mObjectSizes = new int[mNumSizes];
|
373
|
mMaxLevels = new int[mNumSizes];
|
374
|
mResourceIDs = new int[mNumSizes];
|
375
|
mSmallIconIDs = new int[mNumSizes];
|
376
|
mMediumIconIDs= new int[mNumSizes];
|
377
|
mBigIconIDs = new int[mNumSizes];
|
378
|
mHugeIconIDs = new int[mNumSizes];
|
379
|
|
380
|
for(int i=0; i<mNumSizes; i++)
|
381
|
{
|
382
|
mObjectSizes[i] = info[i][0];
|
383
|
mMaxLevels[i] = info[i][1];
|
384
|
mResourceIDs[i] = info[i][2];
|
385
|
mSmallIconIDs[i] = info[i][3];
|
386
|
mMediumIconIDs[i]= info[i][4];
|
387
|
mBigIconIDs[i] = info[i][5];
|
388
|
mHugeIconIDs[i] = info[i][6];
|
389
|
}
|
390
|
|
391
|
mObjectClass = object;
|
392
|
mObjectMovementClass = movement;
|
393
|
mColumn = column;
|
394
|
}
|
395
|
|
396
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
397
|
|
398
|
public int[] getSizes()
|
399
|
{
|
400
|
return mObjectSizes;
|
401
|
}
|
402
|
|
403
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
404
|
|
405
|
public int[] getMaxLevels()
|
406
|
{
|
407
|
return mMaxLevels;
|
408
|
}
|
409
|
|
410
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
411
|
|
412
|
public int[] getIconIDs()
|
413
|
{
|
414
|
int size = RubikActivity.getDrawableSize();
|
415
|
|
416
|
switch(size)
|
417
|
{
|
418
|
case 0 : return mSmallIconIDs;
|
419
|
case 1 : return mMediumIconIDs;
|
420
|
case 2 : return mBigIconIDs;
|
421
|
default: return mHugeIconIDs;
|
422
|
}
|
423
|
}
|
424
|
|
425
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
426
|
|
427
|
public int[] getResourceIDs()
|
428
|
{
|
429
|
return mResourceIDs;
|
430
|
}
|
431
|
|
432
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
433
|
|
434
|
public int getNumVariants()
|
435
|
{
|
436
|
return mObjectSizes.length;
|
437
|
}
|
438
|
|
439
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
440
|
|
441
|
public RubikObject create(int size, Static4D quat, int[][] moves, Resources res, int scrWidth)
|
442
|
{
|
443
|
DistortedTexture texture = new DistortedTexture();
|
444
|
DistortedEffects effects = new DistortedEffects();
|
445
|
MeshSquare mesh = new MeshSquare(20,20); // mesh of the node, not of the cubits
|
446
|
|
447
|
switch(ordinal())
|
448
|
{
|
449
|
case 0: return new RubikCube (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
450
|
case 1: return new RubikPyraminx(size, quat, texture, mesh, effects, moves, res, scrWidth);
|
451
|
case 2: return new RubikDino (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
452
|
case 3: return new RubikSkewb (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
453
|
}
|
454
|
|
455
|
return null;
|
456
|
}
|
457
|
|
458
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
459
|
|
460
|
public RubikMovement getObjectMovementClass()
|
461
|
{
|
462
|
return mObjectMovementClass;
|
463
|
}
|
464
|
}
|