Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.main;
11

    
12
import java.lang.reflect.Constructor;
13
import java.lang.reflect.InvocationTargetException;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17

    
18
import org.distorted.objectlib.R;
19
import org.distorted.objectlib.objects.*;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public enum ObjectType
24
  {
25
  CUBE_2 ( TwistyCuboid.class         , 12, R.drawable.cube_2, true,     0, 1,1, new InitData(new int[] {2,2,2})),
26
  CUBE_3 ( TwistyCuboid.class         , 17, R.drawable.cube_3, true,     0, 1,1, new InitData(new int[] {3,3,3})),
27
  CUBE_4 ( TwistyCuboid.class         , 24, R.drawable.cube_4, true,    50, 1,1, new InitData(new int[] {4,4,4})),
28
  CUBE_5 ( TwistyCuboid.class         , 29, R.drawable.cube_5, true,    60, 1,1, new InitData(new int[] {5,5,5})),
29
  CUBE_6 ( TwistyCuboid.class         , 35, R.drawable.cube_6, true,    70, 1,1, new InitData(new int[] {6,6,6})),
30

    
31
  CUBE_7 ( TwistyCuboid.class         , 42, R.drawable.cube_7, true,   100, 1,1, new InitData(new int[] {7,7,7})),
32
  FISH_3 ( TwistyFisher.class         , 24, R.drawable.fish_3, true,    50, 1,1, new InitData(new int[] {3,3,3})),
33
  WIND_3 ( TwistyWindmill.class       , 24, R.drawable.wind_3, true,    50, 1,1, new InitData(new int[] {3,3,3})),
34
  AXIS_3 ( TwistyAxis.class           , 24, R.drawable.axis_3, true,    60, 1,1, new InitData(new int[] {3,3,3})),
35
  VOID_3 ( TwistyVoid.class           , 17, R.drawable.void_3, true,    70, 1,1, new InitData(new int[] {3,3,3})),
36

    
37
  CA_333 ( TwistyCamouflage.class     ,487, R.drawable.ca_333, true,    50, 1,1, new InitData(new int[] {4,4,4}, TwistyCamouflage.CAM_333)),
38
  BAN1_3 ( TwistyBandagedCuboid.class , 16, R.drawable.ban1_3, true,     0, 1,1, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_1)),
39
  BAN2_3 ( TwistyBandagedCuboid.class , 20, R.drawable.ban2_3, true,    50, 1,1, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_2)),
40
  BAN3_3 ( TwistyBandagedCuboid.class , 16, R.drawable.ban3_3, true,    50, 1,1, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_3)),
41
  BAN4_3 ( TwistyBandagedCuboid.class , 22, R.drawable.ban4_3, true,    60, 1,1, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_4)),
42

    
43
  BAN5_4 ( TwistyBandagedCuboid.class , 48, R.drawable.ban5_4, true,    50, 1,1, new InitData(new int[] {4,4,4}, TwistyBandagedCuboid.POS_5)),
44
  BAN6_4 ( TwistyBandagedCuboid.class ,487, R.drawable.ban6_4, true,    50, 1,1, new InitData(new int[] {4,4,4}, TwistyBandagedCuboid.POS_6)),
45
  CU_323 ( TwistyCuboid.class         , 15, R.drawable.cu_323, true,    40, 1,1, new InitData(new int[] {3,2,3})),
46
  CU_232 ( TwistyCuboid.class         , 16, R.drawable.cu_232, true,     0, 1,1, new InitData(new int[] {2,3,2})),
47
  CU_343 ( TwistyCuboid.class         , 23, R.drawable.cu_343, true,    50, 1,1, new InitData(new int[] {3,4,3})),
48

    
49
  PYRA_3 ( TwistyPyraminx.class       , 11, R.drawable.pyra_3, true,     0, 1,1, new InitData(new int[] {3,3,3,3})),
50
  PYRA_4 ( TwistyPyraminx.class       , 20, R.drawable.pyra_4, true,    50, 1,1, new InitData(new int[] {4,4,4,4})),
51
  PYRA_5 ( TwistyPyraminx.class       , 26, R.drawable.pyra_5, true,    60, 1,1, new InitData(new int[] {5,5,5,5})),
52
  PYRA_6 ( TwistyPyraminx.class       , 33, R.drawable.pyra_6, true,    70, 1,1, new InitData(new int[] {6,6,6,6})),
