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.metadata.*;
|
19
|
|
20
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
21
|
|
22
|
public enum ObjectType
|
23
|
{
|
24
|
CUBE_2 ( new MetadataCuboid222() ),
|
25
|
CUBE_3 ( new MetadataCuboid333() ),
|
26
|
CUBE_4 ( new MetadataCuboid444() ),
|
27
|
CUBE_5 ( new MetadataCuboid555() ),
|
28
|
CUBE_6 ( new MetadataCuboid666() ),
|
29
|
|
30
|
CUBE_7 ( new MetadataCuboid777() ),
|
31
|
FISH_3 ( new MetadataFisher() ),
|
32
|
WIND_3 ( new MetadataWindmill() ),
|
33
|
AXIS_3 ( new MetadataAxis() ),
|
34
|
VOID_3 ( new MetadataVoid() ),
|
35
|
|
36
|
CA_333 ( new MetadataCamouflage333() ),
|
37
|
BAN1_3 ( new MetadataBandaged1_3() ),
|
38
|
BAN2_3 ( new MetadataBandaged2_3() ),
|
39
|
BAN3_3 ( new MetadataBandaged3_3() ),
|
40
|
BAN4_3 ( new MetadataBandaged4_3() ),
|
41
|
|
42
|
BAN5_4 ( new MetadataBandaged5_4() ),
|
43
|
BAN6_4 ( new MetadataBandaged6_4() ),
|
44
|
CU_323 ( new MetadataCuboid323() ),
|
45
|
CU_232 ( new MetadataCuboid232() ),
|
46
|
CU_343 ( new MetadataCuboid343() ),
|
47
|
|
48
|
PYRA_3 ( new MetadataPyraminx3() ),
|
49
|
PYRA_4 ( new MetadataPyraminx4() ),
|
50
|
PYRA_5 ( new MetadataPyraminx5() ),
|
51
|
PYRA_6 ( new MetadataPyraminx6() ),
|
52
|
PDUO_2 ( new MetadataPyraminxDuo() ),
|
53
|
|
54
|
JING_2 ( new MetadataJing2() ),
|
55
|
JING_3 ( new MetadataJing3() ),
|
56
|
JING_4 ( new MetadataJing4() ),
|
57
|
JING_5 ( new MetadataJing5() ),
|
58
|
COIN_3 ( new MetadataCoinTetrahedron() ),
|
59
|
|
60
|
MORP_2 ( new MetadataMorphix2() ),
|
61
|
MORP_3 ( new MetadataMorphix3() ),
|
62
|
MORP_4 ( new MetadataMorphix4() ),
|
63
|
MIXU_3 ( new MetadataMixup333() ),
|
64
|
MIXP_3 ( new MetadataMixup333Plus() ),
|
65
|
|
66
|
CRYS_3 ( new MetadataCrystal() ),
|
67
|
STAR_3 ( new MetadataStarminx() ),
|
68
|
PENT_2 ( new MetadataPentultimate() ),
|
69
|
ULTI_2 ( new MetadataUltimate() ),
|
70
|
KILO_3 ( new MetadataKilominx3() ),
|
71
|
|
72
|
MEGA_3 ( new MetadataMegaminx3() ),
|
73
|
KILO_5 ( new MetadataKilominx5() ),
|
74
|
MEGA_5 ( new MetadataMegaminx5() ),
|
75
|
ICOS_2 ( new MetadataIcosamate2() ),
|
76
|
ICOS_3 ( new MetadataIcosamate3() ),
|
77
|
|
78
|
TRAJ_3 ( new MetadataTrajber3() ),
|
79
|
TRAJ_4 ( new MetadataTrajber4() ),
|
80
|
DIAM_2 ( new MetadataDiamond2() ),
|
81
|
DIAM_3 ( new MetadataDiamond3() ),
|
82
|
DIAM_4 ( new MetadataDiamond4() ),
|
83
|
|
84
|
PDIA_3 ( new MetadataPyraminxDiamond() ),
|
85
|
BALL_4 ( new MetadataMasterball() ),
|
86
|
SQU0_3 ( new MetadataSquare0() ),
|
87
|
SQU1_3 ( new MetadataSquare1() ),
|
88
|
SQU2_3 ( new MetadataSquare2() ),
|
89
|
|
90
|
CRA1_2 ( new MetadataCrazy2x2() ),
|
91
|
CRA1_3 ( new MetadataCrazy3x3_1() ),
|
92
|
CRA2_3 ( new MetadataCrazy3x3_2() ),
|
93
|
CRA3_3 ( new MetadataCrazy3x3_3() ),
|
94
|
CRA4_3 ( new MetadataCrazy3x3_4() ),
|
95
|
|
96
|
CRA5_3 ( new MetadataCrazy3x3_5() ),
|
97
|
CRA6_3 ( new MetadataCrazy3x3_6() ),
|
98
|
CRA7_3 ( new MetadataCrazy3x3_7() ),
|
99
|
CRA8_3 ( new MetadataCrazy3x3_8() ),
|
100
|
CRA9_3 ( new MetadataCrazy3x3_9() ),
|
101
|
|
102
|
MIRR_2 ( new MetadataMirror2() ),
|
103
|
MIRR_3 ( new MetadataMirror3() ),
|
104
|
MIRR_4 ( new MetadataMirror4() ),
|
105
|
IVY_2 ( new MetadataIvy() ),
|
106
|
REX_3 ( new MetadataRex() ),
|
107
|
|
108
|
REDI_3 ( new MetadataRedi() ),
|
109
|
HELI_3 ( new MetadataHelicopter() ),
|
110
|
SKEW_2 ( new MetadataSkewb2() ),
|
111
|
SKEW_3 ( new MetadataSkewb3() ),
|
112
|
CONT_2 ( new MetadataContainer() ),
|
113
|
|
114
|
DINO_3 ( new MetadataDino6() ),
|
115
|
DIN4_3 ( new MetadataDino4() ),
|
116
|
COIH_3 ( new MetadataCoinHexahedron() ),
|
117
|
TINS_5 ( new MetadataTins() ),
|
118
|
O2_2 ( new MetadataO2() ),
|
119
|
|
120
|
DSKE_3 ( new MetadataDinoSkewb() ),
|
121
|
FADI_5 ( new MetadataFadi() ),
|
122
|
LATT_5 ( new MetadataLattice() ),
|
123
|
MSKE_2 ( new MetadataMirrorSkewb() ),
|
124
|
MJIN_2 ( new MetadataMirrorJing() ),
|
125
|
|
126
|
MPYR_3 ( new MetadataMirrorPyraminx() ),
|
127
|
CU_242 ( new MetadataCuboid242() ),
|
128
|
CU_424 ( new MetadataCuboid424() ),
|
129
|
CU_432 ( new MetadataCuboid432() ),
|
130
|
|
131
|
TEST_GHO ( new MetadataTestGhost() ),
|
132
|
;
|
133
|
|
134
|
public static final int NUM_OBJECTS;
|
135
|
public static final int DEFAULT_PRICE_OF_OLD_OBJECTS = 50;
|
136
|
public static final int MAX_SCRAMBLES = 42; // max scrambles at the time we switched from
|
137
|
// remembering the records the old way
|
138
|
private static final ObjectType[] objects;
|
139
|
|
140
|
private final Metadata mClassMet;
|
141
|
|
142
|
static
|
143
|
{
|
144
|
NUM_OBJECTS = ObjectType.values().length;
|
145
|
int i = 0;
|
146
|
objects = new ObjectType[NUM_OBJECTS];
|
147
|
for(ObjectType object: ObjectType.values()) objects[i++] = object;
|
148
|
}
|
149
|
|
150
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151
|
|
152
|
ObjectType(Metadata classM)
|
153
|
{
|
154
|
mClassMet = classM;
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
// PUBLIC API
|
159
|
|
160
|
public static ObjectType getObject(int ordinal)
|
161
|
{
|
162
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
public Metadata getMetadata()
|
168
|
{
|
169
|
return mClassMet;
|
170
|
}
|
171
|
|
172
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173
|
|
174
|
public static TwistyObject create(int ordinal, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset)
|
175
|
{
|
176
|
/*
|
177
|
if( ordinal==MPYR_3.ordinal() )
|
178
|
{
|
179
|
return new TwistyMirrorPyraminx(iconMode,quat,move,scale,objects[ordinal].mClassMet,asset);
|
180
|
}
|
181
|
*/
|
182
|
if( ordinal>=NUM_OBJECTS || ordinal<0 ) ordinal =0;
|
183
|
|
184
|
Metadata meta = objects[ordinal].mClassMet;
|
185
|
Class<? extends TwistyObject> classObj = meta.getObjectClass();
|
186
|
|
187
|
try
|
188
|
{
|
189
|
Constructor<?>[] cons = classObj.getConstructors();
|
190
|
|
191
|
if( cons.length==1 )
|
192
|
{
|
193
|
Object[] parameters = new Object[] { iconMode,quat,move,scale,meta,asset };
|
194
|
return (TwistyObject)cons[0].newInstance(parameters);
|
195
|
}
|
196
|
else
|
197
|
{
|
198
|
android.util.Log.e("ObjectType", "ERROR! number of TwistyObject constructors="+cons.length);
|
199
|
}
|
200
|
}
|
201
|
catch(IllegalAccessException iae)
|
202
|
{
|
203
|
android.util.Log.e("ObjectType", "Illegal Access Exception: "+iae.getMessage());
|
204
|
}
|
205
|
catch(InstantiationException ie)
|
206
|
{
|
207
|
android.util.Log.e("ObjectType", "Instantiation Exception: "+ie.getMessage());
|
208
|
}
|
209
|
catch(InvocationTargetException ite)
|
210
|
{
|
211
|
android.util.Log.e("ObjectType", "Invocation Target Exception: "+ite.getMessage());
|
212
|
}
|
213
|
|
214
|
return null;
|
215
|
}
|
216
|
}
|