Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / metadata / ListObjects.java @ 09d5cf2b

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 MetadataCUBE_2() ),
26
  CUBE_3 ( new MetadataCUBE_3() ),
27
  CUBE_4 ( new MetadataCUBE_4() ),
28
  CUBE_5 ( new MetadataCUBE_5() ),
29
  CUBE_6 ( new MetadataCUBE_6() ),
30

    
31
  CUBE_7 ( new MetadataCUBE_7() ),
32
  FISH_3 ( new MetadataFISH_3() ),
33
  WIND_3 ( new MetadataWIND_3() ),
34
  AXIS_3 ( new MetadataAXIS_3() ),
35
  VOID_3 ( new MetadataVOID_3() ),
36

    
37
  CA_333 ( new MetadataCA_333() ),
38
  BAN1_3 ( new MetadataBAN1_3() ),
39
  BAN2_3 ( new MetadataBAN2_3() ),
40
  BAN3_3 ( new MetadataBAN3_3() ),
41
  BAN4_3 ( new MetadataBAN4_3() ),
42

    
43
  BAN5_4 ( new MetadataBAN5_4() ),
44
  BAN6_4 ( new MetadataBAN6_4() ),
45
  CU_323 ( new MetadataCU_323() ),
46
  CU_232 ( new MetadataCU_232() ),
47
  CU_343 ( new MetadataCU_343() ),
48

    
49
  PYRA_3 ( new MetadataPYRA_3() ),
50
  PYRA_4 ( new MetadataPYRA_4() ),
51
  PYRA_5 ( new MetadataPYRA_5() ),
52
  PYRA_6 ( new MetadataPYRA_6() ),
53
  PDUO_2 ( new MetadataPDUO_2() ),
54

    
55
  JING_2 ( new MetadataJING_2() ),
56
  JING_3 ( new MetadataJING_3() ),
57
  JING_4 ( new MetadataJING_4() ),
58
  JING_5 ( new MetadataJING_5() ),
59
  COIN_3 ( new MetadataCOIN_3() ),
60

    
61
  MORP_2 ( new MetadataMORP_2() ),
62
  MORP_3 ( new MetadataMORP_3() ),
63
  MORP_4 ( new MetadataMORP_4() ),
64
  MIXU_3 ( new MetadataMIXU_3() ),
65
  MIXP_3 ( new MetadataMIXP_3() ),
66

    
67
  CRYS_3 ( new MetadataCRYS_3() ),
68
  STAR_3 ( new MetadataSTAR_3() ),
69
  PENT_2 ( new MetadataPENT_2() ),
70
  ULTI_2 ( new MetadataULTI_2() ),
71
  KILO_3 ( new MetadataKILO_3() ),
72

    
73
  MEGA_3 ( new MetadataMEGA_3() ),
74
  KILO_5 ( new MetadataKILO_5() ),
75
  MEGA_5 ( new MetadataMEGA_5() ),
76
  ICOS_2 ( new MetadataICOS_2() ),
77
  ICOS_3 ( new MetadataICOS_3() ),
78

    
79
  TRAJ_3 ( new MetadataTRAJ_3() ),
80
  TRAJ_4 ( new MetadataTRAJ_4() ),
81
  DIAM_2 ( new MetadataDIAM_2() ),
82
  DIAM_3 ( new MetadataDIAM_3() ),
83
  DIAM_4 ( new MetadataDIAM_4() ),
84

    
85
  PDIA_3 ( new MetadataPDIA_3() ),
86
  BALL_4 ( new MetadataBALL_4() ),
87
  SQU0_3 ( new MetadataSQU0_3() ),
88
  SQU1_3 ( new MetadataSQU1_3() ),
89
  SQU2_3 ( new MetadataSQU2_3() ),
90

    
91
  CRA1_2 ( new MetadataCRA1_2() ),
92
  CRA1_3 ( new MetadataCRA1_3() ),
93
  CRA2_3 ( new MetadataCRA2_3() ),
94
  CRA3_3 ( new MetadataCRA3_3() ),
95
  CRA4_3 ( new MetadataCRA4_3() ),
96

    
97
  CRA5_3 ( new MetadataCRA5_3() ),
98
  CRA6_3 ( new MetadataCRA6_3() ),
99
  CRA7_3 ( new MetadataCRA7_3() ),
100
  CRA8_3 ( new MetadataCRA8_3() ),
101
  CRA9_3 ( new MetadataCRA9_3() ),
102

    
103
  MIRR_2 ( new MetadataMIRR_2() ),
