Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / ObjectList.java @ 00af5060

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
                     },
147
         TwistyKilominx.class,
148
         new MovementMinx(),
149
         4,
150
         30
151
       ),
152

    
153
  MEGA (
154
         new int[][] {
155
                       {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} ,
156
                       {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} ,
157
                     },
158
         TwistyMegaminx.class,
159
         new MovementMinx(),
160
         4,
161
         30
162
       ),
163
  ;
164

    
165
  public static final int NUM_OBJECTS = values().length;
166
  public static final int MAX_NUM_OBJECTS;
167
  public static final int MAX_LEVEL;
168
  public static final int MAX_OBJECT_SIZE;
169

    
170
  private final int[] mObjectSizes, mMaxLevels, mSmallIconIDs, mMediumIconIDs, mBigIconIDs, mHugeIconIDs, mResourceIDs;
171
  private final Class<? extends TwistyObject> mObjectClass;
172
  private final Movement mObjectMovementClass;
173
  private final int mColumn, mNumSizes;
174
  private final int mFOV;
175

    
176
  private static final ObjectList[] objects;
177
  private static int mNumAll;
178
  private static int[] mIndices;
179
  private static int mColCount, mRowCount;
180

    
181
  static
182
    {
183
    mNumAll = 0;
184
    int num, i = 0;
185
    objects = new ObjectList[NUM_OBJECTS];
186
    int maxNum  = Integer.MIN_VALUE;
187
    int maxLevel= Integer.MIN_VALUE;
188
    int maxSize = Integer.MIN_VALUE;
189

    
190
    for(ObjectList object: ObjectList.values())
191
      {
192
      objects[i] = object;
193
      i++;
194
      num = object.mObjectSizes.length;
195
      mNumAll += num;
196
      if( num> maxNum ) maxNum = num;
197

    
198
      for(int j=0; j<num; j++)
199
        {
200
        if( object.mMaxLevels[j] > maxLevel ) maxLevel = object.mMaxLevels[j];
201
        if( object.mObjectSizes[j] > maxSize) maxSize  = object.mObjectSizes[j];
202
        }
203
      }
204

    
205
    MAX_NUM_OBJECTS = maxNum;
206
    MAX_LEVEL       = maxLevel;
207
    MAX_OBJECT_SIZE = maxSize;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  private static void setUpColAndRow()
213
    {
214
    mIndices = new int[NUM_OBJECTS];
215
    mColCount= 0;
216

    
217
    for(int obj=0; obj<NUM_OBJECTS; obj++)
218
      {
219
      mIndices[obj] = objects[obj].mColumn;
220
      if( mIndices[obj]>=mColCount ) mColCount = mIndices[obj]+1;
221
      }
222

    
223
    mRowCount = 0;
224

    
225
    for(int col=0; col<mColCount; col++)
226
      {
227
      int numObjects = computeNumObjectsInColumn(col);
228
      if( numObjects>mRowCount ) mRowCount = numObjects;
229
      }
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  private static int computeNumObjectsInColumn(int column)
235
    {
236
    int num=0;
237

    
238
    for(int object=0; object<NUM_OBJECTS; object++)
239
      {
240
      if( objects[object].mColumn == column )
241
        {
242
        num += objects[object].mNumSizes;
243
        }
244
      }
245

    
246
    return num;
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
  public static int getColumnCount()
252
    {
253
    if( mIndices==null ) setUpColAndRow();
254

    
255
    return mColCount;
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  public static int getRowCount()
261
    {
262
    if( mIndices==null ) setUpColAndRow();
263

    
264
    return mRowCount;
265
    }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
  public static int[] getIndices()
270
    {
271
    if( mIndices==null ) setUpColAndRow();
272

    
273
    return mIndices;
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

    
278
  public static ObjectList getObject(int ordinal)
279
    {
280
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE;
281
    }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

    
285
  public static int pack(int object, int sizeIndex)
286
    {
287
    int ret = 0;
288
    for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
289

    
290
    return ret+sizeIndex;
291
    }
292

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294

    
295
  public static int unpackSizeIndex(int number)
296
    {
297
    int num;
298

    
299
    for(int i=0; i<NUM_OBJECTS; i++)
300
      {
301
      num = objects[i].mObjectSizes.length;
302
      if( number<num ) return number;
303
      number -= num;
304
      }
305

    
306
    return -1;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  public static int unpackObject(int number)
312
    {
313
    int num;
314

    
315
    for(int i=0; i<NUM_OBJECTS; i++)
316
      {
317
      num = objects[i].mObjectSizes.length;
318
      if( number<num ) return i;
319
      number -= num;
320
      }
321

    
322
    return -1;
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  public static int unpackObjectFromString(String obj)
328
    {
329
    int u = obj.indexOf('_');
330
    int l = obj.length();
331

    
332
    if( u>0 )
333
      {
334
      String name = obj.substring(0,u);
335
      int size = Integer.parseInt( obj.substring(u+1,l) );
336

    
337
      for(int i=0; i<NUM_OBJECTS; i++)
338
        {
339
        if( objects[i].name().equals(name) )
340
          {
341
          int sizeIndex = getSizeIndex(i,size);
342
          return pack(i,sizeIndex);
343
          }
344
        }
345
      }
346

    
347
    return -1;
348
    }
349

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

    
352
  public static String getObjectList()
353
    {
354
    String name;
355
    StringBuilder list = new StringBuilder();
356
    int len;
357
    int[] sizes;
358

    
359
    for(int i=0; i<NUM_OBJECTS; i++)
360
      {
361
      sizes = objects[i].mObjectSizes;
362
      len   = sizes.length;
363
      name  = objects[i].name();
364

    
365
      for(int j=0; j<len; j++)
366
        {
367
        if( i>0 || j>0 ) list.append(',');
368
        list.append(name);
369
        list.append('_');
370
        list.append(sizes[j]);
371
        }
372
      }
373

    
374
    return list.toString();
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public static int getTotal()
380
    {
381
    return mNumAll;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public static int getMaxLevel(int ordinal, int sizeIndex)
387
    {
388
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
389
      {
390
      int num = objects[ordinal].mObjectSizes.length;
391
      return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mMaxLevels[sizeIndex] : 0;
392
      }
393

    
394
    return 0;
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398

    
399
  public static int getOrdinal(String name)
400
    {
401
    for(int i=0; i<NUM_OBJECTS; i++)
402
      {
403
      if(objects[i].name().equals(name)) return i;
404
      }
405

    
406
    return -1;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

    
411
  public static int getSizeIndex(int ordinal, int size)
412
    {
413
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
414
      {
415
      int[] sizes = objects[ordinal].getSizes();
416
      int len = sizes.length;
417

    
418
      for(int i=0; i<len; i++)
419
        {
420
        if( sizes[i]==size ) return i;
421
        }
422
      }
423

    
424
    return -1;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public static int[] retFaceColors(ObjectList object)
430
    {
431
    Field field;
432
    int[] faceColors=null;
433

    
434
    try
435
      {
436
      field = object.mObjectClass.getDeclaredField("FACE_COLORS");
437
      field.setAccessible(true);
438
      Object obj = field.get(null);
439
      faceColors = (int[]) obj;
440
      }
441
    catch(NoSuchFieldException ex)
442
      {
443
      android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": no such field exception getting field: "+ex.getMessage());
444
      }
445
    catch(IllegalAccessException ex)
446
      {
447
      android.util.Log.e("RubikObjectList", object.mObjectClass.getSimpleName()+": illegal access exception getting field: "+ex.getMessage());
448
      }
449

    
450
    return faceColors;
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  ObjectList(int[][] info, Class<? extends TwistyObject> object , Movement movement, int column, int fov)
456
    {
457
    mNumSizes = info.length;
458

    
459
    mObjectSizes  = new int[mNumSizes];
460
    mMaxLevels    = new int[mNumSizes];
461
    mResourceIDs  = new int[mNumSizes];
462
    mSmallIconIDs = new int[mNumSizes];
463
    mMediumIconIDs= new int[mNumSizes];
464
    mBigIconIDs   = new int[mNumSizes];
465
    mHugeIconIDs  = new int[mNumSizes];
466

    
467
    for(int i=0; i<mNumSizes; i++)
468
      {
469
      mObjectSizes[i]  = info[i][0];
470
      mMaxLevels[i]    = info[i][1];
471
      mResourceIDs[i]  = info[i][2];
472
      mSmallIconIDs[i] = info[i][3];
473
      mMediumIconIDs[i]= info[i][4];
474
      mBigIconIDs[i]   = info[i][5];
475
      mHugeIconIDs[i]  = info[i][6];
476
      }
477

    
478
    mObjectClass         = object;
479
    mObjectMovementClass = movement;
480
    mColumn              = column;
481
    mFOV                 = fov;
482
    }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

    
486
  public int[] getSizes()
487
    {
488
    return mObjectSizes;
489
    }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

    
493
  public int[] getMaxLevels()
494
    {
495
    return mMaxLevels;
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499

    
500
  public int getFOV()
501
    {
502
    return mFOV;
503
    }
504

    
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506

    
507
  public int[] getIconIDs()
508
    {
509
    int size = RubikActivity.getDrawableSize();
510

    
511
    switch(size)
512
      {
513
      case 0 : return mSmallIconIDs;
514
      case 1 : return mMediumIconIDs;
515
      case 2 : return mBigIconIDs;
516
      default: return mHugeIconIDs;
517
      }
518
    }
519

    
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521

    
522
  public int[] getResourceIDs()
523
    {
524
    return mResourceIDs;
525
    }
526

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528

    
529
  public int getNumVariants()
530
    {
531
    return mObjectSizes.length;
532
    }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
  public TwistyObject create(int size, Static4D quat, int[][] moves, Resources res, int scrWidth)
537
    {
538
    DistortedTexture texture = new DistortedTexture();
539
    DistortedEffects effects = new DistortedEffects();
540
    MeshSquare mesh          = new MeshSquare(20,20);   // mesh of the node, not of the cubits
541

    
542
    switch(ordinal())
543
      {
544
      case  0: return new TwistyCube      (size, quat, texture, mesh, effects, moves, res, scrWidth);
545
      case  1: return new TwistyPyraminx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
546
      case  2: return new TwistyDiamond   (size, quat, texture, mesh, effects, moves, res, scrWidth);
547
      case  3: return new TwistyDino6     (size, quat, texture, mesh, effects, moves, res, scrWidth);
548
      case  4: return new TwistyDino4     (size, quat, texture, mesh, effects, moves, res, scrWidth);
549
      case  5: return new TwistyRedi      (size, quat, texture, mesh, effects, moves, res, scrWidth);
550
      case  6: return new TwistyHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
551
      case  7: return new TwistySkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
552
      case  8: return new TwistyIvy       (size, quat, texture, mesh, effects, moves, res, scrWidth);
553
      case  9: return new TwistyRex       (size, quat, texture, mesh, effects, moves, res, scrWidth);
554
      case 10: return new TwistyKilominx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
555
      case 11: return new TwistyMegaminx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
556
      }
557

    
558
    return null;
559
    }
560

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

    
563
  public Movement getObjectMovementClass()
564
    {
565
    return mObjectMovementClass;
566
    }
567
  }
(15-15/30)