Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectType.java @ ad9f5cae

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.objectlib.main;
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

    
29
import org.distorted.objectlib.R;
30
import org.distorted.objectlib.objects.*;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public enum ObjectType
35
  {
36
  CUBE_2 ( 0, 2, 12, 12, R.drawable.small_cube2, R.drawable.medium_cube2, R.drawable.big_cube2, R.drawable.huge_cube2),
37
  CUBE_3 ( 0, 3, 16, 17, R.drawable.small_cube3, R.drawable.medium_cube3, R.drawable.big_cube3, R.drawable.huge_cube3),
38
  CUBE_4 ( 0, 4, 20, 24, R.drawable.small_cube4, R.drawable.medium_cube4, R.drawable.big_cube4, R.drawable.huge_cube4),
39
  CUBE_5 ( 0, 5, 24, 28, R.drawable.small_cube5, R.drawable.medium_cube5, R.drawable.big_cube5, R.drawable.huge_cube5),
40
  JING_2 ( 1, 2, 11, 11, R.drawable.small_jing2, R.drawable.medium_jing2, R.drawable.big_jing2, R.drawable.huge_jing2),
41
  PYRA_3 ( 1, 3, 10, 10, R.drawable.small_pyra3, R.drawable.medium_pyra3, R.drawable.big_pyra3, R.drawable.huge_pyra3),
42
  PYRA_4 ( 1, 4, 14, 17, R.drawable.small_pyra4, R.drawable.medium_pyra4, R.drawable.big_pyra4, R.drawable.huge_pyra4),
43
  PYRA_5 ( 1, 5, 20, 23, R.drawable.small_pyra5, R.drawable.medium_pyra5, R.drawable.big_pyra5, R.drawable.huge_pyra5),
44
  KILO_3 ( 2, 3, 18, 18, R.drawable.small_kilo3, R.drawable.medium_kilo3, R.drawable.big_kilo3, R.drawable.huge_kilo3),
45
  KILO_5 ( 2, 5, 33, 33, R.drawable.small_kilo5, R.drawable.medium_kilo5, R.drawable.big_kilo5, R.drawable.huge_kilo5),
46
  MEGA_3 ( 2, 3, 21, 21, R.drawable.small_mega3, R.drawable.medium_mega3, R.drawable.big_mega3, R.drawable.huge_mega3),
47
  MEGA_5 ( 2, 5, 35, 37, R.drawable.small_mega5, R.drawable.medium_mega5, R.drawable.big_mega5, R.drawable.huge_mega5),
48
  ULTI_2 ( 3, 2, 18, 18, R.drawable.small_ulti , R.drawable.medium_ulti , R.drawable.big_ulti , R.drawable.huge_ulti ),
49
  DIAM_2 ( 3, 2, 10, 12, R.drawable.small_diam2, R.drawable.medium_diam2, R.drawable.big_diam2, R.drawable.huge_diam2),
50
  DIAM_3 ( 3, 3, 18, 24, R.drawable.small_diam3, R.drawable.medium_diam3, R.drawable.big_diam3, R.drawable.huge_diam3),
51
  DIAM_4 ( 3, 4, 32, 32, R.drawable.small_diam4, R.drawable.medium_diam4, R.drawable.big_diam4, R.drawable.huge_diam4),
52
  DINO_3 ( 4, 3, 10, 10, R.drawable.small_dino , R.drawable.medium_dino , R.drawable.big_dino , R.drawable.huge_dino ),
53
  DIN4_3 ( 4, 3,  7,  7, R.drawable.small_din4 , R.drawable.medium_din4 , R.drawable.big_din4 , R.drawable.huge_din4 ),
54
  REDI_3 ( 4, 3, 14, 16, R.drawable.small_redi , R.drawable.medium_redi , R.drawable.big_redi , R.drawable.huge_redi ),
55
  HELI_3 ( 4, 3, 18, 20, R.drawable.small_heli , R.drawable.medium_heli , R.drawable.big_heli , R.drawable.huge_heli ),
56
  SKEW_2 ( 5, 2, 11, 11, R.drawable.small_skew2, R.drawable.medium_skew2, R.drawable.big_skew2, R.drawable.huge_skew2),
57
  SKEW_3 ( 5, 3, 17, 21, R.drawable.small_skew3, R.drawable.medium_skew3, R.drawable.big_skew3, R.drawable.huge_skew3),
58
  IVY_2  ( 5, 2,  8,  8, R.drawable.small_ivy  , R.drawable.medium_ivy  , R.drawable.big_ivy  , R.drawable.huge_ivy  ),
59
  REX_3  ( 5, 3, 16, 19, R.drawable.small_rex  , R.drawable.medium_rex  , R.drawable.big_rex  , R.drawable.huge_rex  ),
60
  BAN1_3 ( 6, 3, 16, 16, R.drawable.small_ban1 , R.drawable.medium_ban1 , R.drawable.big_ban1 , R.drawable.huge_ban1 ),
61
  BAN2_3 ( 6, 3, 16, 16, R.drawable.small_ban2 , R.drawable.medium_ban2 , R.drawable.big_ban2 , R.drawable.huge_ban2 ),
62
  BAN3_3 ( 6, 3, 16, 16, R.drawable.small_ban3 , R.drawable.medium_ban3 , R.drawable.big_ban3 , R.drawable.huge_ban3 ),
63
  BAN4_3 ( 6, 3, 16, 16, R.drawable.small_ban4 , R.drawable.medium_ban4 , R.drawable.big_ban4 , R.drawable.huge_ban4 ),
64
  SQU1_3 ( 7, 3, 24, 24, R.drawable.small_squa1, R.drawable.medium_squa1, R.drawable.big_squa1, R.drawable.huge_squa1),
65
  SQU2_3 ( 7, 3, 24, 24, R.drawable.small_squa2, R.drawable.medium_squa2, R.drawable.big_squa2, R.drawable.huge_squa2),
66
  MIRR_2 ( 7, 2, 12, 12, R.drawable.small_mirr2, R.drawable.medium_mirr2, R.drawable.big_mirr2, R.drawable.huge_mirr2),
67
  MIRR_3 ( 7, 3, 16, 17, R.drawable.small_mirr3, R.drawable.medium_mirr3, R.drawable.big_mirr3, R.drawable.huge_mirr3),
68
  ;
69

    
70
  public static final int NUM_OBJECTS = values().length;
71
  public static final int MAX_LEVEL,MAX_SCRAMBLE,MAX_OBJECT_SIZE;
72

    
73
  private final int mRow, mSize, mDBLevels, mNumScrambles;
74
  private final int mSmallIcon, mMediumIcon, mBigIcon, mHugeIcon;
75

    
76
  private static final ObjectType[] objects;
77
  private static int[] mIndices;
78
  private static int mColCount, mRowCount;
79

    
80
  static
81
    {
82
    int i = 0;
83
    objects = new ObjectType[NUM_OBJECTS];
84
    int maxLevel   = Integer.MIN_VALUE;
85
    int maxScramble= Integer.MIN_VALUE;
86
    int maxSize    = Integer.MIN_VALUE;
87

    
88
    for(ObjectType object: ObjectType.values())
89
      {
90
      objects[i++] = object;
91

    
92
      if( object.mNumScrambles> maxScramble ) maxScramble= object.mNumScrambles;
93
      if( object.mDBLevels    > maxLevel    ) maxLevel   = object.mDBLevels;
94
      if( object.mSize        > maxSize     ) maxSize    = object.mSize;
95
      }
96

    
97
    MAX_LEVEL       = maxLevel;
98
    MAX_SCRAMBLE    = maxScramble;
99
    MAX_OBJECT_SIZE = maxSize;
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  private static void setUpColAndRow()
105
    {
106
    mIndices = new int[NUM_OBJECTS];
107
    mRowCount= 0;
108

    
109
    for(int obj=0; obj<NUM_OBJECTS; obj++)
110
      {
111
      mIndices[obj] = objects[obj].mRow;
112
      if( mIndices[obj]>=mRowCount ) mRowCount = mIndices[obj]+1;
113
      }
114

    
115
    mColCount = 0;
116

    
117
    for(int row=0; row<mRowCount; row++)
118
      {
119
      int numObjects = computeNumObjectsInRow(row);
120
      if( numObjects>mColCount ) mColCount = numObjects;
121
      }
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  private static int computeNumObjectsInRow(int row)
127
    {
128
    int num=0;
129

    
130
    for(int object=0; object<NUM_OBJECTS; object++)
131
      {
132
      if( objects[object].mRow == row ) num++;
133
      }
134

    
135
    return num;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public static int getColumnCount()
141
    {
142
    if( mIndices==null ) setUpColAndRow();
143
    return mColCount;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public static int getRowCount()
149
    {
150
    if( mIndices==null ) setUpColAndRow();
151
    return mRowCount;
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  public static int[] getIndices()
157
    {
158
    if( mIndices==null ) setUpColAndRow();
159
    return mIndices;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public static ObjectType getObject(int ordinal)
165
    {
166
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public static int getOrdinal(String name)
172
    {
173
    for(int i=0; i<NUM_OBJECTS; i++)
174
      {
175
      if( objects[i].name().equals(name) ) return i;
176
      }
177

    
178
    return -1;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public static String getObjectList()
184
    {
185
    StringBuilder list = new StringBuilder();
186

    
187
    for(int i=0; i<NUM_OBJECTS; i++)
188
      {
189
      if( i>0 ) list.append(',');
190
      list.append(objects[i].name());
191
      }
192

    
193
    return list.toString();
194
    }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

    
198
  public static int getDBLevel(int ordinal)
199
    {
200
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mDBLevels : 0;
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  public static int getNumScramble(int ordinal)
206
    {
207
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mNumScrambles : 0;
208
    }
209

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

    
212
  ObjectType(int row, int size, int db, int scrambles, int sIcon, int mIcon, int bIcon, int hIcon)
213
    {
214
    mRow         = row;
215
    mSize        = size;
216
    mDBLevels    = db;
217
    mNumScrambles= scrambles;
218
    mSmallIcon   = sIcon;
219
    mMediumIcon  = mIcon;
220
    mBigIcon     = bIcon;
221
    mHugeIcon    = hIcon;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public int getIconID(int size)
227
    {
228
    switch(size)
229
      {
230
      case 0: return mSmallIcon;
231
      case 1: return mMediumIcon;
232
      case 2: return mBigIcon;
233
      case 3: return mHugeIcon;
234
      }
235

    
236
    return mSmallIcon;
237
    }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

    
241
  public TwistyObject create(Static4D quat, int[][] moves, Resources res, int scrWidth)
242
    {
243
    DistortedTexture texture = new DistortedTexture();
244
    DistortedEffects effects = new DistortedEffects();
245
    MeshSquare mesh          = new MeshSquare(20,20);   // mesh of the node, not of the cubits
246

    
247
    int ord = ordinal();
248
    int size= objects[ord].mSize;
249

    
250
    switch(ord)
251
      {
252
      case  0:
253
      case  1:
254
      case  2:
255
      case  3: return new TwistyCube          (size, quat, texture, mesh, effects, moves, res, scrWidth);
256
      case  4: return new TwistyJing          (size, quat, texture, mesh, effects, moves, res, scrWidth);
257
      case  5:
258
      case  6:
259
      case  7: return new TwistyPyraminx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
260
      case  8:
261
      case  9: return new TwistyKilominx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
262
      case 10:
263
      case 11: return new TwistyMegaminx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
264
      case 12: return new TwistyUltimate      (size, quat, texture, mesh, effects, moves, res, scrWidth);
265
      case 13:
266
      case 14:
267
      case 15: return new TwistyDiamond       (size, quat, texture, mesh, effects, moves, res, scrWidth);
268
      case 16: return new TwistyDino6         (size, quat, texture, mesh, effects, moves, res, scrWidth);
269
      case 17: return new TwistyDino4         (size, quat, texture, mesh, effects, moves, res, scrWidth);
270
      case 18: return new TwistyRedi          (size, quat, texture, mesh, effects, moves, res, scrWidth);
271
      case 19: return new TwistyHelicopter    (size, quat, texture, mesh, effects, moves, res, scrWidth);
272
      case 20:
273
      case 21: return new TwistySkewb         (size, quat, texture, mesh, effects, moves, res, scrWidth);
274
      case 22: return new TwistyIvy           (size, quat, texture, mesh, effects, moves, res, scrWidth);
275
      case 23: return new TwistyRex           (size, quat, texture, mesh, effects, moves, res, scrWidth);
276
      case 24: return new TwistyBandagedFused (size, quat, texture, mesh, effects, moves, res, scrWidth);
277
      case 25: return new TwistyBandaged2Bar  (size, quat, texture, mesh, effects, moves, res, scrWidth);
278
      case 26: return new TwistyBandaged3Plate(size, quat, texture, mesh, effects, moves, res, scrWidth);
279
      case 27: return new TwistyBandagedEvil  (size, quat, texture, mesh, effects, moves, res, scrWidth);
280
      case 28: return new TwistySquare1       (size, quat, texture, mesh, effects, moves, res, scrWidth);
281
      case 29: return new TwistySquare2       (size, quat, texture, mesh, effects, moves, res, scrWidth);
282
      case 30:
283
      case 31: return new TwistyMirror        (size, quat, texture, mesh, effects, moves, res, scrWidth);
284
      }
285

    
286
    return null;
287
    }
288
  }
(11-11/20)