Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / ObjectList.java @ 4ab3d91b

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
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public enum ObjectList
34
  {
35
  ///////////////////// Size // DB Level // NumScrambles // Mesh // small icon // medium icon // big icon // huge icon
36

    
37
  CUBE (
38
         new int[][] {
39
                       {2 , 12, 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, 17, 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, 24, 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, 28, 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
         0
45
       ),
46

    
47
  JING (
48
         new int[][] {
49
                       {2 , 11, 11, R.raw.jing, R.drawable.ui_small_jing2, R.drawable.ui_medium_jing2, R.drawable.ui_big_jing2, R.drawable.ui_huge_jing2} ,
50
                     },
51
         1
52
       ),
53

    
54
  PYRA (
55
         new int[][] {
56
                       {3 , 10, 10, R.raw.pyra3, R.drawable.ui_small_pyra3, R.drawable.ui_medium_pyra3, R.drawable.ui_big_pyra3, R.drawable.ui_huge_pyra3} ,
57
                       {4 , 15, 17, R.raw.pyra4, R.drawable.ui_small_pyra4, R.drawable.ui_medium_pyra4, R.drawable.ui_big_pyra4, R.drawable.ui_huge_pyra4} ,
58
                       {5 , 20, 23, R.raw.pyra5, R.drawable.ui_small_pyra5, R.drawable.ui_medium_pyra5, R.drawable.ui_big_pyra5, R.drawable.ui_huge_pyra5}
59
                     },
60
         1
61
       ),
62

    
63
  KILO (
64
         new int[][] {
65
                       {3 , 18, 18, R.raw.kilo3, R.drawable.ui_small_kilo3, R.drawable.ui_medium_kilo3, R.drawable.ui_big_kilo3, R.drawable.ui_huge_kilo3} ,
66
                       {5 , 33, 33, R.raw.kilo5, R.drawable.ui_small_kilo5, R.drawable.ui_medium_kilo5, R.drawable.ui_big_kilo5, R.drawable.ui_huge_kilo5} ,
67
                     },
68
         2
69
       ),
70

    
71
  MEGA (
72
         new int[][] {
73
                       {3 , 21, 21, R.raw.mega3, R.drawable.ui_small_mega3, R.drawable.ui_medium_mega3, R.drawable.ui_big_mega3, R.drawable.ui_huge_mega3} ,
74
                       {5 , 35, 37, R.raw.mega5, R.drawable.ui_small_mega5, R.drawable.ui_medium_mega5, R.drawable.ui_big_mega5, R.drawable.ui_huge_mega5} ,
75
                     },
76
         2
77
       ),
78

    
79
  ULTI (
80
         new int[][] {
81
                       {2 , 18, 18, R.raw.ulti, R.drawable.ui_small_ulti, R.drawable.ui_medium_ulti, R.drawable.ui_big_ulti, R.drawable.ui_huge_ulti} ,
82
                     },
83
         3
84
       ),
85

    
86
  DIAM (
87
         new int[][] {
88
                       {2 , 10, 12, R.raw.diam2, R.drawable.ui_small_diam2, R.drawable.ui_medium_diam2, R.drawable.ui_big_diam2, R.drawable.ui_huge_diam2} ,
89
                       {3 , 18, 24, R.raw.diam3, R.drawable.ui_small_diam3, R.drawable.ui_medium_diam3, R.drawable.ui_big_diam3, R.drawable.ui_huge_diam3} ,
90
                       {4 , 32, 32, R.raw.diam4, R.drawable.ui_small_diam4, R.drawable.ui_medium_diam4, R.drawable.ui_big_diam4, R.drawable.ui_huge_diam4} ,
91
                     },
92
         3
93
       ),
94

    
95
  DINO (
96
         new int[][] {
97
                       {3 , 10, 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
98
                     },
99
         4
100
       ),
101

    
102
  DIN4 (
103
         new int[][] {
104
                       {3 , 7, 7, R.raw.dino, R.drawable.ui_small_din4, R.drawable.ui_medium_din4, R.drawable.ui_big_din4, R.drawable.ui_huge_din4} ,
105
                     },
106
         4
107
       ),
108

    
109
  REDI (
110
         new int[][] {
111
                       {3 , 14, 16, R.raw.redi, R.drawable.ui_small_redi, R.drawable.ui_medium_redi, R.drawable.ui_big_redi, R.drawable.ui_huge_redi} ,
112
                     },
113
         4
114
       ),
115

    
116
  HELI (
117
         new int[][] {
118
                       {3 , 18, 20, R.raw.heli, R.drawable.ui_small_heli, R.drawable.ui_medium_heli, R.drawable.ui_big_heli, R.drawable.ui_huge_heli} ,
119
                     },
120
         4
121
       ),
122

    
123
  SKEW (
124
         new int[][] {
125
                       {2 , 11, 11, R.raw.skew2, R.drawable.ui_small_skewb, R.drawable.ui_medium_skewb, R.drawable.ui_big_skewb, R.drawable.ui_huge_skewb} ,
126
                       {3 , 17, 21, R.raw.skew3, R.drawable.ui_small_skewm, R.drawable.ui_medium_skewm, R.drawable.ui_big_skewm, R.drawable.ui_huge_skewm} ,
127
                     },
128
         5
129
       ),
130

    
131
  IVY  (
132
         new int[][] {
133
                       {2 , 8, 8, R.raw.ivy, R.drawable.ui_small_ivy, R.drawable.ui_medium_ivy, R.drawable.ui_big_ivy, R.drawable.ui_huge_ivy} ,
134
                     },
135
         5
136
       ),
137

    
138
  REX  (
139
         new int[][] {
140
                       {3 , 16, 19, R.raw.rex, R.drawable.ui_small_rex, R.drawable.ui_medium_rex, R.drawable.ui_big_rex, R.drawable.ui_huge_rex} ,
141
                     },
142
         5
143
       ),
144

    
145
  BAN1 (
146
         new int[][] {
147
                       {3 , 16, 16, R.raw.ban1, R.drawable.ui_small_ban1, R.drawable.ui_medium_ban1, R.drawable.ui_big_ban1, R.drawable.ui_huge_ban1} ,
148
                     },
149
         6
150
       ),
151

    
152
  BAN2 (
153
         new int[][] {
154
                       {3 , 16, 16, R.raw.ban2, R.drawable.ui_small_ban2, R.drawable.ui_medium_ban2, R.drawable.ui_big_ban2, R.drawable.ui_huge_ban2} ,
155
                     },
156
         6
157
       ),
158

    
159
  BAN3 (
160
         new int[][] {
161
                       {3 , 16, 16, R.raw.ban3, R.drawable.ui_small_ban3, R.drawable.ui_medium_ban3, R.drawable.ui_big_ban3, R.drawable.ui_huge_ban3} ,
162
                     },
163
         6
164
       ),
165

    
166
  BAN4 (
167
         new int[][] {
168
                       {3 , 16, 16, R.raw.ban4, R.drawable.ui_small_ban4, R.drawable.ui_medium_ban4, R.drawable.ui_big_ban4, R.drawable.ui_huge_ban4} ,
169
                     },
170
         6
171
       ),
172

    
173
  SQU1 (
174
         new int[][] {
175
                       {3 , 24, 24, R.raw.square1, R.drawable.ui_small_square1, R.drawable.ui_medium_square1, R.drawable.ui_big_square1, R.drawable.ui_huge_square1} ,
176
                     },
177
         7
178
       ),
179

    
180
  SQU2 (
181
         new int[][] {
182
                       {3 , 24, 24, R.raw.square2, R.drawable.ui_small_square2, R.drawable.ui_medium_square2, R.drawable.ui_big_square2, R.drawable.ui_huge_square2} ,
183
                     },
184
         7
185
       ),
186

    
187
  MIRR (
188
         new int[][] {
189
                       {2 , 12, 12, R.raw.mirr2, R.drawable.ui_small_mirr2, R.drawable.ui_medium_mirr2, R.drawable.ui_big_mirr2, R.drawable.ui_huge_mirr2} ,
190
                       {3 , 16, 17, R.raw.mirr3, R.drawable.ui_small_mirr3, R.drawable.ui_medium_mirr3, R.drawable.ui_big_mirr3, R.drawable.ui_huge_mirr3} ,
191
                     },
192
         7
193
       ),
194
  ;
195

    
196
  public static final int NUM_OBJECTS = values().length;
197
  public static final int MAX_NUM_OBJECTS;
198
  public static final int MAX_LEVEL;
199
  public static final int MAX_SCRAMBLE;
200
  public static final int MAX_OBJECT_SIZE;
201

    
202
  private final int[] mObjectSizes, mDBLevels, mNumScrambles, mSmallIconIDs, mMediumIconIDs, mBigIconIDs, mHugeIconIDs, mResourceIDs;
203
  private final int mRow, mNumSizes;
204

    
205
  private static final ObjectList[] objects;
206
  private static int mNumAll;
207
  private static int[] mIndices;
208
  private static int mColCount, mRowCount;
209

    
210
  static
211
    {
212
    mNumAll = 0;
213
    int num, i = 0;
214
    objects = new ObjectList[NUM_OBJECTS];
215
    int maxNum     = Integer.MIN_VALUE;
216
    int maxLevel   = Integer.MIN_VALUE;
217
    int maxScramble= Integer.MIN_VALUE;
218
    int maxSize    = Integer.MIN_VALUE;
219

    
220
    for(ObjectList object: ObjectList.values())
221
      {
222
      objects[i] = object;
223
      i++;
224
      num = object.mObjectSizes.length;
225
      mNumAll += num;
226
      if( num> maxNum ) maxNum = num;
227

    
228
      for(int j=0; j<num; j++)
229
        {
230
        if( object.mNumScrambles[j]> maxScramble ) maxScramble= object.mNumScrambles[j];
231
        if( object.mDBLevels[j]    > maxLevel    ) maxLevel   = object.mDBLevels[j];
232
        if( object.mObjectSizes[j] > maxSize     ) maxSize    = object.mObjectSizes[j];
233
        }
234
      }
235

    
236
    MAX_NUM_OBJECTS = maxNum;
237
    MAX_LEVEL       = maxLevel;
238
    MAX_SCRAMBLE    = maxScramble;
239
    MAX_OBJECT_SIZE = maxSize;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  private static void setUpColAndRow()
245
    {
246
    mIndices = new int[NUM_OBJECTS];
247
    mRowCount= 0;
248

    
249
    for(int obj=0; obj<NUM_OBJECTS; obj++)
250
      {
251
      mIndices[obj] = objects[obj].mRow;
252
      if( mIndices[obj]>=mRowCount ) mRowCount = mIndices[obj]+1;
253
      }
254

    
255
    mColCount = 0;
256

    
257
    for(int row=0; row<mRowCount; row++)
258
      {
259
      int numObjects = computeNumObjectsInRow(row);
260
      if( numObjects>mColCount ) mColCount = numObjects;
261
      }
262
    }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

    
266
  private static int computeNumObjectsInRow(int row)
267
    {
268
    int num=0;
269

    
270
    for(int object=0; object<NUM_OBJECTS; object++)
271
      {
272
      if( objects[object].mRow == row )
273
        {
274
        num += objects[object].mNumSizes;
275
        }
276
      }
277

    
278
    return num;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public static int getColumnCount()
284
    {
285
    if( mIndices==null ) setUpColAndRow();
286

    
287
    return mColCount;
288
    }
289

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

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

    
296
    return mRowCount;
297
    }
298

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

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

    
305
    return mIndices;
306
    }
307

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

    
310
  public static ObjectList getObject(int ordinal)
311
    {
312
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE;
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  public static int pack(int object, int sizeIndex)
318
    {
319
    int ret = 0;
320
    for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
321

    
322
    return ret+sizeIndex;
323
    }
324

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

    
327
  public static int unpackSizeIndex(int number)
328
    {
329
    int num;
330

    
331
    for(int i=0; i<NUM_OBJECTS; i++)
332
      {
333
      num = objects[i].mObjectSizes.length;
334
      if( number<num ) return number;
335
      number -= num;
336
      }
337

    
338
    return -1;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

    
343
  public static int unpackObject(int number)
344
    {
345
    int num;
346

    
347
    for(int i=0; i<NUM_OBJECTS; i++)
348
      {
349
      num = objects[i].mObjectSizes.length;
350
      if( number<num ) return i;
351
      number -= num;
352
      }
353

    
354
    return -1;
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  public static int unpackObjectFromString(String obj)
360
    {
361
    int u = obj.indexOf('_');
362
    int l = obj.length();
363

    
364
    if( u>0 )
365
      {
366
      String name = obj.substring(0,u);
367
      int size = Integer.parseInt( obj.substring(u+1,l) );
368

    
369
      for(int i=0; i<NUM_OBJECTS; i++)
370
        {
371
        if( objects[i].name().equals(name) )
372
          {
373
          int sizeIndex = getSizeIndex(i,size);
374
          return pack(i,sizeIndex);
375
          }
376
        }
377
      }
378

    
379
    return -1;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  public static String getObjectList()
385
    {
386
    String name;
387
    StringBuilder list = new StringBuilder();
388
    int len;
389
    int[] sizes;
390

    
391
    for(int i=0; i<NUM_OBJECTS; i++)
392
      {
393
      sizes = objects[i].mObjectSizes;
394
      len   = sizes.length;
395
      name  = objects[i].name();
396

    
397
      for(int j=0; j<len; j++)
398
        {
399
        if( i>0 || j>0 ) list.append(',');
400
        list.append(name);
401
        list.append('_');
402
        list.append(sizes[j]);
403
        }
404
      }
405

    
406
    return list.toString();
407
    }
408

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

    
411
  public static int getTotal()
412
    {
413
    return mNumAll;
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

    
418
  public static int getDBLevel(int ordinal, int sizeIndex)
419
    {
420
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
421
      {
422
      int num = objects[ordinal].mObjectSizes.length;
423
      return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mDBLevels[sizeIndex] : 0;
424
      }
425

    
426
    return 0;
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  public static int getNumScramble(int ordinal, int sizeIndex)
432
    {
433
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
434
      {
435
      int num = objects[ordinal].mObjectSizes.length;
436
      return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mNumScrambles[sizeIndex] : 0;
437
      }
438

    
439
    return 0;
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public static int getOrdinal(String name)
445
    {
446
    for(int i=0; i<NUM_OBJECTS; i++)
447
      {
448
      if(objects[i].name().equals(name)) return i;
449
      }
450

    
451
    return -1;
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public static int getSizeIndex(int ordinal, int size)
457
    {
458
    if( ordinal>=0 && ordinal<NUM_OBJECTS )
459
      {
460
      int[] sizes = objects[ordinal].getSizes();
461
      int len = sizes.length;
462

    
463
      for(int i=0; i<len; i++)
464
        {
465
        if( sizes[i]==size ) return i;
466
        }
467
      }
468

    
469
    return -1;
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  ObjectList(int[][] info, int row)
475
    {
476
    mNumSizes = info.length;
477

    
478
    mObjectSizes  = new int[mNumSizes];
479
    mDBLevels     = new int[mNumSizes];
480
    mNumScrambles = new int[mNumSizes];
481
    mResourceIDs  = new int[mNumSizes];
482
    mSmallIconIDs = new int[mNumSizes];
483
    mMediumIconIDs= new int[mNumSizes];
484
    mBigIconIDs   = new int[mNumSizes];
485
    mHugeIconIDs  = new int[mNumSizes];
486

    
487
    for(int i=0; i<mNumSizes; i++)
488
      {
489
      mObjectSizes[i]  = info[i][0];
490
      mDBLevels[i]     = info[i][1];
491
      mNumScrambles[i] = info[i][2];
492
      mResourceIDs[i]  = info[i][3];
493
      mSmallIconIDs[i] = info[i][4];
494
      mMediumIconIDs[i]= info[i][5];
495
      mBigIconIDs[i]   = info[i][6];
496
      mHugeIconIDs[i]  = info[i][7];
497
      }
498

    
499
    mRow  = row;
500
    }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
  public int[] getSizes()
505
    {
506
    return mObjectSizes;
507
    }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
  public int[] getIconIDs()
512
    {
513
    int size = RubikActivity.getDrawableSize();
514

    
515
    switch(size)
516
      {
517
      case 0 : return mSmallIconIDs;
518
      case 1 : return mMediumIconIDs;
519
      case 2 : return mBigIconIDs;
520
      default: return mHugeIconIDs;
521
      }
522
    }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

    
526
  public int[] getResourceIDs()
527
    {
528
    return mResourceIDs;
529
    }
530

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532

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

    
539
    switch(ordinal())
540
      {
541
      case  0: return new TwistyCube          (size, quat, texture, mesh, effects, moves, res, scrWidth);
542
      case  1: return new TwistyJing          (size, quat, texture, mesh, effects, moves, res, scrWidth);
543
      case  2: return new TwistyPyraminx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
544
      case  3: return new TwistyKilominx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
545
      case  4: return new TwistyMegaminx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
546
      case  5: return new TwistyUltimate      (size, quat, texture, mesh, effects, moves, res, scrWidth);
547
      case  6: return new TwistyDiamond       (size, quat, texture, mesh, effects, moves, res, scrWidth);
548
      case  7: return new TwistyDino6         (size, quat, texture, mesh, effects, moves, res, scrWidth);
549
      case  8: return new TwistyDino4         (size, quat, texture, mesh, effects, moves, res, scrWidth);
550
      case  9: return new TwistyRedi          (size, quat, texture, mesh, effects, moves, res, scrWidth);
551
      case 10: return new TwistyHelicopter    (size, quat, texture, mesh, effects, moves, res, scrWidth);
552
      case 11: return new TwistySkewb         (size, quat, texture, mesh, effects, moves, res, scrWidth);
553
      case 12: return new TwistyIvy           (size, quat, texture, mesh, effects, moves, res, scrWidth);
554
      case 13: return new TwistyRex           (size, quat, texture, mesh, effects, moves, res, scrWidth);
555
      case 14: return new TwistyBandagedFused (size, quat, texture, mesh, effects, moves, res, scrWidth);
556
      case 15: return new TwistyBandaged2Bar  (size, quat, texture, mesh, effects, moves, res, scrWidth);
557
      case 16: return new TwistyBandaged3Plate(size, quat, texture, mesh, effects, moves, res, scrWidth);
558
      case 17: return new TwistyBandagedEvil  (size, quat, texture, mesh, effects, moves, res, scrWidth);
559
      case 18: return new TwistySquare1       (size, quat, texture, mesh, effects, moves, res, scrWidth);
560
      case 19: return new TwistySquare2       (size, quat, texture, mesh, effects, moves, res, scrWidth);
561
      case 20: return new TwistyMirror        (size, quat, texture, mesh, effects, moves, res, scrWidth);
562
      }
563

    
564
    return null;
565
    }
566
  }
(17-17/48)