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