Project

General

Profile

« Previous | Next » 

Revision 6916789e

Added by Leszek Koltunski over 2 years ago

call the appropriate TwistyObject constructor by reflection.

View differences:

src/main/java/org/distorted/objectlib/main/ObjectType.java
20 20
package org.distorted.objectlib.main;
21 21

  
22 22
import java.io.InputStream;
23
import java.lang.reflect.Constructor;
24
import java.lang.reflect.InvocationTargetException;
23 25

  
24 26
import org.distorted.library.type.Static3D;
25 27
import org.distorted.library.type.Static4D;
......
31 33

  
32 34
public enum ObjectType
33 35
  {
34
  CUBE_2 ( new int[] {2,2,2}      , 12, R.drawable.cube_2s, R.drawable.cube_2m, R.drawable.cube_2b, R.drawable.cube_2h),
35
  CUBE_3 ( new int[] {3,3,3}      , 17, R.drawable.cube_3s, R.drawable.cube_3m, R.drawable.cube_3b, R.drawable.cube_3h),
36
  CUBE_4 ( new int[] {4,4,4}      , 24, R.drawable.cube_4s, R.drawable.cube_4m, R.drawable.cube_4b, R.drawable.cube_4h),
37
  CUBE_5 ( new int[] {5,5,5}      , 28, R.drawable.cube_5s, R.drawable.cube_5m, R.drawable.cube_5b, R.drawable.cube_5h),
38
  CUBE_6 ( new int[] {6,6,6}      , 35, R.drawable.cube_6s, R.drawable.cube_6m, R.drawable.cube_6b, R.drawable.cube_6h),
39
  CUBE_7 ( new int[] {7,7,7}      , 42, R.drawable.cube_7s, R.drawable.cube_7m, R.drawable.cube_7b, R.drawable.cube_7h),
40
  MIRR_2 ( new int[] {2,2,2}      , 12, R.drawable.mirr_2s, R.drawable.mirr_2m, R.drawable.mirr_2b, R.drawable.mirr_2h),
41
  MIRR_3 ( new int[] {3,3,3}      , 17, R.drawable.mirr_3s, R.drawable.mirr_3m, R.drawable.mirr_3b, R.drawable.mirr_3h),
42
  JING_2 ( new int[] {2,2,2,2}    , 11, R.drawable.jing_2s, R.drawable.jing_2m, R.drawable.jing_2b, R.drawable.jing_2h),
43
  PYRA_3 ( new int[] {3,3,3,3}    , 10, R.drawable.pyra_3s, R.drawable.pyra_3m, R.drawable.pyra_3b, R.drawable.pyra_3h),
44
  PYRA_4 ( new int[] {4,4,4,4}    , 17, R.drawable.pyra_4s, R.drawable.pyra_4m, R.drawable.pyra_4b, R.drawable.pyra_4h),
45
  PYRA_5 ( new int[] {5,5,5,5}    , 23, R.drawable.pyra_5s, R.drawable.pyra_5m, R.drawable.pyra_5b, R.drawable.pyra_5h),
46
  KILO_3 ( new int[] {3,3,3,3,3,3}, 18, R.drawable.kilo_3s, R.drawable.kilo_3m, R.drawable.kilo_3b, R.drawable.kilo_3h),
47
  KILO_5 ( new int[] {5,5,5,5,5,5}, 33, R.drawable.kilo_5s, R.drawable.kilo_5m, R.drawable.kilo_5b, R.drawable.kilo_5h),
48
  MEGA_3 ( new int[] {3,3,3,3,3,3}, 21, R.drawable.mega_3s, R.drawable.mega_3m, R.drawable.mega_3b, R.drawable.mega_3h),
49
  MEGA_5 ( new int[] {5,5,5,5,5,5}, 37, R.drawable.mega_5s, R.drawable.mega_5m, R.drawable.mega_5b, R.drawable.mega_5h),
50
  ULTI_2 ( new int[] {2,2,2,2}    , 18, R.drawable.ulti_2s, R.drawable.ulti_2m, R.drawable.ulti_2b, R.drawable.ulti_2h),
51
  DIAM_2 ( new int[] {2,2,2,2}    , 12, R.drawable.diam_2s, R.drawable.diam_2m, R.drawable.diam_2b, R.drawable.diam_2h),
52
  DIAM_3 ( new int[] {3,3,3,3}    , 24, R.drawable.diam_3s, R.drawable.diam_3m, R.drawable.diam_3b, R.drawable.diam_3h),
53
  DIAM_4 ( new int[] {4,4,4,4}    , 32, R.drawable.diam_4s, R.drawable.diam_4m, R.drawable.diam_4b, R.drawable.diam_4h),
54
  DINO_3 ( new int[] {3,3,3,3}    , 10, R.drawable.dino_3s, R.drawable.dino_3m, R.drawable.dino_3b, R.drawable.dino_3h),
55
  DIN4_3 ( new int[] {3,3,3,3}    ,  7, R.drawable.din4_3s, R.drawable.din4_3m, R.drawable.din4_3b, R.drawable.din4_3h),
56
  REDI_3 ( new int[] {3,3,3,3}    , 16, R.drawable.redi_3s, R.drawable.redi_3m, R.drawable.redi_3b, R.drawable.redi_3h),
57
  HELI_3 ( new int[] {3,3,3,3,3,3}, 20, R.drawable.heli_3s, R.drawable.heli_3m, R.drawable.heli_3b, R.drawable.heli_3h),
58
  SKEW_2 ( new int[] {2,2,2,2}    , 11, R.drawable.skew_2s, R.drawable.skew_2m, R.drawable.skew_2b, R.drawable.skew_2h),
59
  SKEW_3 ( new int[] {3,3,3,3}    , 21, R.drawable.skew_3s, R.drawable.skew_3m, R.drawable.skew_3b, R.drawable.skew_3h),
60
  IVY_2  ( new int[] {2,2,2,2}    ,  8, R.drawable.ivy_2s , R.drawable.ivy_2m , R.drawable.ivy_2b , R.drawable.ivy_2h ),
61
  REX_3  ( new int[] {3,3,3,3}    , 19, R.drawable.rex_3s , R.drawable.rex_3m , R.drawable.rex_3b , R.drawable.rex_3h ),
62
  BAN1_3 ( new int[] {3,3,3}      , 16, R.drawable.ban1_3s, R.drawable.ban1_3m, R.drawable.ban1_3b, R.drawable.ban1_3h),
63
  BAN2_3 ( new int[] {3,3,3}      , 16, R.drawable.ban2_3s, R.drawable.ban2_3m, R.drawable.ban2_3b, R.drawable.ban2_3h),
64
  BAN3_3 ( new int[] {3,3,3}      , 16, R.drawable.ban3_3s, R.drawable.ban3_3m, R.drawable.ban3_3b, R.drawable.ban3_3h),
65
  BAN4_3 ( new int[] {3,3,3}      , 16, R.drawable.ban4_3s, R.drawable.ban4_3m, R.drawable.ban4_3b, R.drawable.ban4_3h),
66
  SQU1_3 ( new int[] {3,2,3}      , 24, R.drawable.squ1_3s, R.drawable.squ1_3m, R.drawable.squ1_3b, R.drawable.squ1_3h),
67
  SQU2_3 ( new int[] {3,2,3}      , 24, R.drawable.squ2_3s, R.drawable.squ2_3m, R.drawable.squ2_3b, R.drawable.squ2_3h),
68
  CU_323 ( new int[] {3,2,3}      , 15, R.drawable.cu_323s, R.drawable.cu_323m, R.drawable.cu_323b, R.drawable.cu_323h),
69
  CU_232 ( new int[] {2,3,2}      , 16, R.drawable.cu_232s, R.drawable.cu_232m, R.drawable.cu_232b, R.drawable.cu_232h),
70
  CU_343 ( new int[] {3,4,3}      , 23, R.drawable.cu_343s, R.drawable.cu_343m, R.drawable.cu_343b, R.drawable.cu_343h),
36
  CUBE_2 ( TwistyCuboid.class        , new int[] {2,2,2}      , 12, R.drawable.cube_2s, R.drawable.cube_2m, R.drawable.cube_2b, R.drawable.cube_2h),
37
  CUBE_3 ( TwistyCuboid.class        , new int[] {3,3,3}      , 17, R.drawable.cube_3s, R.drawable.cube_3m, R.drawable.cube_3b, R.drawable.cube_3h),
38
  CUBE_4 ( TwistyCuboid.class        , new int[] {4,4,4}      , 24, R.drawable.cube_4s, R.drawable.cube_4m, R.drawable.cube_4b, R.drawable.cube_4h),
39
  CUBE_5 ( TwistyCuboid.class        , new int[] {5,5,5}      , 28, R.drawable.cube_5s, R.drawable.cube_5m, R.drawable.cube_5b, R.drawable.cube_5h),
40
  CUBE_6 ( TwistyCuboid.class        , new int[] {6,6,6}      , 35, R.drawable.cube_6s, R.drawable.cube_6m, R.drawable.cube_6b, R.drawable.cube_6h),
41
  CUBE_7 ( TwistyCuboid.class        , new int[] {7,7,7}      , 42, R.drawable.cube_7s, R.drawable.cube_7m, R.drawable.cube_7b, R.drawable.cube_7h),
42
  MIRR_2 ( TwistyMirror.class        , new int[] {2,2,2}      , 12, R.drawable.mirr_2s, R.drawable.mirr_2m, R.drawable.mirr_2b, R.drawable.mirr_2h),
43
  MIRR_3 ( TwistyMirror.class        , new int[] {3,3,3}      , 17, R.drawable.mirr_3s, R.drawable.mirr_3m, R.drawable.mirr_3b, R.drawable.mirr_3h),
44
  JING_2 ( TwistyJing.class          , new int[] {2,2,2,2}    , 11, R.drawable.jing_2s, R.drawable.jing_2m, R.drawable.jing_2b, R.drawable.jing_2h),
45
  PYRA_3 ( TwistyPyraminx.class      , new int[] {3,3,3,3}    , 10, R.drawable.pyra_3s, R.drawable.pyra_3m, R.drawable.pyra_3b, R.drawable.pyra_3h),
46
  PYRA_4 ( TwistyPyraminx.class      , new int[] {4,4,4,4}    , 17, R.drawable.pyra_4s, R.drawable.pyra_4m, R.drawable.pyra_4b, R.drawable.pyra_4h),
47
  PYRA_5 ( TwistyPyraminx.class      , new int[] {5,5,5,5}    , 23, R.drawable.pyra_5s, R.drawable.pyra_5m, R.drawable.pyra_5b, R.drawable.pyra_5h),
48
  KILO_3 ( TwistyKilominx.class      , new int[] {3,3,3,3,3,3}, 18, R.drawable.kilo_3s, R.drawable.kilo_3m, R.drawable.kilo_3b, R.drawable.kilo_3h),
49
  KILO_5 ( TwistyKilominx.class      , new int[] {5,5,5,5,5,5}, 33, R.drawable.kilo_5s, R.drawable.kilo_5m, R.drawable.kilo_5b, R.drawable.kilo_5h),
50
  MEGA_3 ( TwistyMegaminx.class      , new int[] {3,3,3,3,3,3}, 21, R.drawable.mega_3s, R.drawable.mega_3m, R.drawable.mega_3b, R.drawable.mega_3h),
51
  MEGA_5 ( TwistyMegaminx.class      , new int[] {5,5,5,5,5,5}, 37, R.drawable.mega_5s, R.drawable.mega_5m, R.drawable.mega_5b, R.drawable.mega_5h),
52
  ULTI_2 ( TwistyUltimate.class      , new int[] {2,2,2,2}    , 18, R.drawable.ulti_2s, R.drawable.ulti_2m, R.drawable.ulti_2b, R.drawable.ulti_2h),
53
  DIAM_2 ( TwistyDiamond.class       , new int[] {2,2,2,2}    , 12, R.drawable.diam_2s, R.drawable.diam_2m, R.drawable.diam_2b, R.drawable.diam_2h),
54
  DIAM_3 ( TwistyDiamond.class       , new int[] {3,3,3,3}    , 24, R.drawable.diam_3s, R.drawable.diam_3m, R.drawable.diam_3b, R.drawable.diam_3h),
55
  DIAM_4 ( TwistyDiamond.class       , new int[] {4,4,4,4}    , 32, R.drawable.diam_4s, R.drawable.diam_4m, R.drawable.diam_4b, R.drawable.diam_4h),
56
  DINO_3 ( TwistyDino6.class         , new int[] {3,3,3,3}    , 10, R.drawable.dino_3s, R.drawable.dino_3m, R.drawable.dino_3b, R.drawable.dino_3h),
57
  DIN4_3 ( TwistyDino4.class         , new int[] {3,3,3,3}    ,  7, R.drawable.din4_3s, R.drawable.din4_3m, R.drawable.din4_3b, R.drawable.din4_3h),
58
  REDI_3 ( TwistyRedi.class          , new int[] {3,3,3,3}    , 16, R.drawable.redi_3s, R.drawable.redi_3m, R.drawable.redi_3b, R.drawable.redi_3h),
59
  HELI_3 ( TwistyHelicopter.class    , new int[] {3,3,3,3,3,3}, 20, R.drawable.heli_3s, R.drawable.heli_3m, R.drawable.heli_3b, R.drawable.heli_3h),
60
  SKEW_2 ( TwistySkewb.class         , new int[] {2,2,2,2}    , 11, R.drawable.skew_2s, R.drawable.skew_2m, R.drawable.skew_2b, R.drawable.skew_2h),
61
  SKEW_3 ( TwistySkewb.class         , new int[] {3,3,3,3}    , 21, R.drawable.skew_3s, R.drawable.skew_3m, R.drawable.skew_3b, R.drawable.skew_3h),
62
  IVY_2  ( TwistyIvy.class           , new int[] {2,2,2,2}    ,  8, R.drawable.ivy_2s , R.drawable.ivy_2m , R.drawable.ivy_2b , R.drawable.ivy_2h ),
63
  REX_3  ( TwistyRex.class           , new int[] {3,3,3,3}    , 19, R.drawable.rex_3s , R.drawable.rex_3m , R.drawable.rex_3b , R.drawable.rex_3h ),
64
  BAN1_3 ( TwistyBandagedFused.class , new int[] {3,3,3}      , 16, R.drawable.ban1_3s, R.drawable.ban1_3m, R.drawable.ban1_3b, R.drawable.ban1_3h),
65
  BAN2_3 ( TwistyBandaged2Bar.class  , new int[] {3,3,3}      , 16, R.drawable.ban2_3s, R.drawable.ban2_3m, R.drawable.ban2_3b, R.drawable.ban2_3h),
66
  BAN3_3 ( TwistyBandaged3Plate.class, new int[] {3,3,3}      , 16, R.drawable.ban3_3s, R.drawable.ban3_3m, R.drawable.ban3_3b, R.drawable.ban3_3h),
67
  BAN4_3 ( TwistyBandagedEvil.class  , new int[] {3,3,3}      , 16, R.drawable.ban4_3s, R.drawable.ban4_3m, R.drawable.ban4_3b, R.drawable.ban4_3h),
68
  SQU1_3 ( TwistySquare1.class       , new int[] {3,2,3}      , 24, R.drawable.squ1_3s, R.drawable.squ1_3m, R.drawable.squ1_3b, R.drawable.squ1_3h),
69
  SQU2_3 ( TwistySquare1.class       , new int[] {3,2,3}      , 24, R.drawable.squ2_3s, R.drawable.squ2_3m, R.drawable.squ2_3b, R.drawable.squ2_3h),
70
  CU_323 ( TwistyCuboid.class        , new int[] {3,2,3}      , 15, R.drawable.cu_323s, R.drawable.cu_323m, R.drawable.cu_323b, R.drawable.cu_323h),
71
  CU_232 ( TwistyCuboid.class        , new int[] {2,3,2}      , 16, R.drawable.cu_232s, R.drawable.cu_232m, R.drawable.cu_232b, R.drawable.cu_232h),
72
  CU_343 ( TwistyCuboid.class        , new int[] {3,4,3}      , 23, R.drawable.cu_343s, R.drawable.cu_343m, R.drawable.cu_343b, R.drawable.cu_343h),
71 73
  ;
72 74

  
73 75
  public static final int NUM_OBJECTS = values().length;
......
76 78
  private final int[] mNumLayers;
77 79
  private final int mNumScrambles;
78 80
  private final int mSmallIcon, mMediumIcon, mBigIcon, mHugeIcon;
81
  private final Class<? extends TwistyObject> mClass;
79 82

  
80 83
  static
81 84
    {
......
105 108

  
106 109
///////////////////////////////////////////////////////////////////////////////////////////////////
107 110

  
108
  ObjectType(int[] numLayers, int scrambles, int sIcon, int mIcon, int bIcon, int hIcon)
111
  ObjectType(Class<? extends TwistyObject> clazz, int[] numLayers, int scrambles, int sIcon, int mIcon, int bIcon, int hIcon)
109 112
    {
113
    mClass       = clazz;
110 114
    mNumLayers   = numLayers;
111 115
    mNumScrambles= scrambles;
112 116
    mSmallIcon   = sIcon;
......
142 146
  public static TwistyObject create(int ordinal, Static4D quat, Static3D move, float scale, InputStream meshStream)
143 147
    {
144 148
    int[] numL= objects[ordinal].mNumLayers;
149
    Class<? extends TwistyObject> clazz = objects[ordinal].mClass;
145 150

  
146
    switch(ordinal)
151
    try
147 152
      {
148
      case  0:
149
      case  1:
150
      case  2:
151
      case  3:
152
      case  4:
153
      case  5: return new TwistyCuboid        (numL, quat, move, scale, meshStream);
154
      case  6:
155
      case  7: return new TwistyMirror        (numL, quat, move, scale, meshStream);
156
      case  8: return new TwistyJing          (numL, quat, move, scale, meshStream);
157
      case  9:
158
      case 10:
159
      case 11: return new TwistyPyraminx      (numL, quat, move, scale, meshStream);
160
      case 12:
161
      case 13: return new TwistyKilominx      (numL, quat, move, scale, meshStream);
162
      case 14:
163
      case 15: return new TwistyMegaminx      (numL, quat, move, scale, meshStream);
164
      case 16: return new TwistyUltimate      (numL, quat, move, scale, meshStream);
165
      case 17:
166
      case 18:
167
      case 19: return new TwistyDiamond       (numL, quat, move, scale, meshStream);
168

  
169
      case 20: return new TwistyDino6         (numL, quat, move, scale, meshStream);
170
      case 21: return new TwistyDino4         (numL, quat, move, scale, meshStream);
171
      case 22: return new TwistyRedi          (numL, quat, move, scale, meshStream);
172
      case 23: return new TwistyHelicopter    (numL, quat, move, scale, meshStream);
173
      case 24:
174
      case 25: return new TwistySkewb         (numL, quat, move, scale, meshStream);
175
      case 26: return new TwistyIvy           (numL, quat, move, scale, meshStream);
176
      case 27: return new TwistyRex           (numL, quat, move, scale, meshStream);
177
      case 28: return new TwistyBandagedFused (numL, quat, move, scale, meshStream);
178
      case 29: return new TwistyBandaged2Bar  (numL, quat, move, scale, meshStream);
179
      case 30: return new TwistyBandaged3Plate(numL, quat, move, scale, meshStream);
180
      case 31: return new TwistyBandagedEvil  (numL, quat, move, scale, meshStream);
181
      case 32: return new TwistySquare1       (numL, quat, move, scale, meshStream);
182
      case 33: return new TwistySquare2       (numL, quat, move, scale, meshStream);
183
      case 34:
184
      case 35:
185
      case 36: return new TwistyCuboid        (numL, quat, move, scale, meshStream);
153
      Constructor<?>[] cons = clazz.getConstructors();
154

  
155
      if( cons.length==1 )
156
        {
157
        Object[] parameters = new Object[] { numL,quat,move,scale,meshStream };
158
        return (TwistyObject)cons[0].newInstance(parameters);
159
        }
160
      else
161
        {
162
        android.util.Log.e("D", "ERROR! number of TwistyObject constructors="+cons.length);
163
        }
164
      }
165
    catch(IllegalAccessException iae)
166
      {
167
      android.util.Log.e("D", "Illegal Access Exception: "+iae.getMessage());
168
      }
169
    catch(InstantiationException ie)
170
      {
171
      android.util.Log.e("D", "Instantiation Exception: "+ie.getMessage());
172
      }
173
    catch(InvocationTargetException ite)
174
      {
175
      android.util.Log.e("D", "Invocation Target Exception: "+ite.getMessage());
186 176
      }
187 177

  
188 178
    return null;

Also available in: Unified diff