1 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
4c87f159
|
Leszek Koltunski
|
// 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 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.objectlib.main;
|
11 |
|
|
|
12 |
82eb152a
|
Leszek Koltunski
|
import java.io.InputStream;
|
13 |
6916789e
|
Leszek Koltunski
|
import java.lang.reflect.Constructor;
|
14 |
|
|
import java.lang.reflect.InvocationTargetException;
|
15 |
82eb152a
|
Leszek Koltunski
|
|
16 |
ecf3d6e3
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
17 |
29b82486
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
18 |
ad9f5cae
|
Leszek Koltunski
|
|
19 |
29b82486
|
Leszek Koltunski
|
import org.distorted.objectlib.R;
|
20 |
ad9f5cae
|
Leszek Koltunski
|
import org.distorted.objectlib.objects.*;
|
21 |
29b82486
|
Leszek Koltunski
|
|
22 |
61aa85e4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23 |
|
|
|
24 |
8005e762
|
Leszek Koltunski
|
public enum ObjectType
|
25 |
29b82486
|
Leszek Koltunski
|
{
|
26 |
18185895
|
Leszek Koltunski
|
CUBE_2 ( TwistyCuboid.class , 12, R.drawable.cube_2, true, new InitData(new int[] {2,2,2})),
|
27 |
|
|
CUBE_3 ( TwistyCuboid.class , 17, R.drawable.cube_3, true, new InitData(new int[] {3,3,3})),
|
28 |
|
|
CUBE_4 ( TwistyCuboid.class , 24, R.drawable.cube_4, true, new InitData(new int[] {4,4,4})),
|
29 |
|
|
CUBE_5 ( TwistyCuboid.class , 28, R.drawable.cube_5, true, new InitData(new int[] {5,5,5})),
|
30 |
|
|
CUBE_6 ( TwistyCuboid.class , 35, R.drawable.cube_6, true, new InitData(new int[] {6,6,6})),
|
31 |
|
|
|
32 |
|
|
CUBE_7 ( TwistyCuboid.class , 42, R.drawable.cube_7, true, new InitData(new int[] {7,7,7})),
|
33 |
|
|
BAN1_3 ( TwistyBandagedCuboid.class, 16, R.drawable.ban1_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_1)),
|
34 |
|
|
BAN2_3 ( TwistyBandagedCuboid.class, 20, R.drawable.ban2_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_2)),
|
35 |
|
|
BAN3_3 ( TwistyBandagedCuboid.class, 16, R.drawable.ban3_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_3)),
|
36 |
|
|
BAN4_3 ( TwistyBandagedCuboid.class, 22, R.drawable.ban4_3, true, new InitData(new int[] {3,3,3}, TwistyBandagedCuboid.POS_4)),
|
37 |
9d7e72cd
|
Leszek Koltunski
|
|
38 |
18185895
|
Leszek Koltunski
|
CU_323 ( TwistyCuboid.class , 15, R.drawable.cu_323, true, new InitData(new int[] {3,2,3})),
|
39 |
|
|
CU_232 ( TwistyCuboid.class , 16, R.drawable.cu_232, true, new InitData(new int[] {2,3,2})),
|
40 |
|
|
CU_343 ( TwistyCuboid.class , 23, R.drawable.cu_343, true, new InitData(new int[] {3,4,3})),
|
41 |
|
|
SQU1_3 ( TwistySquare1.class , 24, R.drawable.squ1_3, true, new InitData(new int[] {3,2,3})),
|
42 |
|
|
SQU2_3 ( TwistySquare2.class , 24, R.drawable.squ2_3, true, new InitData(new int[] {3,2,3})),
|
43 |
|
|
|
44 |
|
|
MORP_2 ( TwistyMorphix.class , 12, R.drawable.morp_2, true, new InitData(new int[] {2,2,2})),
|
45 |
|
|
JING_2 ( TwistyJing.class , 11, R.drawable.jing_2, true, new InitData(new int[] {2,2,2,2})),
|
46 |
|
|
PYRA_3 ( TwistyPyraminx.class , 10, R.drawable.pyra_3, true, new InitData(new int[] {3,3,3,3})),
|
47 |
|
|
PYRA_4 ( TwistyPyraminx.class , 17, R.drawable.pyra_4, true, new InitData(new int[] {4,4,4,4})),
|
48 |
|
|
PYRA_5 ( TwistyPyraminx.class , 23, R.drawable.pyra_5, true, new InitData(new int[] {5,5,5,5})),
|
49 |
|
|
|
50 |
|
|
TRAJ_3 ( TwistyTrajber.class , 17, R.drawable.traj_3, true, new InitData(new int[] {3,3,3})),
|
51 |
|
|
TRAJ_4 ( TwistyTrajber.class , 24, R.drawable.traj_4, true, new InitData(new int[] {4,4,4})),
|
52 |
|
|
DIAM_2 ( TwistyDiamond.class , 12, R.drawable.diam_2, true, new InitData(new int[] {2,2,2,2})),
|
53 |
|
|
DIAM_3 ( TwistyDiamond.class , 24, R.drawable.diam_3, true, new InitData(new int[] {3,3,3,3})),
|
54 |
|
|
DIAM_4 ( TwistyDiamond.class , 32, R.drawable.diam_4, true, new InitData(new int[] {4,4,4,4})),
|
55 |
|
|
|
56 |
|
|
ULTI_2 ( TwistyUltimate.class , 18, R.drawable.ulti_2, true, new InitData(new int[] {2,2,2,2})),
|
57 |
|
|
KILO_3 ( TwistyKilominx.class , 18, R.drawable.kilo_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
58 |
|
|
MEGA_3 ( TwistyMegaminx.class , 21, R.drawable.mega_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
59 |
|
|
KILO_5 ( TwistyKilominx.class , 33, R.drawable.kilo_5, true, new InitData(new int[] {5,5,5,5,5,5})),
|
60 |
|
|
MEGA_5 ( TwistyMegaminx.class , 37, R.drawable.mega_5, true, new InitData(new int[] {5,5,5,5,5,5})),
|
61 |
|
|
|
62 |
|
|
CRYS_3 ( TwistyCrystal.class , 27, R.drawable.crys_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
63 |
|
|
STAR_3 ( TwistyStarminx.class , 27, R.drawable.star_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
64 |
|
|
PENT_2 ( TwistyPentultimate.class , 21, R.drawable.pent_2, true, new InitData(new int[] {2,2,2,2,2,2})),
|
65 |
|
|
DINO_3 ( TwistyDino6.class , 10, R.drawable.dino_3, true, new InitData(new int[] {3,3,3,3})),
|
66 |
|
|
DIN4_3 ( TwistyDino4.class , 9, R.drawable.din4_3, true, new InitData(new int[] {3,3,3,3})),
|
67 |
|
|
|
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 |
|
|
IVY_2 ( TwistyIvy.class , 9, R.drawable.ivy_2 , true, new InitData(new int[] {2,2,2,2})),
|
72 |
|
|
REX_3 ( TwistyRex.class , 19, R.drawable.rex_3 , true, new InitData(new int[] {3,3,3,3})),
|
73 |
|
|
|
74 |
|
|
REDI_3 ( TwistyRedi.class , 16, R.drawable.redi_3, true, new InitData(new int[] {3,3,3,3})),
|
75 |
|
|
HELI_3 ( TwistyHelicopter.class , 20, R.drawable.heli_3, true, new InitData(new int[] {3,3,3,3,3,3})),
|
76 |
|
|
SKEW_2 ( TwistySkewb.class , 11, R.drawable.skew_2, true, new InitData(new int[] {2,2,2,2})),
|
77 |
|
|
SKEW_3 ( TwistySkewb.class , 21, R.drawable.skew_3, true, new InitData(new int[] {3,3,3,3})),
|
78 |
|
|
CONT_2 ( TwistyContainer.class , 12, R.drawable.cont_2, true, new InitData(new int[] {2,2,2,2})),
|
79 |
|
|
|
80 |
b3b79e9b
|
Leszek Koltunski
|
FISH_3 ( TwistyFisher.class , 24, R.drawable.fish_3, true, new InitData(new int[] {3,3,3})),
|
81 |
|
|
WIND_3 ( TwistyWindmill.class , 24, R.drawable.wind_3, true, new InitData(new int[] {3,3,3})),
|
82 |
|
|
AXIS_3 ( TwistyAxis.class , 24, R.drawable.axis_3, true, new InitData(new int[] {3,3,3})),
|
83 |
|
|
VOID_3 ( TwistyVoid.class , 17, R.drawable.void_3, true, new InitData(new int[] {3,3,3})),
|
84 |
18185895
|
Leszek Koltunski
|
MIXU_3 ( TwistyMixup3x3.class , 24, R.drawable.mixu_3, true, new InitData(new int[] {3,3,3})),
|
85 |
b3b79e9b
|
Leszek Koltunski
|
|
86 |
18185895
|
Leszek Koltunski
|
MIXP_3 ( TwistyMixup3x3Plus.class , 28, R.drawable.mixp_3, true, new InitData(new int[] {3,3,3})),
|
87 |
|
|
CRA1_2 ( TwistyCrazy2x2.class , 16, R.drawable.cra1_2, false, new InitData(new int[] {2,2,2})),
|
88 |
|
|
CRA1_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra1_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.CRAZY )),
|
89 |
|
|
CRA2_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra2_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.MERCURY)),
|
90 |
|
|
CRA3_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra3_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.VENUS )),
|
91 |
|
|
CRA4_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra4_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.EARTH )),
|
92 |
|
|
CRA5_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra5_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.MARS )),
|
93 |
|
|
CRA6_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra6_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.JUPITER)),
|
94 |
|
|
CRA7_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra7_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.SATURN )),
|
95 |
|
|
CRA8_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra8_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.URANUS )),
|
96 |
|
|
CRA9_3 ( TwistyCrazy3x3.class , 22, R.drawable.cra9_3, false, new InitData(new int[] {3,3,3}, TwistyCrazy3x3.NEPTUNE)),
|
97 |
29b82486
|
Leszek Koltunski
|
;
|
98 |
|
|
|
99 |
a7e1fa79
|
Leszek Koltunski
|
public static int NUM_OBJECTS;
|
100 |
96ae36f2
|
Leszek Koltunski
|
public static final int MAX_SCRAMBLES = 42; // max scrambles at the time we switched from
|
101 |
|
|
// remembering the records the old way
|
102 |
e1a86bf2
|
Leszek Koltunski
|
private static final ObjectType[] objects;
|
103 |
29b82486
|
Leszek Koltunski
|
|
104 |
a8295031
|
Leszek Koltunski
|
private final InitData mInitData;
|
105 |
a57e6870
|
Leszek Koltunski
|
private final int mNumScrambles;
|
106 |
ce956bcf
|
Leszek Koltunski
|
private final int mIcon;
|
107 |
a7e1fa79
|
Leszek Koltunski
|
private final boolean mExportToApp;
|
108 |
6916789e
|
Leszek Koltunski
|
private final Class<? extends TwistyObject> mClass;
|
109 |
29b82486
|
Leszek Koltunski
|
|
110 |
|
|
static
|
111 |
|
|
{
|
112 |
a7e1fa79
|
Leszek Koltunski
|
NUM_OBJECTS = 0;
|
113 |
|
|
for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) NUM_OBJECTS++;
|
114 |
|
|
|
115 |
61aa85e4
|
Leszek Koltunski
|
int i = 0;
|
116 |
8005e762
|
Leszek Koltunski
|
objects = new ObjectType[NUM_OBJECTS];
|
117 |
a7e1fa79
|
Leszek Koltunski
|
for(ObjectType object: ObjectType.values()) if( object.mExportToApp ) objects[i++] = object;
|
118 |
29b82486
|
Leszek Koltunski
|
}
|
119 |
|
|
|
120 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121 |
|
|
|
122 |
18185895
|
Leszek Koltunski
|
ObjectType(Class<? extends TwistyObject> clazz, int scrambles, int icon, boolean export, InitData data)
|
123 |
b63bedcc
|
Leszek Koltunski
|
{
|
124 |
96ae36f2
|
Leszek Koltunski
|
mClass = clazz;
|
125 |
|
|
mInitData = data;
|
126 |
|
|
mNumScrambles = scrambles;
|
127 |
|
|
mIcon = icon;
|
128 |
|
|
mExportToApp = export;
|
129 |
b63bedcc
|
Leszek Koltunski
|
}
|
130 |
|
|
|
131 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
|
|
// PUBLIC API
|
133 |
|
|
|
134 |
8005e762
|
Leszek Koltunski
|
public static ObjectType getObject(int ordinal)
|
135 |
29b82486
|
Leszek Koltunski
|
{
|
136 |
61aa85e4
|
Leszek Koltunski
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
|
137 |
29b82486
|
Leszek Koltunski
|
}
|
138 |
|
|
|
139 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
|
|
141 |
61aa85e4
|
Leszek Koltunski
|
public static int getOrdinal(String name)
|
142 |
29b82486
|
Leszek Koltunski
|
{
|
143 |
|
|
for(int i=0; i<NUM_OBJECTS; i++)
|
144 |
|
|
{
|
145 |
61aa85e4
|
Leszek Koltunski
|
if( objects[i].name().equals(name) ) return i;
|
146 |
29b82486
|
Leszek Koltunski
|
}
|
147 |
|
|
|
148 |
|
|
return -1;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152 |
|
|
|
153 |
ce956bcf
|
Leszek Koltunski
|
public int getIconID()
|
154 |
29b82486
|
Leszek Koltunski
|
{
|
155 |
ce956bcf
|
Leszek Koltunski
|
return mIcon;
|
156 |
29b82486
|
Leszek Koltunski
|
}
|
157 |
|
|
|
158 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
159 |
|
|
|
160 |
e1a86bf2
|
Leszek Koltunski
|
public int getNumScramble()
|
161 |
594bbce0
|
Leszek Koltunski
|
{
|
162 |
e1a86bf2
|
Leszek Koltunski
|
return mNumScrambles;
|
163 |
594bbce0
|
Leszek Koltunski
|
}
|
164 |
|
|
|
165 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166 |
|
|
|
167 |
3bf19410
|
Leszek Koltunski
|
public static TwistyObject create(int ordinal, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream meshStream)
|
168 |
29b82486
|
Leszek Koltunski
|
{
|
169 |
d844220f
|
Leszek Koltunski
|
/*
|
170 |
3a0a23bf
|
Leszek Koltunski
|
if( ordinal==CRA1_3.ordinal() )
|
171 |
d844220f
|
Leszek Koltunski
|
{
|
172 |
3a0a23bf
|
Leszek Koltunski
|
return new TwistyCrazy3x3(objects[ordinal].mInitData,meshState,iconMode,quat,move,scale,meshStream);
|
173 |
d844220f
|
Leszek Koltunski
|
}
|
174 |
|
|
*/
|
175 |
6916789e
|
Leszek Koltunski
|
Class<? extends TwistyObject> clazz = objects[ordinal].mClass;
|
176 |
ad9f5cae
|
Leszek Koltunski
|
|
177 |
6916789e
|
Leszek Koltunski
|
try
|
178 |
29b82486
|
Leszek Koltunski
|
{
|
179 |
6916789e
|
Leszek Koltunski
|
Constructor<?>[] cons = clazz.getConstructors();
|
180 |
|
|
|
181 |
|
|
if( cons.length==1 )
|
182 |
|
|
{
|
183 |
a8295031
|
Leszek Koltunski
|
InitData data = objects[ordinal].mInitData;
|
184 |
|
|
Object[] parameters = new Object[] { data,meshState,iconMode,quat,move,scale,meshStream };
|
185 |
6916789e
|
Leszek Koltunski
|
return (TwistyObject)cons[0].newInstance(parameters);
|
186 |
|
|
}
|
187 |
|
|
else
|
188 |
|
|
{
|
189 |
7af68038
|
Leszek Koltunski
|
android.util.Log.e("ObjectType", "ERROR! number of TwistyObject constructors="+cons.length);
|
190 |
6916789e
|
Leszek Koltunski
|
}
|
191 |
|
|
}
|
192 |
|
|
catch(IllegalAccessException iae)
|
193 |
|
|
{
|
194 |
7af68038
|
Leszek Koltunski
|
android.util.Log.e("ObjectType", "Illegal Access Exception: "+iae.getMessage());
|
195 |
6916789e
|
Leszek Koltunski
|
}
|
196 |
|
|
catch(InstantiationException ie)
|
197 |
|
|
{
|
198 |
7af68038
|
Leszek Koltunski
|
android.util.Log.e("ObjectType", "Instantiation Exception: "+ie.getMessage());
|
199 |
6916789e
|
Leszek Koltunski
|
}
|
200 |
|
|
catch(InvocationTargetException ite)
|
201 |
|
|
{
|
202 |
7af68038
|
Leszek Koltunski
|
android.util.Log.e("ObjectType", "Invocation Target Exception: "+ite.getMessage());
|
203 |
29b82486
|
Leszek Koltunski
|
}
|
204 |
|
|
|
205 |
|
|
return null;
|
206 |
|
|
}
|
207 |
|
|
}
|