Project

General

Profile

Download (19.8 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / ObjectList.java @ 5b115c9b

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
         60
48
       ),
49

    
50
  PYRA (
51
         new int[][] {
52
                       {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} ,
53
                       {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} ,
54
                       {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}
55
                     },
56
         TwistyPyraminx.class,
57
         new MovementPyraminx(),
58
         1,
59
         30
60
       ),
61

    
62
  DIAM (
63
         new int[][] {
64
                       {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} ,
65
                     },
66
         TwistyDiamond.class,
67
         new MovementDiamond(),
68
         1,
69
         60
70
       ),
71

    
72
  DINO (
73
         new int[][] {
74
                       {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} ,
75
                     },
76
         TwistyDino6.class,
77
         new MovementDino(),
78
         2,
79
         60
80
       ),
81

    
82
  DIN4 (
83
         new int[][] {
84
                       {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} ,
85
                     },
86
         TwistyDino4.class,
87
         new MovementDino(),
88
         2,
89
         60
90
       ),
91

    
92
  REDI (
93
         new int[][] {
94
                       {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} ,
95
                     },
96
         TwistyRedi.class,
97
         new MovementRedi(),
98
         2,
99
         60
100
       ),
101

    
102
  HELI (
103
         new int[][] {
104
                       {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} ,
105
                     },
106
         TwistyHelicopter.class,
107
         new MovementHelicopter(),
108
         2,
109
         60
110
       ),
111

    
112
  SKEW (
113
         new int[][] {
114
                       {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} ,
115
                       {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} ,
116
                     },
117
         TwistySkewb.class,
118
         new MovementSkewb(),
119
         3,
120
         60
121
       ),
122

    
123
  IVY  (
124
         new int[][] {
125
                       {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} ,
126
                     },
127
         TwistyIvy.class,
128
         new MovementIvy(),
129
         3,
130
         60
131
       ),
132

    
133
  REX  (
134
         new int[][] {
135
                       {3 , 16, R.raw.rex, R.drawable.ui_small_rex, R.drawable.ui_medium_rex, R.drawable.ui_big_rex, R.drawable.ui_huge_rex} ,
136
                     },
137
         TwistyRex.class,
138
         new MovementRex(),
139
         3,
140
         60
141
       ),
142

    
143
  KILO (
144
         new int[][] {
145
                       {3 , 18, R.raw.kilo3, R.drawable.ui_small_kilo3, R.drawable.ui_medium_kilo3, R.drawable.ui_big_kilo3, R.drawable.ui_huge_kilo3} ,
146
                       {5 , 33, R.raw.kilo3, R.drawable.ui_small_kilo5, R.drawable.ui_medium_kilo5, R.drawable.ui_big_kilo5, R.drawable.ui_huge_kilo5} ,
147
                     },
148
         TwistyKilominx.class,
149
         new MovementMinx(),
150
         4,
151
         30
152
       ),
153

    
154
  MEGA (
155
         new int[][] {
156
                       {3 , 21, R.raw.mega3, R.drawable.ui_small_mega3, R.drawable.ui_medium_mega3, R.drawable.ui_big_mega3, R.drawable.ui_huge_mega3} ,
157
                       {5 , 35, R.raw.mega5, R.drawable.ui_small_mega5, R.drawable.ui_medium_mega5, R.drawable.ui_big_mega5, R.drawable.ui_huge_mega5} ,
158
                     },
159
         TwistyMegaminx.class,
160
         new MovementMinx(),
161
         4,
162
         30
163
       ),
164

    
165
  BAN1 (
166
         new int[][] {
167
                       {3 , 16, R.raw.ban1, R.drawable.ui_small_ban1, R.drawable.ui_medium_ban1, R.drawable.ui_big_ban1, R.drawable.ui_huge_ban1} ,
168
                     },
169
         TwistyBandagedFused.class,
170
         new MovementCube(),
171
         5,
172
         60
173
       ),
174

    
175
  BAN2 (
176
         new int[][] {
177
                       {3 , 16, R.raw.ban2, R.drawable.ui_small_ban2, R.drawable.ui_medium_ban2, R.drawable.ui_big_ban2, R.drawable.ui_huge_ban2} ,
178
                     },
179
         TwistyBandaged2Bar.class,
180
         new MovementCube(),
181
         5,
182
         60
183
       ),
