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.object;
|
21
|
|
22
|
import org.distorted.library.main.DistortedEffects;
|
23
|
import org.distorted.library.main.DistortedTexture;
|
24
|
import org.distorted.library.mesh.MeshRectangles;
|
25
|
import org.distorted.library.type.Static4D;
|
26
|
import org.distorted.magic.R;
|
27
|
|
28
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29
|
|
30
|
public enum RubikObjectList
|
31
|
{
|
32
|
CUBE (
|
33
|
new int[][] {
|
34
|
{2 , R.drawable.cube2} ,
|
35
|
{3 , R.drawable.cube3} ,
|
36
|
{4 , R.drawable.cube4} ,
|
37
|
{5 , R.drawable.cube5}
|
38
|
},
|
39
|
new RubikCubeMovement()
|
40
|
),
|
41
|
|
42
|
PYRA (
|
43
|
new int[][] {
|
44
|
{3 , R.drawable.pyra3} ,
|
45
|
{4 , R.drawable.pyra4} ,
|
46
|
{5 , R.drawable.pyra5}
|
47
|
},
|
48
|
new RubikPyraminxMovement()
|
49
|
),
|
50
|
;
|
51
|
|
52
|
public static final int NUM_OBJECTS = values().length;
|
53
|
public static final int MAX_SIZE;
|
54
|
|
55
|
private final int[] mObjectSizes, mIconIDs;
|
56
|
final RubikObjectMovement mObjectMovementClass;
|
57
|
private static final RubikObjectList[] objects;
|
58
|
private static int mNumAll;
|
59
|
|
60
|
static
|
61
|
{
|
62
|
mNumAll = 0;
|
63
|
int size, i = 0;
|
64
|
objects = new RubikObjectList[NUM_OBJECTS];
|
65
|
int maxsize = Integer.MIN_VALUE;
|
66
|
|
67
|
for(RubikObjectList object: RubikObjectList.values())
|
68
|
{
|
69
|
objects[i] = object;
|
70
|
i++;
|
71
|
size = object.mObjectSizes.length;
|
72
|
mNumAll += size;
|
73
|
if( size> maxsize ) maxsize = size;
|
74
|
}
|
75
|
|
76
|
MAX_SIZE = maxsize;
|
77
|
}
|
78
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
public static RubikObjectList getObject(int ordinal)
|
82
|
{
|
83
|
return objects[ordinal];
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
public static int pack(int object, int size)
|
89
|
{
|
90
|
int ret = 0;
|
91
|
for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
|
92
|
|
93
|
return ret+size;
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
|
98
|
public static int unpackSize(int number)
|
99
|
{
|
100
|
int num;
|
101
|
|
102
|
for(int i=0; i<NUM_OBJECTS; i++)
|
103
|
{
|
104
|
num = objects[i].mObjectSizes.length;
|
105
|
if( number<num ) return number;
|
106
|
number -= num;
|
107
|
}
|
108
|
|
109
|
return -1;
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
public static int unpackObject(int number)
|
115
|
{
|
116
|
int num;
|
117
|
|
118
|
for(int i=0; i<NUM_OBJECTS; i++)
|
119
|
{
|
120
|
num = objects[i].mObjectSizes.length;
|
121
|
if( number<num ) return i;
|
122
|
number -= num;
|
123
|
}
|
124
|
|
125
|
return -1;
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
public static int unpackObjectFromString(String obj)
|
131
|
{
|
132
|
int u = obj.indexOf('_');
|
133
|
int l = obj.length();
|
134
|
|
135
|
if( u>0 )
|
136
|
{
|
137
|
String name = obj.substring(0,u);
|
138
|
int size = Integer.parseInt( obj.substring(u+1,l) );
|
139
|
|
140
|
for(int i=0; i<NUM_OBJECTS; i++)
|
141
|
{
|
142
|
if( objects[i].name().equals(name) )
|
143
|
{
|
144
|
int sizeIndex = getSizeIndex(i,size);
|
145
|
return pack(i,sizeIndex);
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
|
150
|
return -1;
|
151
|
}
|
152
|
|
153
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154
|
|
155
|
public static String getObjectList()
|
156
|
{
|
157
|
String name;
|
158
|
StringBuilder list = new StringBuilder();
|
159
|
int len;
|
160
|
int[] sizes;
|
161
|
|
162
|
for(int i=0; i<NUM_OBJECTS; i++)
|
163
|
{
|
164
|
sizes = objects[i].mObjectSizes;
|
165
|
len = sizes.length;
|
166
|
name = objects[i].name();
|
167
|
|
168
|
for(int j=0; j<len; j++)
|
169
|
{
|
170
|
if( i>0 || j>0 ) list.append(',');
|
171
|
list.append(name);
|
172
|
list.append('_');
|
173
|
list.append(sizes[j]);
|
174
|
}
|
175
|
}
|
176
|
|
177
|
return list.toString();
|
178
|
}
|
179
|
|
180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181
|
|
182
|
public static int getTotal()
|
183
|
{
|
184
|
return mNumAll;
|
185
|
}
|
186
|
|
187
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188
|
|
189
|
public static int getOrdinal(String name)
|
190
|
{
|
191
|
for(int i=0; i<NUM_OBJECTS; i++)
|
192
|
{
|
193
|
if(objects[i].name().equals(name)) return i;
|
194
|
}
|
195
|
|
196
|
return -1;
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
public static int getSizeIndex(int ordinal, int size)
|
202
|
{
|
203
|
int[] sizes = objects[ordinal].getSizes();
|
204
|
int len = sizes.length;
|
205
|
|
206
|
for(int i=0; i<len; i++)
|
207
|
{
|
208
|
if( sizes[i]==size ) return i;
|
209
|
}
|
210
|
|
211
|
return -1;
|
212
|
}
|
213
|
|
214
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
215
|
|
216
|
RubikObjectList(int[][] info, RubikObjectMovement movement)
|
217
|
{
|
218
|
int length = info.length;
|
219
|
|
220
|
mObjectSizes= new int[length];
|
221
|
mIconIDs = new int[length];
|
222
|
|
223
|
for(int i=0; i<length; i++)
|
224
|
{
|
225
|
mObjectSizes[i] = info[i][0];
|
226
|
mIconIDs[i] = info[i][1];
|
227
|
}
|
228
|
|
229
|
mObjectMovementClass = movement;
|
230
|
}
|
231
|
|
232
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233
|
|
234
|
public int[] getIconIDs()
|
235
|
{
|
236
|
return mIconIDs;
|
237
|
}
|
238
|
|
239
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
|
241
|
public int[] getSizes()
|
242
|
{
|
243
|
return mObjectSizes;
|
244
|
}
|
245
|
|
246
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247
|
|
248
|
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc)
|
249
|
{
|
250
|
DistortedTexture texture = new DistortedTexture();
|
251
|
DistortedEffects effects = new DistortedEffects();
|
252
|
MeshRectangles mesh = new MeshRectangles(20,20); // mesh of the node, not of the cubits
|
253
|
|
254
|
switch(ordinal())
|
255
|
{
|
256
|
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects);
|
257
|
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects);
|
258
|
}
|
259
|
|
260
|
return null;
|
261
|
}
|
262
|
|
263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264
|
|
265
|
public RubikObjectMovement getObjectMovementClass()
|
266
|
{
|
267
|
return mObjectMovementClass;
|
268
|
}
|
269
|
}
|