Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / metadata / ListObjects.java @ 743cdab7

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.metadata;
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.main.InitAssets;
19
import org.distorted.objectlib.main.TwistyObject;
20

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

    
23
public enum ListObjects
24
  {
25
  CUBE_2 ( new MetadataCuboid222()       ),
26
  CUBE_3 ( new MetadataCuboid333()       ),
27
  CUBE_4 ( new MetadataCuboid444()       ),
28
  CUBE_5 ( new MetadataCuboid555()       ),
29
  CUBE_6 ( new MetadataCuboid666()       ),
30

    
31
  CUBE_7 ( new MetadataCuboid777()       ),
32
  FISH_3 ( new MetadataFisher()          ),
33
  WIND_3 ( new MetadataWindmill()        ),
34
  AXIS_3 ( new MetadataAxis()            ),
35
  VOID_3 ( new MetadataVoid()            ),
36

    
37
  CA_333 ( new MetadataCamouflage333()   ),
38
  BAN1_3 ( new MetadataBandaged1_3()     ),
39
  BAN2_3 ( new MetadataBandaged2_3()     ),
40
  BAN3_3 ( new MetadataBandaged3_3()     ),
41
  BAN4_3 ( new MetadataBandaged4_3()     ),
42

    
43
  BAN5_4 ( new MetadataBandaged5_4()     ),
44
  BAN6_4 ( new MetadataBandaged6_4()     ),
45
  CU_323 ( new MetadataCuboid323()       ),
46
  CU_232 ( new MetadataCuboid232()       ),
47
  CU_343 ( new MetadataCuboid343()       ),
48

    
49
  PYRA_3 ( new MetadataPyraminx3()       ),
50
  PYRA_4 ( new MetadataPyraminx4()       ),
51
  PYRA_5 ( new MetadataPyraminx5()       ),
52
  PYRA_6 ( new MetadataPyraminx6()       ),
53
  PDUO_2 ( new MetadataPyraminxDuo()     ),
54

    
55
  JING_2 ( new MetadataJing2()           ),
56
  JING_3 ( new MetadataJing3()           ),
57
  JING_4 ( new MetadataJing4()           ),
58
  JING_5 ( new MetadataJing5()           ),
59
  COIN_3 ( new MetadataCoinTetrahedron() ),
60

    
61
  MORP_2 ( new MetadataMorphix2()        ),
62
  MORP_3 ( new MetadataMorphix3()        ),
63
  MORP_4 ( new MetadataMorphix4()        ),
64
  MIXU_3 ( new MetadataMixup333()        ),
65
  MIXP_3 ( new MetadataMixup333Plus()    ),
66

    
67
  CRYS_3 ( new MetadataCrystal()         ),
68
  STAR_3 ( new MetadataStarminx()        ),
69
  PENT_2 ( new MetadataPentultimate()    ),
70
  ULTI_2 ( new MetadataUltimate()        ),
71
  KILO_3 ( new MetadataKilominx3()       ),
72

    
73
  MEGA_3 ( new MetadataMegaminx3()       ),
74
  KILO_5 ( new MetadataKilominx5()       ),
75
  MEGA_5 ( new MetadataMegaminx5()       ),
76
  ICOS_2 ( new MetadataIcosamate2()      ),
77
  ICOS_3 ( new MetadataIcosamate3()      ),
78

    
79
  TRAJ_3 ( new MetadataTrajber3()        ),
80
  TRAJ_4 ( new MetadataTrajber4()        ),
81
  DIAM_2 ( new MetadataDiamond2()        ),
82
  DIAM_3 ( new MetadataDiamond3()        ),
83
  DIAM_4 ( new MetadataDiamond4()        ),
84

    
85
  PDIA_3 ( new MetadataPyraminxDiamond() ),
86
  BALL_4 ( new MetadataMasterball()      ),
87
  SQU0_3 ( new MetadataSquare0()         ),
88
  SQU1_3 ( new MetadataSquare1()         ),
89
  SQU2_3 ( new MetadataSquare2()         ),
90

    
91
  CRA1_2 ( new MetadataCrazy2x2()        ),
92
  CRA1_3 ( new MetadataCrazy3x3_1()      ),
93
  CRA2_3 ( new MetadataCrazy3x3_2()      ),
94
  CRA3_3 ( new MetadataCrazy3x3_3()      ),
95
  CRA4_3 ( new MetadataCrazy3x3_4()      ),
96

    
97
  CRA5_3 ( new MetadataCrazy3x3_5()      ),
98
  CRA6_3 ( new MetadataCrazy3x3_6()      ),
99
  CRA7_3 ( new MetadataCrazy3x3_7()      ),
100
  CRA8_3 ( new MetadataCrazy3x3_8()      ),
101
  CRA9_3 ( new MetadataCrazy3x3_9()      ),
102

    
103
  MIRR_2 ( new MetadataMirror2()         ),
104
  MIRR_3 ( new MetadataMirror3()         ),
105
  MIRR_4 ( new MetadataMirror4()         ),
106
  IVY_2  ( new MetadataIvy()             ),
107
  REX_3  ( new MetadataRex()             ),
108

    
109
  REDI_3 ( new MetadataRedi()            ),
110
  HELI_3 ( new MetadataHelicopter()      ),
111
  SKEW_2 ( new MetadataSkewb2()          ),
112
  SKEW_3 ( new MetadataSkewb3()          ),
113
  CONT_2 ( new MetadataContainer()       ),
114

    
115
  DINO_3 ( new MetadataDino6()           ),
116
  DIN4_3 ( new MetadataDino4()           ),
117
  COIH_3 ( new MetadataCoinHexahedron()  ),
118
  TINS_5 ( new MetadataTins()            ),
119
  O2_2   ( new MetadataO2()              ),
120

    
121
  DSKE_3 ( new MetadataDinoSkewb()       ),
122
  FADI_5 ( new MetadataFadi()            ),
123
  LATT_5 ( new MetadataLattice()         ),
124
  MSKE_2 ( new MetadataMirrorSkewb()     ),
125
  MJIN_2 ( new MetadataMirrorJing()      ),
126

    
127
  MPYR_3 ( new MetadataMirrorPyraminx()  ),
128
  CU_242 ( new MetadataCuboid242()       ),
129
  CU_424 ( new MetadataCuboid424()       ),
130
  CU_432 ( new MetadataCuboid432()       ),
131

    
132
  TEST_GHO ( new MetadataTestGhost()       ),
133
  ;
134

    
135
  public static final int NUM_OBJECTS;
136
  public static final int DEFAULT_PRICE_OF_OLD_OBJECTS = 50;
137
  public static final int MAX_SCRAMBLES = 42;  // max scrambles at the time we switched from
138
                                               // remembering the records the old way
139
  private static final ListObjects[] objects;
140

    
141
  private final Metadata mClassMet;
142

    
143
  static
144
    {
145
    NUM_OBJECTS = ListObjects.values().length;
146
    int i = 0;
147
    objects = new ListObjects[NUM_OBJECTS];
148
    for(ListObjects object: ListObjects.values()) objects[i++] = object;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  ListObjects(Metadata classM)
154
    {
155
    mClassMet = classM;
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
// PUBLIC API
160

    
161
  public static ListObjects getObject(int ordinal)
162
    {
163
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
164
    }
165

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

    
168
  public Metadata getMetadata()
169
    {
170
    return mClassMet;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public static TwistyObject create(int ordinal, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset)
176
    {
177
    /*
178
    if( ordinal==MPYR_3.ordinal() )
179
      {
180
      return new TwistyMirrorPyraminx(iconMode,quat,move,scale,objects[ordinal].mClassMet,asset);
181
      }
182
    */
183
    if( ordinal>=NUM_OBJECTS || ordinal<0 ) ordinal =0;
184

    
185
    Metadata meta = objects[ordinal].mClassMet;
186
    Class<? extends TwistyObject> classObj = meta.getObjectClass();
187

    
188
    try
189
      {
190
      Constructor<?>[] cons = classObj.getConstructors();
191

    
192
      if( cons.length==1 )
193
        {
194
        Object[] parameters = new Object[] { iconMode,quat,move,scale,meta,asset };
195
        return (TwistyObject)cons[0].newInstance(parameters);
196
        }
197
      else
198
        {
199
        android.util.Log.e("ObjectType", "ERROR! number of TwistyObject constructors="+cons.length);
200
        }
201
      }
202
    catch(IllegalAccessException iae)
203
      {
204
      android.util.Log.e("ObjectType", "Illegal Access Exception: "+iae.getMessage());
205
      }
206
    catch(InstantiationException ie)
207
      {
208
      android.util.Log.e("ObjectType", "Instantiation Exception: "+ie.getMessage());
209
      }
210
    catch(InvocationTargetException ite)
211
      {
212
      android.util.Log.e("ObjectType", "Invocation Target Exception: "+ite.getMessage());
213
      }
214

    
215
    return null;
216
    }
217
  }
(1-1/92)