Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectType.java @ 60bed292

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 java.io.InputStream;
23
import java.lang.reflect.Constructor;
24
import java.lang.reflect.InvocationTargetException;
25

    
26
import org.distorted.library.type.Static3D;
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 ( TwistyCuboid.class        , new int[] {2,2,2}      , 12, R.drawable.cube_2, true),
37
  CUBE_3 ( TwistyCuboid.class        , new int[] {3,3,3}      , 17, R.drawable.cube_3, true),
38
  CUBE_4 ( TwistyCuboid.class        , new int[] {4,4,4}      , 24, R.drawable.cube_4, true),
39
  CUBE_5 ( TwistyCuboid.class        , new int[] {5,5,5}      , 28, R.drawable.cube_5, true),
40
  CUBE_6 ( TwistyCuboid.class        , new int[] {6,6,6}      , 35, R.drawable.cube_6, true),
41
  CUBE_7 ( TwistyCuboid.class        , new int[] {7,7,7}      , 42, R.drawable.cube_7, true),
42
  BAN1_3 ( TwistyBandagedFused.class , new int[] {3,3,3}      , 16, R.drawable.ban1_3, true),
43
  BAN2_3 ( TwistyBandaged2Bar.class  , new int[] {3,3,3}      , 20, R.drawable.ban2_3, true),
44
  BAN3_3 ( TwistyBandaged3Plate.class, new int[] {3,3,3}      , 16, R.drawable.ban3_3, true),
45
  BAN4_3 ( TwistyBandagedBiCube.class, new int[] {3,3,3}      , 22, R.drawable.ban4_3, true),
46
  CU_323 ( TwistyCuboid.class        , new int[] {3,2,3}      , 15, R.drawable.cu_323, true),
47
  CU_232 ( TwistyCuboid.class        , new int[] {2,3,2}      , 16, R.drawable.cu_232, true),
48
  CU_343 ( TwistyCuboid.class        , new int[] {3,4,3}      , 23, R.drawable.cu_343, true),
49
  SQU1_3 ( TwistySquare1.class       , new int[] {3,2,3}      , 24, R.drawable.squ1_3, true),
50
  SQU2_3 ( TwistySquare2.class       , new int[] {3,2,3}      , 24, R.drawable.squ2_3, true),
51
  ULTI_2 ( TwistyUltimate.class      , new int[] {2,2,2,2}    , 18, R.drawable.ulti_2, true),
52
  KILO_3 ( TwistyKilominx.class      , new int[] {3,3,3,3,3,3}, 18, R.drawable.kilo_3, true),
53
  MEGA_3 ( TwistyMegaminx.class      , new int[] {3,3,3,3,3,3}, 21, R.drawable.mega_3, true),
54
  KILO_5 ( TwistyKilominx.class      , new int[] {5,5,5,5,5,5}, 33, R.drawable.kilo_5, true),
55
  MEGA_5 ( TwistyMegaminx.class      , new int[] {5,5,5,5,5,5}, 37, R.drawable.mega_5, true),
56
  MORP_2 ( TwistyMorphix.class       , new int[] {2,2,2}      , 12, R.drawable.morp_2, true),
57
  JING_2 ( TwistyJing.class          , new int[] {2,2,2,2}    , 11, R.drawable.jing_2, true),
58
  PYRA_3 ( TwistyPyraminx.class      , new int[] {3,3,3,3}    , 10, R.drawable.pyra_3, true),
59
  PYRA_4 ( TwistyPyraminx.class      , new int[] {4,4,4,4}    , 17, R.drawable.pyra_4, true),
60
  PYRA_5 ( TwistyPyraminx.class      , new int[] {5,5,5,5}    , 23, R.drawable.pyra_5, true),
61
  TRAJ_3 ( TwistyTrajber.class       , new int[] {3,3,3}      , 17, R.drawable.traj_3, true),
62
  TRAJ_4 ( TwistyTrajber.class       , new int[] {4,4,4}      , 24, R.drawable.traj_4, true),
63
  DIAM_2 ( TwistyDiamond.class       , new int[] {2,2,2,2}    , 12, R.drawable.diam_2, true),
64
  DIAM_3 ( TwistyDiamond.class       , new int[] {3,3,3,3}    , 24, R.drawable.diam_3, true),
65
  DIAM_4 ( TwistyDiamond.class       , new int[] {4,4,4,4}    , 32, R.drawable.diam_4, true),
66
  DINO_3 ( TwistyDino6.class         , new int[] {3,3,3,3}    , 10, R.drawable.dino_3, true),
67
  DIN4_3 ( TwistyDino4.class         , new int[] {3,3,3,3}    ,  7, R.drawable.din4_3, true),
68
  MIRR_2 ( TwistyMirror.class        , new int[] {2,2,2}      , 12, R.drawable.mirr_2, true),
69
  MIRR_3 ( TwistyMirror.class        , new int[] {3,3,3}      , 17, R.drawable.mirr_3, true),
70
  MIRR_4 ( TwistyMirror.class        , new int[] {4,4,4}      , 24, R.drawable.mirr_4, true),
71
  FISH_3 ( TwistyFisher.class        , new int[] {3,3,3}      , 24, R.drawable.fish_3, true),
