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 ObjectList
|
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
|
TwistyCube.class,
|
45
|
new MovementCube(),
|
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
|
TwistyPyraminx.class,
|
56
|
new MovementPyraminx(),
|
57
|
1
|
58
|
),
|
59
|
|
60
|
DIAM (
|
61
|
new int[][] {
|
62
|
{2 , 10, R.raw.diamond, R.drawable.ui_small_diam, R.drawable.ui_medium_diam, R.drawable.ui_big_diam, R.drawable.ui_huge_diam} ,
|
63
|
},
|
64
|
TwistyDiamond.class,
|
65
|
new MovementDiamond(),
|
66
|
1
|
67
|
),
|
68
|
|
69
|
DINO (
|
70
|
new int[][] {
|
71
|
{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} ,
|
72
|
},
|
73
|
TwistyDino6.class,
|
74
|
new MovementDino(),
|
75
|
2
|
76
|
),
|
77
|
|
78
|
DIN4 (
|
79
|
new int[][] {
|
80
|
{3 , 7, R.raw.dino, R.drawable.ui_small_din4, R.drawable.ui_medium_din4, R.drawable.ui_big_din4, R.drawable.ui_huge_din4} ,
|
81
|
},
|
82
|
TwistyDino4.class,
|
83
|
new MovementDino(),
|
84
|
2
|
85
|
),
|
86
|
|
87
|
REDI (
|
88
|
new int[][] {
|
89
|
{3 , 14, R.raw.redi, R.drawable.ui_small_redi, R.drawable.ui_medium_redi, R.drawable.ui_big_redi, R.drawable.ui_huge_redi} ,
|
90
|
},
|
91
|
TwistyRedi.class,
|
92
|
new MovementRedi(),
|
93
|
2
|
94
|
),
|
95
|
|
96
|
HELI (
|
97
|
new int[][] {
|
98
|
{3 , 18, R.raw.heli, R.drawable.ui_small_heli, R.drawable.ui_medium_heli, R.drawable.ui_big_heli, R.drawable.ui_huge_heli} ,
|
99
|
},
|
100
|
TwistyHelicopter.class,
|
101
|
new MovementHelicopter(),
|
102
|
2
|
103
|
),
|
104
|
|
105
|
SKEW (
|
106
|
new int[][] {
|
107
|
{2 , 11, R.raw.skewb, R.drawable.ui_small_skewb, R.drawable.ui_medium_skewb, R.drawable.ui_big_skewb, R.drawable.ui_huge_skewb} ,
|
108
|
{3 , 17, R.raw.skewm, R.drawable.ui_small_skewm, R.drawable.ui_medium_skewm, R.drawable.ui_big_skewm, R.drawable.ui_huge_skewm} ,
|
109
|
},
|
110
|
TwistySkewb.class,
|
111
|
new MovementSkewb(),
|
112
|
3
|
113
|
),
|
114
|
|
115
|
IVY (
|
116
|
new int[][] {
|
117
|
{2 , 8, R.raw.ivy, R.drawable.ui_small_ivy, R.drawable.ui_medium_ivy, R.drawable.ui_big_ivy, R.drawable.ui_huge_ivy} ,
|
118
|
},
|
119
|
TwistyIvy.class,
|
120
|
new MovementIvy(),
|
121
|
3
|
122
|
),
|
123
|
;
|
124
|
|
125
|
public static final int NUM_OBJECTS = values().length;
|
126
|
public static final int MAX_NUM_OBJECTS;
|
127
|
public static final int MAX_LEVEL;
|
128
|
public static final int MAX_OBJECT_SIZE;
|
129
|
|
130
|
private final int[] mObjectSizes, mMaxLevels, mSmallIconIDs, mMediumIconIDs, mBigIconIDs, mHugeIconIDs, mResourceIDs;
|
131
|
private final Class<? extends TwistyObject> mObjectClass;
|
132
|
private final Movement mObjectMovementClass;
|
133
|
private final int mColumn, mNumSizes;
|
134
|
|
135
|
private static final ObjectList[] objects;
|
136
|
private static int mNumAll;
|
137
|
private static int[] mIndices;
|
138
|
private static int mColCount, mRowCount;
|
139
|
|
140
|
static
|
141
|
{
|
142
|
mNumAll = 0;
|
143
|
int num, i = 0;
|
144
|
objects = new ObjectList[NUM_OBJECTS];
|
145
|
int maxNum = Integer.MIN_VALUE;
|
146
|
int maxLevel= Integer.MIN_VALUE;
|
147
|
int maxSize = Integer.MIN_VALUE;
|
148
|
|
149
|
for(ObjectList object: ObjectList.values())
|
150
|
{
|
151
|
objects[i] = object;
|
152
|
i++;
|
153
|
num = object.mObjectSizes.length;
|
154
|
mNumAll += num;
|
155
|
if( num> maxNum ) maxNum = num;
|
156
|
|
157
|
for(int j=0; j<num; j++)
|
158
|
{
|
159
|
if( object.mMaxLevels[j] > maxLevel ) maxLevel = object.mMaxLevels[j];
|
160
|
if( object.mObjectSizes[j] > maxSize) maxSize = object.mObjectSizes[j];
|
161
|
}
|
162
|
}
|
163
|
|
164
|
MAX_NUM_OBJECTS = maxNum;
|
165
|
MAX_LEVEL = maxLevel;
|
166
|
MAX_OBJECT_SIZE = maxSize;
|
167
|
}
|
168
|
|
169
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170
|
|
171
|
private static void setUpColAndRow()
|
172
|
{
|
173
|
mIndices = new int[NUM_OBJECTS];
|
174
|
mColCount= 0;
|
175
|
|
176
|
for(int obj=0; obj<NUM_OBJECTS; obj++)
|
177
|
{
|
178
|
mIndices[obj] = objects[obj].mColumn;
|
179
|
if( mIndices[obj]>=mColCount ) mColCount = mIndices[obj]+1;
|
180
|
}
|
181
|
|
182
|
mRowCount = 0;
|
183
|
|
184
|
for(int col=0; col<mColCount; col++)
|
185
|
{
|
186
|
int numObjects = computeNumObjectsInColumn(col);
|
187
|
if( numObjects>mRowCount ) mRowCount = numObjects;
|
188
|
}
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
private static int computeNumObjectsInColumn(int column)
|
194
|
{
|
195
|
int num=0;
|
196
|
|
197
|
for(int object=0; object<NUM_OBJECTS; object++)
|
198
|
{
|
199
|
if( objects[object].mColumn == column )
|
200
|
{
|
201
|
num += objects[object].mNumSizes;
|
202
|
}
|
203
|
}
|
204
|
|
205
|
return num;
|
206
|
}
|
207
|
|
208
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209
|
|
210
|
public static int getColumnCount()
|
211
|
{
|
212
|
if( mIndices==null ) setUpColAndRow();
|
213
|
|
214
|
return mColCount;
|
215
|
}
|
216
|
|
217
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218
|
|
219
|
public static int getRowCount()
|
220
|
{
|
221
|
if( mIndices==null ) setUpColAndRow();
|
222
|
|
223
|
return mRowCount;
|
224
|
}
|
225
|
|
226
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
227
|
|
228
|
public static int[] getIndices()
|
229
|
{
|
230
|
if( mIndices==null ) setUpColAndRow();
|
231
|
|
232
|
return mIndices;
|
233
|
}
|
234
|
|
235
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236
|
|
237
|
public static ObjectList getObject(int ordinal)
|
238
|
{
|
239
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE;
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
public static int pack(int object, int sizeIndex)
|
245
|
{
|
246
|
int ret = 0;
|
247
|
for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
|
248
|
|
249
|
return ret+sizeIndex;
|
250
|
}
|
251
|
|
252
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
253
|
|
254
|
public static int unpackSizeIndex(int number)
|
255
|
{
|
256
|
int num;
|
257
|
|
258
|
for(int i=0; i<NUM_OBJECTS; i++)
|
259
|
{
|
260
|
num = objects[i].mObjectSizes.length;
|
261
|
if( number<num ) return number;
|
262
|
number -= num;
|
263
|
}
|
264
|
|
265
|
return -1;
|
266
|
}
|
267
|
|
268
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269
|
|
270
|
public static int unpackObject(int number)
|
271
|
{
|
272
|
int num;
|
273
|
|
274
|
for(int i=0; i<NUM_OBJECTS; i++)
|
275
|
{
|
276
|
num = objects[i].mObjectSizes.length;
|
277
|
if( number<num ) return i;
|
278
|
number -= num;
|
279
|
}
|
280
|
|
281
|
return -1;
|
282
|
}
|
283
|
|
284
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
285
|
|
286
|
public static int unpackObjectFromString(String obj)
|
287
|
{
|
288
|
int u = obj.indexOf('_');
|
289
|
int l = obj.length();
|
290
|
|
291
|
if( u>0 )
|
292
|
{
|
293
|
String name = obj.substring(0,u);
|
294
|
int size = Integer.parseInt( obj.substring(u+1,l) );
|
295
|
|
296
|
for(int i=0; i<NUM_OBJECTS; i++)
|
297
|
{
|
298
|
if( objects[i].name().equals(name) )
|
299
|
{
|
300
|
int sizeIndex = getSizeIndex(i,size);
|
301
|
return pack(i,sizeIndex);
|
302
|
}
|
303
|
}
|
304
|
}
|
305
|
|
306
|
return -1;
|
307
|
}
|
308
|
|
309
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
310
|
|
311
|
public static String getObjectList()
|
312
|
{
|
313
|
String name;
|
314
|
StringBuilder list = new StringBuilder();
|
315
|
int len;
|
316
|
int[] sizes;
|
317
|
|
318
|
for(int i=0; i<NUM_OBJECTS; i++)
|
319
|
{
|
320
|
sizes = objects[i].mObjectSizes;
|
321
|
len = sizes.length;
|
322
|
name = objects[i].name();
|
323
|
|
324
|
for(int j=0; j<len; j++)
|
325
|
{
|
326
|
if( i>0 || j>0 ) list.append(',');
|
327
|
list.append(name);
|
328
|
list.append('_');
|
329
|
list.append(sizes[j]);
|
330
|
}
|
331
|
}
|
332
|
|
333
|
return list.toString();
|
334
|
}
|
335
|
|
336
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
337
|
|
338
|
public static int getTotal()
|
339
|
{
|
340
|
return mNumAll;
|
341
|
}
|
342
|
|
343
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
344
|
|
345
|
public static int getMaxLevel(int ordinal, int sizeIndex)
|
346
|
{
|
347
|
if( ordinal>=0 && ordinal<NUM_OBJECTS )
|
348
|
{
|
349
|
int num = objects[ordinal].mObjectSizes.length;
|
350
|
return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mMaxLevels[sizeIndex] : 0;
|
351
|
}
|
352
|
|
353
|
return 0;
|
354
|
}
|
355
|
|
356
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
357
|
|
358
|
public static int getOrdinal(String name)
|
359
|
{
|
360
|
for(int i=0; i<NUM_OBJECTS; i++)
|
361
|
{
|
362
|
if(objects[i].name().equals(name)) return i;
|
363
|
}
|
364
|
|
365
|
return -1;
|
366
|
}
|
367
|
|
368
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
369
|
|
370
|
public static int getSizeIndex(int ordinal, int size)
|
371
|
{
|
372
|
if( ordinal>=0 && ordinal<NUM_OBJECTS )
|
373
|
{
|
374
|
int[] sizes = objects[ordinal].getSizes();
|
375
|
int len = sizes.length;
|
376
|
|
377
|
for(int i=0; i<len; i++)
|
378
|
{
|
379
|
if( sizes[i]==size ) return i;
|
380
|
}
|
381
|
}
|
382
|
|
383
|
return -1;
|
384
|
}
|
385
|
|
386
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
387
|
|
388
|
public static int[] retFaceColors(ObjectList object)
|
389
|
{
|
390
|
Field field;
|
391
|
int[] faceColors=null;
|
392
|
|
393
|
try
|
394
|
{
|
395
|
field = object.mObjectClass.getDeclaredField("FACE_COLORS");
|
396
|
field.setAccessible(true);
|
397
|
Object obj = field.get(null);
|
398
|
faceColors = (int[]) obj;
|
399
|
}
|
400
|
catch(NoSuchFieldException ex)
|
401
|
{
|
402
|
android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": no such field exception getting field: "+ex.getMessage());
|
403
|
}
|
404
|
catch(IllegalAccessException ex)
|
405
|
{
|
406
|
android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": illegal access exception getting field: "+ex.getMessage());
|
407
|
}
|
408
|
|
409
|
return faceColors;
|
410
|
}
|
411
|
|
412
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
413
|
|
414
|
ObjectList(int[][] info, Class<? extends TwistyObject> object , Movement movement, int column)
|
415
|
{
|
416
|
mNumSizes = info.length;
|
417
|
|
418
|
mObjectSizes = new int[mNumSizes];
|
419
|
mMaxLevels = new int[mNumSizes];
|
420
|
mResourceIDs = new int[mNumSizes];
|
421
|
mSmallIconIDs = new int[mNumSizes];
|
422
|
mMediumIconIDs= new int[mNumSizes];
|
423
|
mBigIconIDs = new int[mNumSizes];
|
424
|
mHugeIconIDs = new int[mNumSizes];
|
425
|
|
426
|
for(int i=0; i<mNumSizes; i++)
|
427
|
{
|
428
|
mObjectSizes[i] = info[i][0];
|
429
|
mMaxLevels[i] = info[i][1];
|
430
|
mResourceIDs[i] = info[i][2];
|
431
|
mSmallIconIDs[i] = info[i][3];
|
432
|
mMediumIconIDs[i]= info[i][4];
|
433
|
mBigIconIDs[i] = info[i][5];
|
434
|
mHugeIconIDs[i] = info[i][6];
|
435
|
}
|
436
|
|
437
|
mObjectClass = object;
|
438
|
mObjectMovementClass = movement;
|
439
|
mColumn = column;
|
440
|
}
|
441
|
|
442
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
443
|
|
444
|
public int[] getSizes()
|
445
|
{
|
446
|
return mObjectSizes;
|
447
|
}
|
448
|
|
449
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
450
|
|
451
|
public int[] getMaxLevels()
|
452
|
{
|
453
|
return mMaxLevels;
|
454
|
}
|
455
|
|
456
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
457
|
|
458
|
public int[] getIconIDs()
|
459
|
{
|
460
|
int size = RubikActivity.getDrawableSize();
|
461
|
|
462
|
switch(size)
|
463
|
{
|
464
|
case 0 : return mSmallIconIDs;
|
465
|
case 1 : return mMediumIconIDs;
|
466
|
case 2 : return mBigIconIDs;
|
467
|
default: return mHugeIconIDs;
|
468
|
}
|
469
|
}
|
470
|
|
471
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
472
|
|
473
|
public int[] getResourceIDs()
|
474
|
{
|
475
|
return mResourceIDs;
|
476
|
}
|
477
|
|
478
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479
|
|
480
|
public int getNumVariants()
|
481
|
{
|
482
|
return mObjectSizes.length;
|
483
|
}
|
484
|
|
485
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
486
|
|
487
|
public TwistyObject create(int size, Static4D quat, int[][] moves, Resources res, int scrWidth)
|
488
|
{
|
489
|
DistortedTexture texture = new DistortedTexture();
|
490
|
DistortedEffects effects = new DistortedEffects();
|
491
|
MeshSquare mesh = new MeshSquare(20,20); // mesh of the node, not of the cubits
|
492
|
|
493
|
switch(ordinal())
|
494
|
{
|
495
|
case 0: return new TwistyCube (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
496
|
case 1: return new TwistyPyraminx (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
497
|
case 2: return new TwistyDiamond (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
498
|
case 3: return new TwistyDino6 (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
499
|
case 4: return new TwistyDino4 (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
500
|
case 5: return new TwistyRedi (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
501
|
case 6: return new TwistyHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
|
502
|
case 7: return new TwistySkewb (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
503
|
case 8: return new TwistyIvy (size, quat, texture, mesh, effects, moves, res, scrWidth);
|
504
|
}
|
505
|
|
506
|
return null;
|
507
|
}
|
508
|
|
509
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
510
|
|
511
|
public Movement getObjectMovementClass()
|
512
|
{
|
513
|
return mObjectMovementClass;
|
514
|
}
|
515
|
}
|