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 android.content.res.Resources;
|
23
|
|
24
|
import org.distorted.library.main.DistortedEffects;
|
25
|
import org.distorted.library.main.DistortedTexture;
|
26
|
import org.distorted.library.mesh.MeshSquare;
|
27
|
import org.distorted.library.type.Static4D;
|
28
|
import org.distorted.objectlib.R;
|
29
|
import org.distorted.objectlib.objects.TwistyBandaged2Bar;
|
30
|
import org.distorted.objectlib.objects.TwistyBandaged3Plate;
|
31
|
import org.distorted.objectlib.objects.TwistyBandagedEvil;
|
32
|
import org.distorted.objectlib.objects.TwistyBandagedFused;
|
33
|
import org.distorted.objectlib.objects.TwistyCube;
|
34
|
import org.distorted.objectlib.objects.TwistyDiamond;
|
35
|
import org.distorted.objectlib.objects.TwistyDino4;
|
36
|
import org.distorted.objectlib.objects.TwistyDino6;
|
37
|
import org.distorted.objectlib.objects.TwistyHelicopter;
|
38
|
import org.distorted.objectlib.objects.TwistyIvy;
|
39
|
import org.distorted.objectlib.objects.TwistyJing;
|
40
|
import org.distorted.objectlib.objects.TwistyKilominx;
|
41
|
import org.distorted.objectlib.objects.TwistyMegaminx;
|
42
|
import org.distorted.objectlib.objects.TwistyMirror;
|
43
|
import org.distorted.objectlib.objects.TwistyPyraminx;
|
44
|
import org.distorted.objectlib.objects.TwistyRedi;
|
45
|
import org.distorted.objectlib.objects.TwistyRex;
|
46
|
import org.distorted.objectlib.objects.TwistySkewb;
|
47
|
import org.distorted.objectlib.objects.TwistySquare1;
|
48
|
import org.distorted.objectlib.objects.TwistySquare2;
|
49
|
import org.distorted.objectlib.objects.TwistyUltimate;
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
public enum ObjectList
|
54
|
{
|
55
|
CUBE_2 ( 0, 2, 12, 12, R.drawable.small_cube2, R.drawable.medium_cube2, R.drawable.big_cube2, R.drawable.huge_cube2),
|
56
|
CUBE_3 ( 0, 3, 16, 17, R.drawable.small_cube3, R.drawable.medium_cube3, R.drawable.big_cube3, R.drawable.huge_cube3),
|
57
|
CUBE_4 ( 0, 4, 20, 24, R.drawable.small_cube4, R.drawable.medium_cube4, R.drawable.big_cube4, R.drawable.huge_cube4),
|
58
|
CUBE_5 ( 0, 5, 24, 28, R.drawable.small_cube5, R.drawable.medium_cube5, R.drawable.big_cube5, R.drawable.huge_cube5),
|
59
|
JING_2 ( 1, 2, 11, 11, R.drawable.small_jing2, R.drawable.medium_jing2, R.drawable.big_jing2, R.drawable.huge_jing2),
|
60
|
PYRA_3 ( 1, 3, 10, 10, R.drawable.small_pyra3, R.drawable.medium_pyra3, R.drawable.big_pyra3, R.drawable.huge_pyra3),
|
61
|
PYRA_4 ( 1, 4, 14, 17, R.drawable.small_pyra4, R.drawable.medium_pyra4, R.drawable.big_pyra4, R.drawable.huge_pyra4),
|
62
|
PYRA_5 ( 1, 5, 20, 23, R.drawable.small_pyra5, R.drawable.medium_pyra5, R.drawable.big_pyra5, R.drawable.huge_pyra5),
|
63
|
KILO_3 ( 2, 3, 18, 18, R.drawable.small_kilo3, R.drawable.medium_kilo3, R.drawable.big_kilo3, R.drawable.huge_kilo3),
|
64
|
KILO_5 ( 2, 5, 33, 33, R.drawable.small_kilo5, R.drawable.medium_kilo5, R.drawable.big_kilo5, R.drawable.huge_kilo5),
|
65
|
MEGA_3 ( 2, 3, 21, 21, R.drawable.small_mega3, R.drawable.medium_mega3, R.drawable.big_mega3, R.drawable.huge_mega3),
|
66
|
MEGA_5 ( 2, 5, 35, 37, R.drawable.small_mega5, R.drawable.medium_mega5, R.drawable.big_mega5, R.drawable.huge_mega5),
|
67
|
ULTI_2 ( 3, 2, 18, 18, R.drawable.small_ulti , R.drawable.medium_ulti , R.drawable.big_ulti , R.drawable.huge_ulti ),
|
68
|
DIAM_2 ( 3, 2, 10, 12, R.drawable.small_diam2, R.drawable.medium_diam2, R.drawable.big_diam2, R.drawable.huge_diam2),
|
69
|
DIAM_3 ( 3, 3, 18, 24, R.drawable.small_diam3, R.drawable.medium_diam3, R.drawable.big_diam3, R.drawable.huge_diam3),
|
70
|
DIAM_4 ( 3, 4, 32, 32, R.drawable.small_diam4, R.drawable.medium_diam4, R.drawable.big_diam4, R.drawable.huge_diam4),
|
71
|
DINO_3 ( 4, 3, 10, 10, R.drawable.small_dino , R.drawable.medium_dino , R.drawable.big_dino , R.drawable.huge_dino ),
|
72
|
DIN4_3 ( 4, 3, 7, 7, R.drawable.small_din4 , R.drawable.medium_din4 , R.drawable.big_din4 , R.drawable.huge_din4 ),
|
73
|
REDI_3 ( 4, 3, 14, 16, R.drawable.small_redi , R.drawable.medium_redi , R.drawable.big_redi , R.drawable.huge_redi ),
|
74
|
HELI_3 ( 4, 3, 18, 20, R.drawable.small_heli , R.drawable.medium_heli , R.drawable.big_heli , R.drawable.huge_heli ),
|
75
|
SKEW_2 ( 5, 2, 11, 11, R.drawable.small_skew2, R.drawable.medium_skew2, R.drawable.big_skew2, R.drawable.huge_skew2),
|
76
|
SKEW_3 ( 5, 3, 17, 21, R.drawable.small_skew3, R.drawable.medium_skew3, R.drawable.big_skew3, R.drawable.huge_skew3),
|
77
|
IVY_2 ( 5, 2, 8, 8, R.drawable.small_ivy , R.drawable.medium_ivy , R.drawable.big_ivy , R.drawable.huge_ivy ),
|
78
|
REX_3 ( 5, 3, 16, 19, R.drawable.small_rex , R.drawable.medium_rex , R.drawable.big_rex , R.drawable.huge_rex ),
|
79
|
BAN1_3 ( 6, 3, 16, 16, R.drawable.small_ban1 , R.drawable.medium_ban1 , R.drawable.big_ban1 , R.drawable.huge_ban1 ),
|
80
|
BAN2_3 ( 6, 3, 16, 16, R.drawable.small_ban2 , R.drawable.medium_ban2 , R.drawable.big_ban2 , R.drawable.huge_ban2 ),
|
81
|
BAN3_3 ( 6, 3, 16, 16, R.drawable.small_ban3 , R.drawable.medium_ban3 , R.drawable.big_ban3 , R.drawable.huge_ban3 ),
|
82
|
BAN4_3 ( 6, 3, 16, 16, R.drawable.small_ban4 , R.drawable.medium_ban4 , R.drawable.big_ban4 , R.drawable.huge_ban4 ),
|
83
|
SQU1_3 ( 7, 3, 24, 24, R.drawable.small_squa1, R.drawable.medium_squa1, R.drawable.big_squa1, R.drawable.huge_squa1),
|
84
|
SQU2_3 ( 7, 3, 24, 24, R.drawable.small_squa2, R.drawable.medium_squa2, R.drawable.big_squa2, R.drawable.huge_squa2),
|
85
|
MIRR_2 ( 7, 2, 12, 12, R.drawable.small_mirr2, R.drawable.medium_mirr2, R.drawable.big_mirr2, R.drawable.huge_mirr2),
|
86
|
MIRR_3 ( 7, 3, 16, 17, R.drawable.small_mirr3, R.drawable.medium_mirr3, R.drawable.big_mirr3, R.drawable.huge_mirr3),
|
87
|
;
|
88
|
|
89
|
public static final int NUM_OBJECTS = values().length;
|
90
|
public static final int MAX_LEVEL;
|
91
|
public static final int MAX_SCRAMBLE;
|
92
|
public static final int MAX_OBJECT_SIZE;
|
93
|
|
94
|
private final int mRow, mSize, mDBLevels, mNumScrambles;
|
95
|
private final int mSmallIconID, mMediumIconID, mBigIconID, mHugeIconID;
|
96
|
|
97
|
private static final ObjectList[] objects;
|
98
|
private static int[] mIndices;
|
99
|
private static int mColCount, mRowCount;
|
100
|
|
101
|
static
|
102
|
{
|
103
|
int i = 0;
|
104
|
objects = new ObjectList[NUM_OBJECTS];
|
105
|
int maxLevel = Integer.MIN_VALUE;
|
106
|
int maxScramble= Integer.MIN_VALUE;
|
107
|
int maxSize = Integer.MIN_VALUE;
|
108
|
|
109
|
for(ObjectList object: ObjectList.values())
|
110
|
{
|
111
|
objects[i++] = object;
|
112
|
|
113
|
if( object.mNumScrambles> maxScramble ) maxScramble= object.mNumScrambles;
|
114
|
if( object.mDBLevels > maxLevel ) maxLevel = object.mDBLevels;
|
115
|
if( object.mSize > maxSize ) maxSize = object.mSize;
|
116
|
}
|
117
|
|
118
|
MAX_LEVEL = maxLevel;
|
119
|
MAX_SCRAMBLE = maxScramble;
|
120
|
MAX_OBJECT_SIZE = maxSize;
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
private static void setUpColAndRow()
|
126
|
{
|
127
|
mIndices = new int[NUM_OBJECTS];
|
128
|
mRowCount= 0;
|
129
|
|
130
|
for(int obj=0; obj<NUM_OBJECTS; obj++)
|
131
|
{
|
132
|
mIndices[obj] = objects[obj].mRow;
|
133
|
if( mIndices[obj]>=mRowCount ) mRowCount = mIndices[obj]+1;
|
134
|
}
|
135
|
|
136
|
mColCount = 0;
|
137
|
|
138
|
for(int row=0; row<mRowCount; row++)
|
139
|
{
|
140
|
int numObjects = computeNumObjectsInRow(row);
|
141
|
if( numObjects>mColCount ) mColCount = numObjects;
|
142
|
}
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
private static int computeNumObjectsInRow(int row)
|
148
|
{
|
149
|
int num=0;
|
150
|
|
151
|
for(int object=0; object<NUM_OBJECTS; object++)
|
152
|
{
|
153
|
if( objects[object].mRow == row ) num++;
|
154
|
}
|
155
|
|
156
|
return num;
|
157
|
}
|
158
|
|
159
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160
|
|
161
|
public static int getColumnCount()
|
162
|
{
|
163
|
if( mIndices==null ) setUpColAndRow();
|
164
|
|
165
|
return mColCount;
|
166
|
}
|
167
|
|
168
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169
|
|
170
|
public static int getRowCount()
|
171
|
{
|
172
|
if( mIndices==null ) setUpColAndRow();
|
173
|
|
174
|
return mRowCount;
|
175
|
}
|
176
|
|
177
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178
|
|
179
|
public static int[] getIndices()
|
180
|
{
|
181
|
if( mIndices==null ) setUpColAndRow();
|
182
|
|
183
|
return mIndices;
|
184
|
}
|
185
|
|
186
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187
|
|
188
|
public static ObjectList getObject(int ordinal)
|
189
|
{
|
190
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal] : CUBE_3;
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
public static int getOrdinal(String name)
|
196
|
{
|
197
|
for(int i=0; i<NUM_OBJECTS; i++)
|
198
|
{
|
199
|
if( objects[i].name().equals(name) ) return i;
|
200
|
}
|
201
|
|
202
|
return -1;
|
203
|
}
|
204
|
|
205
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206
|
|
207
|
public static String getObjectList()
|
208
|
{
|
209
|
StringBuilder list = new StringBuilder();
|
210
|
|
211
|
for(int i=0; i<NUM_OBJECTS; i++)
|
212
|
{
|
213
|
if( i>0 ) list.append(',');
|
214
|
list.append(objects[i].name());
|
215
|
}
|
216
|
|
217
|
return list.toString();
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
public static int getDBLevel(int ordinal)
|
223
|
{
|
224
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mDBLevels : 0;
|
225
|
}
|
226
|
|
227
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
228
|
|
229
|
public static int getNumScramble(int ordinal)
|
230
|
{
|
231
|
return ordinal>=0 && ordinal<NUM_OBJECTS ? objects[ordinal].mNumScrambles : 0;
|
232
|
}
|
233
|
|
234
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
235
|
|
236
|
ObjectList(int row, int size, int db, int scrambles, int smallIcon, int mediumIcon, int bigIcon, int hugeIcon)
|
237
|
{
|
238
|
mRow = row;
|
239
|
mSize = size;
|
240
|
mDBLevels = db;
|
241
|
mNumScrambles= scrambles;
|
242
|
mSmallIconID = smallIcon;
|
243
|
mMediumIconID= mediumIcon;
|
244
|
mBigIconID = bigIcon;
|
245
|
mHugeIconID = hugeIcon;
|
246
|
}
|
247
|
|
248
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249
|
|
250
|
public int getIconID(int size)
|
251
|
{
|
252
|
switch(size)
|
253
|
{
|
254
|
case 0: return mSmallIconID;
|
255
|
case 1: return mMediumIconID;
|
256
|
case 2: return mBigIconID;
|
257
|
case 3: return mHugeIconID;
|
258
|
}
|
259
|
|
260
|
return mSmallIconID;
|
261
|
}
|
262
|
|
263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264
|
|
265
|
public TwistyObject create(Static4D quat, int[][] moves, Resources res, int scrWidth)
|
266
|
{
|
267
|
DistortedTexture texture = new DistortedTexture();
|
268
|
DistortedEffects effects = new DistortedEffects();
|
269
|
MeshSquare mesh = new MeshSquare(20,20); // mesh of the node, not of the cubits
|
270
|
|
271
|
switch(ordinal())
|
272
|
{
|
273
|
case 0: return new TwistyCube (objects[ 0].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
274
|
case 1: return new TwistyCube (objects[ 1].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
275
|
case 2: return new TwistyCube (objects[ 2].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
276
|
case 3: return new TwistyCube (objects[ 3].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
277
|
case 4: return new TwistyJing (objects[ 4].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
278
|
case 5: return new TwistyPyraminx (objects[ 5].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
279
|
case 6: return new TwistyPyraminx (objects[ 6].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
280
|
case 7: return new TwistyPyraminx (objects[ 7].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
281
|
case 8: return new TwistyKilominx (objects[ 8].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
282
|
case 9: return new TwistyKilominx (objects[ 9].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
283
|
case 10: return new TwistyMegaminx (objects[10].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
284
|
case 11: return new TwistyMegaminx (objects[11].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
285
|
case 12: return new TwistyUltimate (objects[12].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
286
|
case 13: return new TwistyDiamond (objects[13].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
287
|
case 14: return new TwistyDiamond (objects[14].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
288
|
case 15: return new TwistyDiamond (objects[15].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
289
|
case 16: return new TwistyDino6 (objects[16].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
290
|
case 17: return new TwistyDino4 (objects[17].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
291
|
case 18: return new TwistyRedi (objects[18].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
292
|
case 19: return new TwistyHelicopter (objects[19].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
293
|
case 20: return new TwistySkewb (objects[20].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
294
|
case 21: return new TwistySkewb (objects[21].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
295
|
case 22: return new TwistyIvy (objects[22].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
296
|
case 23: return new TwistyRex (objects[23].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
297
|
case 24: return new TwistyBandagedFused (objects[24].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
298
|
case 25: return new TwistyBandaged2Bar (objects[25].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
299
|
case 26: return new TwistyBandaged3Plate(objects[26].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
300
|
case 27: return new TwistyBandagedEvil (objects[27].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
301
|
case 28: return new TwistySquare1 (objects[28].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
302
|
case 29: return new TwistySquare2 (objects[29].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
303
|
case 30: return new TwistyMirror (objects[30].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
304
|
case 31: return new TwistyMirror (objects[31].mSize, quat, texture, mesh, effects, moves, res, scrWidth);
|
305
|
}
|
306
|
|
307
|
return null;
|
308
|
}
|
309
|
}
|