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 , 12, R.drawable.cube_2, true, new InitData(new int[] {2,2,2})),
|
37
|
CUBE_3 ( TwistyCuboid.class , 17, R.drawable.cube_3, true, new InitData(new int[] {3,3,3})),
|
38
|
CUBE_4 ( TwistyCuboid.class , 24, R.drawable.cube_4, true, new InitData(new int[] {4,4,4})),
|
39
|
CUBE_5 ( TwistyCuboid.class , 28, R.drawable.cube_5, true, new InitData(new int[] {5,5,5})),
|
40
|
CUBE_6 ( TwistyCuboid.class , 35, R.drawable.cube_6, true, new InitData(new int[] {6,6,6})),
|
41
|
CUBE_7 ( TwistyCuboid.class , 42, R.drawable.cube_7, true, new InitData(new int[] {7,7,7})),
|
42
|
BAN1_3 ( TwistyBandagedCuboid.class, 16, R.drawable.ban1_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_1)),
|
43
|
BAN2_3 ( TwistyBandagedCuboid.class, 20, R.drawable.ban2_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_2)),
|
44
|
BAN3_3 ( TwistyBandagedCuboid.class, 16, R.drawable.ban3_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_3)),
|
45
|
BAN4_3 ( TwistyBandagedCuboid.class, 22, R.drawable.ban4_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_4)),
|
46
|
CU_323 ( TwistyCuboid.class , 15, R.drawable.cu_323, true, new InitData(new int[] {3,2,3})),
|
47
|
CU_232 ( TwistyCuboid.class , 16, R.drawable.cu_232, true, new InitData(new int[] {2,3,2})),
|
48
|
CU_343 ( TwistyCuboid.class , 23, R.drawable.cu_343, true, new InitData(new int[] {3,4,3})),
|
49
|
SQU1_3 ( TwistySquare1.class , 24, R.drawable.squ1_3, true, new InitData(new int[] {3,2,3})),
|
50
|
SQU2_3 ( TwistySquare2.class , 24, R.drawable.squ2_3, true, new InitData(new int[] {3,2,3})),
|
51
|
ULTI_2 ( TwistyUltimate.class , 18, R.drawable.ulti_2, true, new InitData(new int[] {2,2,2,2})),
|
52
|
KILO_3 ( TwistyKilominx.class , 18, R.drawable.kilo_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
53
|
MEGA_3 ( TwistyMegaminx.class , 21, R.drawable.mega_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
54
|
KILO_5 ( TwistyKilominx.class , 33, R.drawable.kilo_5, true, new InitData(new int[] {5,5,5,5,5,5})),
|
55
|
MEGA_5 ( TwistyMegaminx.class , 37, R.drawable.mega_5, true, new InitData(new int[] {5,5,5,5,5,5})),
|
56
|
MORP_2 ( TwistyMorphix.class , 12, R.drawable.morp_2, true, new InitData(new int[] {2,2,2})),
|
57
|
JING_2 ( TwistyJing.class , 11, R.drawable.jing_2, true, new InitData(new int[] {2,2,2,2})),
|
58
|
PYRA_3 ( TwistyPyraminx.class , 10, R.drawable.pyra_3, true, new InitData(new int[] {3,3,3,3})),
|
59
|
PYRA_4 ( TwistyPyraminx.class , 17, R.drawable.pyra_4, true, new InitData(new int[] {4,4,4,4})),
|
60
|
PYRA_5 ( TwistyPyraminx.class , 23, R.drawable.pyra_5, true, new InitData(new int[] {5,5,5,5})),
|
61
|
TRAJ_3 ( TwistyTrajber.class , 17, R.drawable.traj_3, true, new InitData(new int[] {3,3,3})),
|
62
|
TRAJ_4 ( TwistyTrajber.class , 24, R.drawable.traj_4, true, new InitData(new int[] {4,4,4})),
|
63
|
DIAM_2 ( TwistyDiamond.class , 12, R.drawable.diam_2, true, new InitData(new int[] {2,2,2,2})),
|
64
|
DIAM_3 ( TwistyDiamond.class , 24, R.drawable.diam_3, true, new InitData(new int[] {3,3,3,3})),
|
65
|
DIAM_4 ( TwistyDiamond.class , 32, R.drawable.diam_4, true, new InitData(new int[] {4,4,4,4})),
|
66
|
DINO_3 ( TwistyDino6.class , 10, R.drawable.dino_3, true, new InitData(new int[] {3,3,3,3})),
|
67
|
DIN4_3 ( TwistyDino4.class , 7, R.drawable.din4_3, true, new InitData(new int[] {3,3,3,3})),
|
68
|
MIRR_2 ( TwistyMirror.class , 12, R.drawable.mirr_2, true, new InitData(new int[] {2,2,2})),
|
69
|
MIRR_3 ( TwistyMirror.class , 17, R.drawable.mirr_3, true, new InitData(new int[] {3,3,3})),
|
70
|
MIRR_4 ( TwistyMirror.class , 24, R.drawable.mirr_4, true, new InitData(new int[] {4,4,4})),
|
71
|
FISH_3 ( TwistyFisher.class , 24, R.drawable.fish_3, true, new InitData(new int[] {3,3,3})),
|
72
|
WIND_3 ( TwistyWindmill.class , 24, R.drawable.wind_3, true, new InitData(new int[] {3,3,3})),
|
73
|
AXIS_3 ( TwistyAxis.class , 24, R.drawable.axis_3, true, new InitData(new int[] {3,3,3})),
|
74
|
IVY_2 ( TwistyIvy.class , 8, R.drawable.ivy_2 , true, new InitData(new int[] {2,2,2,2})),
|
75
|
REX_3 ( TwistyRex.class , 19, R.drawable.rex_3 , true, new InitData(new int[] {3,3,3,3})),
|
76
|
REDI_3 ( TwistyRedi.class , 16, R.drawable.redi_3, true, new InitData(new int[] {3,3,3,3})),
|
77
|
HELI_3 ( TwistyHelicopter.class , 20, R.drawable.heli_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
78
|
SKEW_2 ( TwistySkewb.class , 11, R.drawable.skew_2, true, new InitData(new int[] {2,2,2,2})),
|
79
|
SKEW_3 ( TwistySkewb.class , 21, R.drawable.skew_3, true, new InitData(new int[] {3,3,3,3})),
|
80
|
CONT_2 ( TwistyContainer.class , 12, R.drawable.cont_2, true, new InitData(new int[] {2,2,2,2})),
|
81
|
|
82
|
CRA1_2 ( TwistyCrazy2x2.class , 16, R.drawable.cra1_2, true, new InitData(new int[] {2,2,2} )),
|
83
|
CRA1_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.CRAZY )),
|
84
|
CRA2_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.MERCURY)),
|
85
|
CRA3_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.VENUS )),
|
86
|
CRA4_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.EARTH )),
|
87
|
CRA5_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.MARS )),
|
88
|
CRA6_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.JUPITER)),
|
89
|
CRA7_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.SATURN )),
|
90
|
CRA8_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.URANUS )),
|
91
|
CRA9_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, true, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.NEPTUNE)),
|
92
|
|
93
|
VOID_3 ( TwistyVoid.class , 17, R.drawable.void_3, false, new InitData(new int[] {3,3,3})), // wasDownloadableButNowIsBuiltIn()
|
94
|
CRYS_3 ( TwistyCrystal.class , 27, R.drawable.crys_3, false, new InitData(new int[] {3,3,3,3,3,3})), // function!
|
95
|
STAR_3 ( TwistyStarminx.class , 27, R.drawable.star_3, false, new InitData(new int[] {3,3,3,3,3,3})),
|
96
|
PENT_2 ( TwistyPentultimate.class , 21, R.drawable.pent_2, false, new InitData(new int[] {2,2,2,2,2,2})),
|
97
|
MIXU_3 ( TwistyMixup3x3.class , 24, R.drawable.mixu_3, false, new InitData(new int[] {3,3,3})),
|
98
|
MIXP_3 ( TwistyMixup3x3Plus.class , 28, R.drawable.mixp_3, false, new InitData(new int[] {3,3,3})),
|
99
|
;
|
100
|
|
101
|
public static int NUM_OBJECTS;
|
102
|
private static final ObjectType[] objects;
|
103
|
|
104
|
private final InitData mInitData;
|
105
|
private final int mNumScrambles;
|
106
|
private final int mIcon;
|
107
|
private final boolean mExportToApp;
|
108
|
private final Class<? extends TwistyObject> mClass;
|
109
|
|
110
|
static
|
111
|
{
|
112
|
NUM_OBJECTS = 0;
|
113
|
for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) NUM_OBJECTS++;
|
114
|
|
115
|
int i = 0;
|
116
|
objects = new ObjectType[NUM_OBJECTS];
|
117
|
for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) objects[i++] = object;
|
118
|
}
|
119
|
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121
|
|
122
|
ObjectType(Class<? extends TwistyObject> clazz, int scrambles, int icon, boolean export, InitData data)
|
123
|
{
|
124
|
mClass = clazz;
|
125
|
mInitData = data;
|
126
|
mNumScrambles= scrambles;
|
127
|
mIcon = icon;
|
128
|
mExportToApp = export;
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
// PUBLIC API
|
133
|
|
134
|
public static ObjectType getObject(int ordinal)
|
135
|
{
|
136
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
// This is for the getDBLevel() function in RubikObjectList.
|
141
|
|
142
|
public static boolean wasDownloadableButNowIsBuiltIn(int ord)
|
143
|
{
|
144
|
return ((ord>=CONT_2.ordinal() && ord<NUM_OBJECTS) ||
|
145
|
ord==MIRR_4.ordinal() || ord==FISH_3.ordinal() ||
|
146
|
ord==AXIS_3.ordinal() || ord==MORP_2.ordinal() );
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
public static int getOrdinal(String name)
|
152
|
{
|
153
|
for(int i=0; i<NUM_OBJECTS; i++)
|
154
|
{
|
155
|
if( objects[i].name().equals(name) ) return i;
|
156
|
}
|
157
|
|
158
|
return -1;
|
159
|
}
|
160
|
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
|
163
|
public int getIconID()
|
164
|
{
|
165
|
return mIcon;
|
166
|
}
|
167
|
|
168
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169
|
|
170
|
public int getNumScramble()
|
171
|
{
|
172
|
return mNumScrambles;
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
public static TwistyObject create(int ordinal, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream meshStream)
|
178
|
{
|
179
|
/*
|
180
|
if( ordinal==CRA1_3.ordinal() )
|
181
|
{
|
182
|
return new TwistyCrazy3x3(objects[ordinal].mInitData,meshState,iconMode,quat,move,scale,meshStream);
|
183
|
}
|
184
|
*/
|
185
|
Class<? extends TwistyObject> clazz = objects[ordinal].mClass;
|
186
|
|
187
|
try
|
188
|
{
|
189
|
Constructor<?>[] cons = clazz.getConstructors();
|
190
|
|
191
|
if( cons.length==1 )
|
192
|
{
|
193
|
InitData data = objects[ordinal].mInitData;
|
194
|
Object[] parameters = new Object[] { data,meshState,iconMode,quat,move,scale,meshStream };
|
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
|
}
|