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