53
  PDUO_2 ( TwistyPyraminxDuo.class    ,  4, R.drawable.pduo_2, true,     0, 1,1, new InitData(new int[] {2,2,2,2})),
54

    
55
  JING_2 ( TwistyJing.class           , 11, R.drawable.jing_2, true,    50, 1,1, new InitData(new int[] {2,2,2,2}, TwistyJing.JING_2) ),
56
  JING_3 ( TwistyJing.class           , 20, R.drawable.jing_3, true,    50, 1,1, new InitData(new int[] {3,3,3,3}, TwistyJing.JING_3)),
57
  JING_4 ( TwistyJing.class           , 27, R.drawable.jing_4, true,    55, 1,1, new InitData(new int[] {3,3,3,3}, TwistyJing.JING_4)),
58
  JING_5 ( TwistyJing.class           , 35, R.drawable.jing_5, true,    60, 1,1, new InitData(new int[] {4,4,4,4}, TwistyJing.JING_5)),
59
  COIN_3 ( TwistyCoinTetrahedron.class, 15, R.drawable.coin_3, true,    40, 2,1, new InitData(new int[] {3,3,3,3})),
60

    
61
  MORP_2 ( TwistyMorphix.class        , 12, R.drawable.morp_2, true,     0, 1,1, new InitData(new int[] {2,2,2})),
62
  MORP_3 ( TwistyMorphix.class        , 17, R.drawable.morp_3, true,    60, 1,1, new InitData(new int[] {3,3,3})),
63
  MORP_4 ( TwistyMorphix.class        , 24, R.drawable.morp_4, true,    70, 1,1, new InitData(new int[] {4,4,4})),
64
  MIXU_3 ( TwistyMixup3x3.class       , 24, R.drawable.mixu_3, true,    70, 1,1, new InitData(new int[] {3,3,3})),
65
  MIXP_3 ( TwistyMixup3x3Plus.class   , 28, R.drawable.mixp_3, true,    70, 1,1, new InitData(new int[] {3,3,3})),
66

    
67
  CRYS_3 ( TwistyCrystal.class        , 27, R.drawable.crys_3, true,    70, 1,1, new InitData(new int[] {3,3,3,3,3,3})),
68
  STAR_3 ( TwistyStarminx.class       , 27, R.drawable.star_3, true,    80, 1,1, new InitData(new int[] {3,3,3,3,3,3})),
69
  PENT_2 ( TwistyPentultimate.class   , 21, R.drawable.pent_2, true,    80, 1,1, new InitData(new int[] {2,2,2,2,2,2})),
70
  ULTI_2 ( TwistyUltimate.class       , 18, R.drawable.ulti_2, true,    70, 1,1, new InitData(new int[] {2,2,2,2})),
71
  KILO_3 ( TwistyKilominx.class       , 18, R.drawable.kilo_3, true,    50, 1,1, new InitData(new int[] {3,3,3,3,3,3})),
72

    
73
  MEGA_3 ( TwistyMegaminx.class       , 21, R.drawable.mega_3, true,     0, 1,1, new InitData(new int[] {3,3,3,3,3,3})),
74
  KILO_5 ( TwistyKilominx.class       , 33, R.drawable.kilo_5, true,    80, 1,1, new InitData(new int[] {5,5,5,5,5,5})),
75
  MEGA_5 ( TwistyMegaminx.class       , 40, R.drawable.mega_5, true,   100, 1,1, new InitData(new int[] {5,5,5,5,5,5})),
76
  ICOS_2 ( TwistyIcosamate.class      , 30, R.drawable.icos_2, true,    60, 1,1, new InitData(new int[] {2,2,2,2,2,2})),
77
  ICOS_3 ( TwistyIcosamate.class      , 40, R.drawable.icos_3, true,    70, 1,1, new InitData(new int[] {3,3,3,3,3,3})),
78

    
79
  TRAJ_3 ( TwistyTrajber.class        , 17, R.drawable.traj_3, true,    50, 1,1, new InitData(new int[] {3,3,3})),
80
  TRAJ_4 ( TwistyTrajber.class        , 24, R.drawable.traj_4, true,    60, 1,1, new InitData(new int[] {4,4,4})),
81
  DIAM_2 ( TwistyDiamond.class        , 12, R.drawable.diam_2, true,     0, 1,1, new InitData(new int[] {2,2,2,2})),
82
  DIAM_3 ( TwistyDiamond.class        , 24, R.drawable.diam_3, true,    60, 1,1, new InitData(new int[] {3,3,3,3})),