104
  MIRR_3 ( new MetadataMIRR_3() ),
105
  MIRR_4 ( new MetadataMIRR_4() ),
106
  IVY_2  ( new MetadataIVY_2()  ),
107
  REX_3  ( new MetadataREX_3()  ),
108

    
109
  REDI_3 ( new MetadataREDI_3() ),
110
  HELI_3 ( new MetadataHELI_3() ),
111
  SKEW_2 ( new MetadataSKEW_2() ),
112
  SKEW_3 ( new MetadataSKEW_3() ),
113
  CONT_2 ( new MetadataCONT_2() ),
114

    
115
  DINO_3 ( new MetadataDINO_3() ),
116
  DIN4_3 ( new MetadataDIN4_3() ),
117
  COIH_3 ( new MetadataCOIH_3() ),
118
  TINS_5 ( new MetadataTINS_5() ),
119
  O2_2   ( new MetadataO2_2()   ),
120

    
121
  DSKE_3 ( new MetadataDSKE_3() ),
122
  FADI_5 ( new MetadataFADI_5() ),
123
  LATT_5 ( new MetadataLATT_5() ),
124
  MSKE_2 ( new MetadataMSKE_2() ),
125
  MJIN_2 ( new MetadataMJIN_3() ),
126

    
127
  MPYR_3 ( new MetadataMPYR_3() ),
128
  CU_242 ( new MetadataCU_242() ),
129
  CU_424 ( new MetadataCU_424() ),
130
  CU_432 ( new MetadataCU_432() ),
131
  PENR_2 ( new MetadataPENR_2() ),
132

    
133
  PENR_3 ( new MetadataPENR_3() ),
134
  PENR_4 ( new MetadataPENR_4() ),
135
  CHES_2 ( new MetadataCHES_2() ),
136

    
137
  //OF_334 ( new MetadataOF_334() ),
138
  //TEST   ( new MetadataTEST()   ),
139
  ;
140

    
141
  public static final int NUM_OBJECTS;
142
  public static final int DEFAULT_PRICE_OF_OLD_OBJECTS = 50;
143
  public static final int MAX_SCRAMBLES = 42;  // max scrambles at the time we switched from
144
                                               // remembering the records the old way
145
  private static final ListObjects[] objects;
146

    
147
  private final Metadata mClassMet;
148

    
149
  static
150
    {
151
    NUM_OBJECTS = ListObjects.values().length;
152
    int i = 0;
153
    objects = new ListObjects[NUM_OBJECTS];
154
    for(ListObjects object: ListObjects.values()) objects[i++] = object;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  ListObjects(Metadata classM)
160
    {
161
    mClassMet = classM;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165
// PUBLIC API
166

    
167
  public static ListObjects getObject(int ordinal)
168
    {
169
    return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
  public boolean isEnabled()
175
    {
176
    return mClassMet.getActive();
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  public Metadata getMetadata()
182
    {
183
    return mClassMet;
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  public static TwistyObject create(int ordinal, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset)
189
    {
190
    /*
191
    if( ordinal==PENR_3.ordinal() )
192
      {
193
      return new TwistyPenrose(iconMode,quat,move,scale,objects[ordinal].mClassMet,asset);
194
      }
195
    */
196
    if( ordinal>=NUM_OBJECTS || ordinal<0 ) ordinal =0;
197

    
198
    Metadata meta = objects[ordinal].mClassMet;
199
    Class<? extends TwistyObject> classObj = meta.getObjectClass();
200

    
201
    try
202
      {
203
      Constructor<?>[] cons = classObj.getConstructors();
204

    
205
      if( cons.length==1 )
206
        {
207
        Object[] parameters = new Object[] { iconMode,quat,move,scale,meta,asset };
208
        return (TwistyObject)cons[0].newInstance(parameters);
209
        }
210
      else
211
        {
212
        android.util.Log.e("ObjectType", "ERROR! number of TwistyObject constructors="+cons.length);
213
        }
214
      }
215
    catch(IllegalAccessException iae)
216
      {
217
      android.util.Log.e("ObjectType", "Illegal Access Exception: "+iae.getMessage());
218
      }
219
    catch(InstantiationException ie)
220
      {
221
      android.util.Log.e("ObjectType", "Instantiation Exception: "+ie.getMessage());
222
      }
223
    catch(InvocationTargetException ite)
224
      {
225
      android.util.Log.e("ObjectType", "Invocation Target Exception: "+ite.getMessage());
226
      }
227

    
228
    return null;
229
    }
230
  }
(1-1/97)