184

    
185
  BAN3 (
186
         new int[][] {
187
                       {3 , 16, R.raw.ban3, R.drawable.ui_small_ban3, R.drawable.ui_medium_ban3, R.drawable.ui_big_ban3, R.drawable.ui_huge_ban3} ,
188
                     },
189
         TwistyBandaged3Plate.class,
190
         new MovementCube(),
191
         5,
192
         60
193
       ),
194

    
195
  BAN4 (
196
         new int[][] {
197
                       {3 , 16, R.raw.ban4, R.drawable.ui_small_ban4, R.drawable.ui_medium_ban4, R.drawable.ui_big_ban4, R.drawable.ui_huge_ban4} ,
198
                     },
199
         TwistyBandagedEvil.class,
200
         new MovementCube(),
201
         5,
202
         60
203
       ),
204
  ;
205

    
206
  public static final int NUM_OBJECTS = values().length;
207
  public static final int MAX_NUM_OBJECTS;
208
  public static final int MAX_LEVEL;
209
  public static final int MAX_OBJECT_SIZE;
210

    
211
  private final int[] mObjectSizes, mMaxLevels, mSmallIconIDs, mMediumIconIDs, mBigIconIDs, mHugeIconIDs, mResourceIDs;
212
  private final Class<? extends TwistyObject> mObjectClass;
213
  private final Movement mObjectMovementClass;
214
  private final int mRow, mNumSizes;
215
  private final int mFOV;
216

    
217
  private static final ObjectList[] objects;
218
  private static int mNumAll;
219
  private static int[] mIndices;
220
  private static int mColCount, mRowCount;
221

    
222
  static