83
  DIAM_4 ( TwistyDiamond.class        , 32, R.drawable.diam_4, true,    80, 1,1, new InitData(new int[] {4,4,4,4})),
84

    
85
  PDIA_3 ( TwistyPyraminxDiamond.class, 12, R.drawable.pdia_3, true,    40, 1,1, new InitData(new int[] {3,3,3})),
86
  BALL_4 ( TwistyMasterball.class     , 28, R.drawable.ball_4, true,    70, 1,1, new InitData(new int[] {4,2,2,2,2})),
87
  SQU0_3 ( TwistySquare0.class        , 18, R.drawable.squ0_3, true,    40, 1,1, new InitData(new int[] {3,2,3})),
88
  SQU1_3 ( TwistySquare1.class        , 24, R.drawable.squ1_3, true,    70, 1,1, new InitData(new int[] {3,2,3})),
89
  SQU2_3 ( TwistySquare2.class        , 24, R.drawable.squ2_3, true,    70, 1,1, new InitData(new int[] {3,2,3})),
90

    
91
  CRA1_2 ( TwistyCrazy2x2.class       , 16, R.drawable.cra1_2, true,    50, 1,1, new InitData(new int[] {2,2,2})),
92
  CRA1_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra1_3, true,    50, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.CRAZY  )),
93
  CRA2_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra2_3, true,    80, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.MERCURY)),
94
  CRA3_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra3_3, true,    80, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.VENUS  )),
95
  CRA4_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra4_3, true,    80, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.EARTH  )),
96

    
97
  CRA5_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra5_3, true,    80, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.MARS   )),
98
  CRA6_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra6_3, true,    60, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.JUPITER)),
99
  CRA7_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra7_3, true,    80, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.SATURN )),
100
  CRA8_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra8_3, true,    60, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.URANUS )),
101
  CRA9_3 ( TwistyCrazy3x3.class       , 22, R.drawable.cra9_3, true,    80, 1,1, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.NEPTUNE)),
102

    
103
  MIRR_2 ( TwistyMirror.class         , 12, R.drawable.mirr_2, true,     0, 1,1, new InitData(new int[] {2,2,2})),
104
  MIRR_3 ( TwistyMirror.class         , 17, R.drawable.mirr_3, true,    50, 1,1, new InitData(new int[] {3,3,3})),
105
  MIRR_4 ( TwistyMirror.class         , 24, R.drawable.mirr_4, true,    60, 1,1, new InitData(new int[] {4,4,4})),
106
  IVY_2  ( TwistyIvy.class            ,  9, R.drawable.ivy_2 , true,     0, 1,1, new InitData(new int[] {2,2,2,2})),
107
  REX_3  ( TwistyRex.class            , 19, R.drawable.rex_3 , true,    70, 1,1, new InitData(new int[] {3,3,3,3})),
108

    
109
  REDI_3 ( TwistyRedi.class           , 16, R.drawable.redi_3, true,     0, 1,1, new InitData(new int[] {3,3,3,3})),
110
  HELI_3 ( TwistyHelicopter.class     , 20, R.drawable.heli_3, true,    80, 1,1, new InitData(new int[] {3,3,3,3,3,3})),
111
  SKEW_2 ( TwistySkewb.class          , 11, R.drawable.skew_2, true,     0, 1,1, new InitData(new int[] {2,2,2,2})),
112
  SKEW_3 ( TwistySkewb.class          , 21, R.drawable.skew_3, true,    70, 1,1, new InitData(new int[] {3,3,3,3})),
113
  CONT_2 ( TwistyContainer.class      , 12, R.drawable.cont_2, true,    40, 1,1, new InitData(new int[] {2,2,2,2})),
114

    
115
  DINO_3 ( TwistyDino6.class          , 10, R.drawable.dino_3, true,     0, 1,1, new InitData(new int[] {3,3,3,3})),
116
  DIN4_3 ( TwistyDino4.class          ,  9, R.drawable.din4_3, true,    30, 1,1, new InitData(new int[] {3,3,3,3})),
117
  COIH_3 ( TwistyCoinHexahedron.class , 35, R.drawable.coih_3, true,    50, 1,1, new InitData(new int[] {3,3,3,3,3,3,3})),
118

    
119

    
120
    LATT_5 ( TwistyLattice.class        , 35, R.drawable.latt_5, true,   50, 1,1, new InitData(new int[] {5,5,5,5})),