72
  WIND_3 ( TwistyWindmill.class      , new int[] {3,3,3}      , 24, R.drawable.wind_3, true),
73
  AXIS_3 ( TwistyAxis.class          , new int[] {3,3,3}      , 24, R.drawable.axis_3, true),
74
  IVY_2  ( TwistyIvy.class           , new int[] {2,2,2,2}    ,  8, R.drawable.ivy_2 , true),
75
  REX_3  ( TwistyRex.class           , new int[] {3,3,3,3}    , 19, R.drawable.rex_3 , true),
76
  REDI_3 ( TwistyRedi.class          , new int[] {3,3,3,3}    , 16, R.drawable.redi_3, true),
77
  HELI_3 ( TwistyHelicopter.class    , new int[] {3,3,3,3,3,3}, 20, R.drawable.heli_3, true),
78
  SKEW_2 ( TwistySkewb.class         , new int[] {2,2,2,2}    , 11, R.drawable.skew_2, true),
79
  SKEW_3 ( TwistySkewb.class         , new int[] {3,3,3,3}    , 21, R.drawable.skew_3, true),
80
  CONT_2 ( TwistyContainer.class     , new int[] {2,2,2,2}    , 12, R.drawable.cont_2, true),
81

    
82
  MIXU_3 ( TwistyMixup3x3.class      , new int[] {3,3,3}      , 24, R.drawable.mixu_3, true),
83
  MIXP_3 ( TwistyMixup3x3Plus.class  , new int[] {3,3,3}      , 28, R.drawable.mixu_3, true),
84

    
85
  VOID_3 ( TwistyVoid.class          , new int[] {3,3,3}      , 17, R.drawable.void_3, false),  // wasDownloadableButNowIsBuiltIn()
86
  CRYS_3 ( TwistyCrystal.class       , new int[] {3,3,3,3,3,3}, 27, R.drawable.crys_3, false),  // function!
87
  STAR_3 ( TwistyStarminx.class      , new int[] {3,3,3,3,3,3}, 27, R.drawable.star_3, false),
88
  PENT_2 ( TwistyPentultimate.class  , new int[] {2,2,2,2,2,2}, 21, R.drawable.pent_2, false),
89

    
90
  ;
91

    
92
  public static int NUM_OBJECTS;
93
  private static final ObjectType[] objects;
94

    
95
  private final int[] mNumLayers;
96
  private final int mNumScrambles;
97
  private final int mIcon;
98
  private final boolean mExportToApp;
99
  private final Class<? extends TwistyObject> mClass;
100

    
101
  static
102
    {
103
    NUM_OBJECTS = 0;
104
    for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) NUM_OBJECTS++;
105

    
106
    int i = 0;
107
    objects = new ObjectType[NUM_OBJECTS];
108
    for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) objects[i++] = object;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  ObjectType(Class<? extends TwistyObject> clazz, int[] numLayers, int scrambles, int icon, boolean export)
114
    {
115
    mClass       = clazz;
116
    mNumLayers   = numLayers;
117
    mNumScrambles= scrambles;
118
    mIcon        = icon;
119
    mExportToApp = export;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
// PUBLIC API
124

    
125
  public static ObjectType getObject(int ordinal)
126
    {
127
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
128
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
// This is for the getDBLevel() function in RubikObjectList.
132

    
133
  public static boolean wasDownloadableButNowIsBuiltIn(int ord)
134
    {
135
    return ((ord>=CONT_2.ordinal() && ord<NUM_OBJECTS)      ||
136
             ord==MIRR_4.ordinal() || ord==FISH_3.ordinal() ||
137
             ord==AXIS_3.ordinal() || ord==MORP_2.ordinal()  );
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  public static int getOrdinal(String name)
143
    {
144
    for(int i=0; i<NUM_OBJECTS; i++)
145
      {
146
      if( objects[i].name().equals(name) ) return i;
147
      }
148

    
149
    return -1;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  public int getIconID()
155
    {
156
    return mIcon;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public int getNumScramble()
162
    {
163
    return mNumScrambles;
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  public static TwistyObject create(int ordinal, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream meshStream)
169
    {
170
    int[] numL= objects[ordinal].mNumLayers;
171
    Class<? extends TwistyObject> clazz = objects[ordinal].mClass;
172

    
173
    try
174
      {
175
      Constructor<?>[] cons = clazz.getConstructors();
176

    
177
      if( cons.length==1 )
178
        {
179
        Object[] parameters = new Object[] { numL,meshState,iconMode,quat,move,scale,meshStream };
180
        return (TwistyObject)cons[0].newInstance(parameters);
181
        }
182
      else
183
        {
184
        android.util.Log.e("ObjectType", "ERROR! number of TwistyObject constructors="+cons.length);
185
        }
186
      }
187
    catch(IllegalAccessException iae)
188
      {
189
      android.util.Log.e("ObjectType", "Illegal Access Exception: "+iae.getMessage());
190
      }
191
    catch(InstantiationException ie)
192
      {
193
      android.util.Log.e("ObjectType", "Instantiation Exception: "+ie.getMessage());
194
      }
195
    catch(InvocationTargetException ite)
196
      {
197
      android.util.Log.e("ObjectType", "Invocation Target Exception: "+ite.getMessage());
198
      }
199

    
200
    return null;
201
    }
202
  }
(5-5/12)