1 |
27a70eae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
97c012ae
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshRectangles;
|
25 |
27a70eae
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
26 |
|
|
import org.distorted.magic.R;
|
27 |
|
|
|
28 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29 |
|
|
|
30 |
|
|
public enum RubikObjectList
|
31 |
|
|
{
|
32 |
4888e97c
|
Leszek Koltunski
|
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 |
27a70eae
|
Leszek Koltunski
|
;
|
39 |
|
|
|
40 |
4888e97c
|
Leszek Koltunski
|
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 |
27a70eae
|
Leszek Koltunski
|
private static final RubikObjectList[] objects;
|
46 |
4888e97c
|
Leszek Koltunski
|
private static int mNumAll;
|
47 |
27a70eae
|
Leszek Koltunski
|
|
48 |
|
|
static
|
49 |
|
|
{
|
50 |
4888e97c
|
Leszek Koltunski
|
mNumAll = 0;
|
51 |
|
|
int size, i = 0;
|
52 |
|
|
objects = new RubikObjectList[NUM_OBJECTS];
|
53 |
|
|
int maxsize = Integer.MIN_VALUE;
|
54 |
27a70eae
|
Leszek Koltunski
|
|
55 |
4888e97c
|
Leszek Koltunski
|
for(RubikObjectList object: RubikObjectList.values())
|
56 |
27a70eae
|
Leszek Koltunski
|
{
|
57 |
4888e97c
|
Leszek Koltunski
|
objects[i] = object;
|
58 |
27a70eae
|
Leszek Koltunski
|
i++;
|
59 |
4888e97c
|
Leszek Koltunski
|
size = object.mObjectSizes.length;
|
60 |
|
|
mNumAll += size;
|
61 |
|
|
if( size> maxsize ) maxsize = size;
|
62 |
27a70eae
|
Leszek Koltunski
|
}
|
63 |
4888e97c
|
Leszek Koltunski
|
|
64 |
|
|
MAX_SIZE = maxsize;
|
65 |
27a70eae
|
Leszek Koltunski
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
|
|
public static RubikObjectList getObject(int ordinal)
|
70 |
|
|
{
|
71 |
|
|
return objects[ordinal];
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
4888e97c
|
Leszek Koltunski
|
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 |
27a70eae
|
Leszek Koltunski
|
{
|
104 |
4888e97c
|
Leszek Koltunski
|
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 getTotal()
|
119 |
|
|
{
|
120 |
|
|
return mNumAll;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
|
|
|
125 |
|
|
RubikObjectList(int[] sizes, int[] iconIDs, RubikObjectMovement movement)
|
126 |
|
|
{
|
127 |
|
|
mObjectSizes= sizes;
|
128 |
|
|
mIconIDs = iconIDs;
|
129 |
27a70eae
|
Leszek Koltunski
|
mObjectMovementClass = movement;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133 |
|
|
|
134 |
4888e97c
|
Leszek Koltunski
|
public int[] getIconIDs()
|
135 |
27a70eae
|
Leszek Koltunski
|
{
|
136 |
4888e97c
|
Leszek Koltunski
|
return mIconIDs;
|
137 |
27a70eae
|
Leszek Koltunski
|
}
|
138 |
|
|
|
139 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
|
|
141 |
4888e97c
|
Leszek Koltunski
|
public int[] getSizes()
|
142 |
|
|
{
|
143 |
|
|
return mObjectSizes;
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147 |
|
|
|
148 |
|
|
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc)
|
149 |
27a70eae
|
Leszek Koltunski
|
{
|
150 |
5974d2ae
|
Leszek Koltunski
|
DistortedTexture texture = new DistortedTexture();
|
151 |
36273130
|
Leszek Koltunski
|
DistortedEffects effects = new DistortedEffects();
|
152 |
b32444ee
|
Leszek Koltunski
|
MeshRectangles mesh = new MeshRectangles(20,20); // mesh of the node, not of the cubits
|
153 |
74686c71
|
Leszek Koltunski
|
|
154 |
4888e97c
|
Leszek Koltunski
|
switch(ordinal())
|
155 |
|
|
{
|
156 |
|
|
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects);
|
157 |
|
|
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects);
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
return null;
|
161 |
27a70eae
|
Leszek Koltunski
|
}
|
162 |
|
|
|
163 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164 |
|
|
|
165 |
|
|
public RubikObjectMovement getObjectMovementClass()
|
166 |
|
|
{
|
167 |
4888e97c
|
Leszek Koltunski
|
return mObjectMovementClass;
|
168 |
27a70eae
|
Leszek Koltunski
|
}
|
169 |
|
|
}
|