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