121

    
122

    
123

    
124

    
125
    TINS_5 ( TwistyTins.class           , 28, R.drawable.tins_5, false,   60, 1,1, new InitData(new int[] {5,5,5,5})),
126
  O2_2   ( TwistyO2.class             ,  2, R.drawable.o2_2  , false,   20, 1,1, new InitData(new int[] {2,2,2})),
127
  DSKE_3 ( TwistyDinoSkewb.class      , 25, R.drawable.dske_3, false,   50, 1,1, new InitData(new int[] {3,3,3,3})),
128
  FADI_5 ( TwistyRedi.class           , 35, R.drawable.fadi_5, false,   60, 1,1, new InitData(new int[] {5,5,5,5})),
129

    
130
  ;
131

    
132
  public static int NUM_OBJECTS;
133
  public static final int DEFAULT_PRICE_OF_OLD_OBJECTS = 50;
134
  public static final int MAX_SCRAMBLES = 42;  // max scrambles at the time we switched from
135
                                               // remembering the records the old way
136
  private static final ObjectType[] objects;
137

    
138
  private final InitData mInitData;
139
  private final int mNumScrambles;
140
  private final int mIcon;
141
  private final int mObjectVersion, mExtrasVersion;
142
  private final boolean mExportToApp;
143
  private final int mPrice;
144
  private final Class<? extends TwistyObject> mClass;
145

    
146
  static
147
    {
148
    NUM_OBJECTS = 0;
149
    for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) NUM_OBJECTS++;
150

    
151
    int i = 0;
152
    objects = new ObjectType[NUM_OBJECTS];
153
    for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) objects[i++] = object;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  ObjectType(Class<? extends TwistyObject> clazz, int scrambles, int icon, boolean export, int price, int oVersion, int eVersion, InitData data)
159
    {
160
    mClass         = clazz;
161
    mInitData      = data;
162
    mNumScrambles  = scrambles;
163
    mIcon          = icon;
164
    mExportToApp   = export;
165
    mPrice         = price;
166
    mObjectVersion = oVersion;
167
    mExtrasVersion = eVersion;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
// PUBLIC API
172

    
173
  public static ObjectType getObject(int ordinal)
174
    {
175
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
176
    }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

    
180
  public static int getOrdinal(String name)
181
    {
182
    for(int i=0; i<NUM_OBJECTS; i++)
183
      {
184
      if( objects[i].name().equals(name) ) return i;
185
      }
186

    
187
    return -1;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  public static int getObjectVersion(int ordinal)
193
    {
194
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mObjectVersion : 0;
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

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

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  public int getIconID()
207
    {
208
    return mIcon;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  public int getNumScramble()
214
    {
215
    return mNumScrambles;
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  public int getPrice()
221
    {
222
    return mPrice;
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  public static TwistyObject create(int ordinal, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset)
228
    {
229
    /*
230
    if( ordinal==MORP_2.ordinal() )
231
      {
232
      return new TwistyMorphix(meshState,iconMode,quat,move,scale,objects[ordinal].mInitData,asset);
233
      }
234
    */
235

    
236
    if( ordinal>=NUM_OBJECTS || ordinal<0 ) ordinal =0;
237

    
238
    Class<? extends TwistyObject> clazz = objects[ordinal].mClass;
239

    
240
    try
241
      {
242
      Constructor<?>[] cons = clazz.getConstructors();
243

    
244
      if( cons.length==1 )
245
        {
246
        InitData data = objects[ordinal].mInitData;
247
        Object[] parameters = new Object[] { meshState,iconMode,quat,move,scale,data,asset };
248
        return (TwistyObject)cons[0].newInstance(parameters);
249
        }
250
      else
251
        {
252
        android.util.Log.e("ObjectType", "ERROR! number of TwistyObject constructors="+cons.length);
253
        }
254
      }
255
    catch(IllegalAccessException iae)
256
      {
257
      android.util.Log.e("ObjectType", "Illegal Access Exception: "+iae.getMessage());
258
      }
259
    catch(InstantiationException ie)
260
      {
261
      android.util.Log.e("ObjectType", "Instantiation Exception: "+ie.getMessage());
262
      }
263
    catch(InvocationTargetException ite)
264
      {
265
      android.util.Log.e("ObjectType", "Invocation Target Exception: "+ite.getMessage());
266
      }
267

    
268
    return null;
269
    }
270
  }
(5-5/10)