223
    {
224
    mNumAll = 0;
225
    int num, i = 0;
226
    objects = new ObjectList[NUM_OBJECTS];
227
    int maxNum  = Integer.MIN_VALUE;
228
    int maxLevel= Integer.MIN_VALUE;
229
    int maxSize = Integer.MIN_VALUE;
230

    
231
    for(ObjectList object: ObjectList.values())
232
      {
233
      objects[i] = object;
234
      i++;
235
      num = object.mObjectSizes.length;
236
      mNumAll += num;
237
      if( num> maxNum ) maxNum = num;
238

    
239
      for(int j=0; j<num; j++)
240
        {
241
        if( object.mMaxLevels[j] > maxLevel ) maxLevel = object.mMaxLevels[j];
242
        if( object.mObjectSizes[j] > maxSize) maxSize  = object.mObjectSizes[j];
243
        }
244
      }
245

    
246
    MAX_NUM_OBJECTS = maxNum;
247
    MAX_LEVEL       = maxLevel;
248
    MAX_OBJECT_SIZE = maxSize;
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  private static void setUpColAndRow()
254
    {
255
    mIndices = new int[NUM_OBJECTS];
256
    mRowCount= 0;
257

    
258
    for(int obj=0; obj<NUM_OBJECTS; obj++)
259
      {
260
      mIndices[obj] = objects[obj].mRow;
261
      if( mIndices[obj]>=mRowCount ) mRowCount = mIndices[obj]+1;
262
      }
263

    
264
    mColCount = 0;
265

    
266
    for(int row=0; row<mRowCount; row++)
267
      {
268
      int numObjects = computeNumObjectsInRow(row);
269
      if( numObjects>mColCount ) mColCount = numObjects;
270
      }
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  private static int computeNumObjectsInRow(int row)
276
    {
277
    int num=0;
278

    
279
    for(int object=0; object<NUM_OBJECTS; object++)
280
      {
281
      if( objects[object].mRow == row )
282
        {
283
        num += objects[object].mNumSizes;
284
        }
285
      }
286

    
287
    return num;
288
    }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
  public static int getColumnCount()
293
    {
294
    if( mIndices==null ) setUpColAndRow();
295

    
296
    return mColCount;
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  public static int getRowCount()
302
    {
303
    if( mIndices==null ) setUpColAndRow();
304

    
305
    return mRowCount;
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  public static int[] getIndices()
311
    {
312
    if( mIndices==null ) setUpColAndRow();
313

    
314
    return mIndices;
315
    }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  public static ObjectList getObject(int ordinal)
320
    {
321
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE;
322
    }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
  public static int pack(int object, int sizeIndex)
327
    {
328
    int ret = 0;
329
    for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
330

    
331
    return ret+sizeIndex;
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  public static int unpackSizeIndex(int number)
337
    {
338
    int num;
339

    
340
    for(int i=0; i<NUM_OBJECTS; i++)
341
      {
342
      num = objects[i].mObjectSizes.length;
343
      if( number<num ) return number;
344
      number -= num;
345
      }
346

    
347
    return -1;
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
  public static int unpackObject(int number)
353
    {
354
    int num;
355

    
356
    for(int i=0; i<NUM_OBJECTS; i++)
357
      {
358
      num = objects[i].mObjectSizes.length;
359
      if( number<num ) return i;
360
      number -= num;
361
      }
362

    
363
    return -1;
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
  public static int unpackObjectFromString(String obj)
369
    {
370
    int u = obj.indexOf('_');
371
    int l = obj.length();
372

    
373
    if( u>0 )
374
      {
375
      String name = obj.substring(0,u);
376
      int size = Integer.parseInt( obj.substring(u+1,l) );
377

    
378
      for(int i=0; i<NUM_OBJECTS; i++)
379
        {
380
        if( objects[i].name().equals(name) )
381
          {
382
          int sizeIndex = getSizeIndex(i,size);
383
          return pack(i,sizeIndex);
384
          }
385
        }
386
      }
387

    
388
    return -1;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public static String getObjectList()
394
    {
395
    String name;
396
    StringBuilder list = new StringBuilder();
397
    int len;
398
    int[] sizes;
399

    
400
    for(int i=0; i<NUM_OBJECTS; i++)
401
      {
402
      sizes = objects[i].mObjectSizes;
403
      len   = sizes.length;
404
      name  = objects[i].name();
405

    
406
      for(int j=0; j<len; j++)
407
        {
408
        if( i>0 || j>0 ) list.append(',');
409
        list.append(name);
410
        list.append('_');
411
        list.append(sizes[j]);
412
        }
413
      }
414

    
415
    return list.toString();
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public static int getTotal()
421
    {
422
    return mNumAll;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public static int getMaxLevel(int ordinal, int sizeIndex)
428
    {
429
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
430
      {
431
      int num = objects[ordinal].mObjectSizes.length;
432
      return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mMaxLevels[sizeIndex] : 0;
433
      }
434

    
435
    return 0;
436
    }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

    
440
  public static int getOrdinal(String name)
441
    {
442
    for(int i=0; i<NUM_OBJECTS; i++)
443
      {
444
      if(objects[i].name().equals(name)) return i;
445
      }
446

    
447
    return -1;
448
    }
449

    
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

    
452
  public static int getSizeIndex(int ordinal, int size)
453
    {
454
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
455
      {
456
      int[] sizes = objects[ordinal].getSizes();
457
      int len = sizes.length;
458

    
459
      for(int i=0; i<len; i++)
460
        {
461
        if( sizes[i]==size ) return i;
462
        }
463
      }
464

    
465
    return -1;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public static int[] retFaceColors(ObjectList object)
471
    {
472
    Field field;
473
    int[] faceColors=null;
474

    
475
    try
476
      {
477
      field = object.mObjectClass.getDeclaredField("FACE_COLORS");
478
      field.setAccessible(true);
479
      Object obj = field.get(null);
480
      faceColors = (int[]) obj;
481
      }
482
    catch(NoSuchFieldException ex)
483
      {
484
      android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": no such field exception getting field: "+ex.getMessage());
485
      }
486
    catch(IllegalAccessException ex)
487
      {
488
      android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": illegal access exception getting field: "+ex.getMessage());
489
      }
490

    
491
    return faceColors;
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
  ObjectList(int[][] info, Class<? extends TwistyObject> object , Movement movement, int row, int fov)
497
    {
498
    mNumSizes = info.length;
499

    
500
    mObjectSizes  = new int[mNumSizes];
501
    mMaxLevels    = new int[mNumSizes];
502
    mResourceIDs  = new int[mNumSizes];
503
    mSmallIconIDs = new int[mNumSizes];
504
    mMediumIconIDs= new int[mNumSizes];
505
    mBigIconIDs   = new int[mNumSizes];
506
    mHugeIconIDs  = new int[mNumSizes];
507

    
508
    for(int i=0; i<mNumSizes; i++)
509
      {
510
      mObjectSizes[i]  = info[i][0];
511
      mMaxLevels[i]    = info[i][1];
512
      mResourceIDs[i]  = info[i][2];
513
      mSmallIconIDs[i] = info[i][3];
514
      mMediumIconIDs[i]= info[i][4];
515
      mBigIconIDs[i]   = info[i][5];
516
      mHugeIconIDs[i]  = info[i][6];
517
      }
518

    
519
    mObjectClass         = object;
520
    mObjectMovementClass = movement;
521
    mRow                 = row;
522
    mFOV                 = fov;
523
    }
524

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

    
527
  public int[] getSizes()
528
    {
529
    return mObjectSizes;
530
    }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533

    
534
  public int[] getMaxLevels()
535
    {
536
    return mMaxLevels;
537
    }
538

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
  public int getFOV()
542
    {
543
    return mFOV;
544
    }
545

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

    
548
  public int[] getIconIDs()
549
    {
550
    int size = RubikActivity.getDrawableSize();
551

    
552
    switch(size)
553
      {
554
      case 0 : return mSmallIconIDs;
555
      case 1 : return mMediumIconIDs;
556
      case 2 : return mBigIconIDs;
557
      default: return mHugeIconIDs;
558
      }
559
    }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

    
563
  public int[] getResourceIDs()
564
    {
565
    return mResourceIDs;
566
    }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
  public int getNumVariants()
571
    {
572
    return mObjectSizes.length;
573
    }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576

    
577
  public TwistyObject create(int size, Static4D quat, int[][] moves, Resources res, int scrWidth)
578
    {
579
    DistortedTexture texture = new DistortedTexture();
580
    DistortedEffects effects = new DistortedEffects();
581
    MeshSquare mesh          = new MeshSquare(20,20);   // mesh of the node, not of the cubits
582

    
583
    switch(ordinal())
584
      {
585
      case  0: return new TwistyCube          (size, quat, texture, mesh, effects, moves, res, scrWidth);
586
      case  1: return new TwistyPyraminx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
587
      case  2: return new TwistyDiamond       (size, quat, texture, mesh, effects, moves, res, scrWidth);
588
      case  3: return new TwistyDino6         (size, quat, texture, mesh, effects, moves, res, scrWidth);
589
      case  4: return new TwistyDino4         (size, quat, texture, mesh, effects, moves, res, scrWidth);
590
      case  5: return new TwistyRedi          (size, quat, texture, mesh, effects, moves, res, scrWidth);
591
      case  6: return new TwistyHelicopter    (size, quat, texture, mesh, effects, moves, res, scrWidth);
592
      case  7: return new TwistySkewb         (size, quat, texture, mesh, effects, moves, res, scrWidth);
593
      case  8: return new TwistyIvy           (size, quat, texture, mesh, effects, moves, res, scrWidth);
594
      case  9: return new TwistyRex           (size, quat, texture, mesh, effects, moves, res, scrWidth);
595
      case 10: return new TwistyKilominx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
596
      case 11: return new TwistyMegaminx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
597
      case 12: return new TwistyBandagedFused (size, quat, texture, mesh, effects, moves, res, scrWidth);
598
      case 13: return new TwistyBandaged2Bar(size, quat, texture, mesh, effects, moves, res, scrWidth);
599
      case 14: return new TwistyBandaged3Plate(size, quat, texture, mesh, effects, moves, res, scrWidth);
600
      case 15: return new TwistyBandagedEvil  (size, quat, texture, mesh, effects, moves, res, scrWidth);
601
      }
602

    
603
    return null;
604
    }
605

    
606
///////////////////////////////////////////////////////////////////////////////////////////////////
607

    
608
  public Movement getObjectMovementClass()
609
    {
610
    return mObjectMovementClass;
611
    }
612
  }
(15-15/35)