1 |
48e61813
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2024 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.objects;
|
11 |
|
|
|
12 |
121f1ba9
|
leszek
|
import static org.distorted.objectlib.metadata.Metadata.*;
|
13 |
|
|
|
14 |
|
|
import org.distorted.main.R;
|
15 |
|
|
|
16 |
48e61813
|
leszek
|
import java.util.Arrays;
|
17 |
|
|
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
881697b3
|
leszek
|
public class RubikObjectCategoriesShape extends RubikObjectCategories
|
21 |
48e61813
|
leszek
|
{
|
22 |
|
|
private void buildSort(int[] data)
|
23 |
|
|
{
|
24 |
|
|
int numObjects = data.length;
|
25 |
|
|
int[] sorted = new int[numObjects];
|
26 |
|
|
System.arraycopy(data, 0, sorted, 0, numObjects);
|
27 |
|
|
|
28 |
|
|
Arrays.sort(sorted);
|
29 |
|
|
|
30 |
|
|
int[] categories = new int[numObjects];
|
31 |
|
|
int numCategories = 0;
|
32 |
|
|
|
33 |
|
|
for(int o=0; o<numObjects; o++)
|
34 |
|
|
if( o==0 || sorted[o-1]!=sorted[o] )
|
35 |
|
|
{
|
36 |
|
|
categories[numCategories] = sorted[o];
|
37 |
|
|
numCategories++;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
int lastChange = -1;
|
41 |
|
|
int curr = 0;
|
42 |
|
|
int[] numInCategory = new int[numCategories];
|
43 |
|
|
|
44 |
|
|
for(int o=0; o<numObjects; o++)
|
45 |
|
|
if( o==numObjects-1 || sorted[o]!=sorted[o+1] )
|
46 |
|
|
{
|
47 |
|
|
numInCategory[curr] = o-lastChange;
|
48 |
|
|
curr++;
|
49 |
|
|
lastChange = o;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
mObjectIndices = new int[numCategories][];
|
53 |
|
|
|
54 |
|
|
for(int c=0; c<numCategories; c++)
|
55 |
|
|
{
|
56 |
|
|
mObjectIndices[c] = new int[numInCategory[c]];
|
57 |
|
|
|
58 |
|
|
int cat = categories[c];
|
59 |
|
|
int index = 0;
|
60 |
|
|
|
61 |
|
|
for(int o=0; o<numObjects; o++)
|
62 |
|
|
if( data[o]==cat ) mObjectIndices[c][index++] = o;
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
881697b3
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
|
68 |
|
|
private int digestCategory(int cat)
|
69 |
|
|
{
|
70 |
|
|
int shape = (cat & 0x7);
|
71 |
121f1ba9
|
leszek
|
|
72 |
|
|
switch(shape)
|
73 |
|
|
{
|
74 |
|
|
case CATEGORY_SHAPE_HEX: int axis = (cat & 0x1f) >> 3;
|
75 |
|
|
return (shape<<2) + axis;
|
76 |
|
|
case CATEGORY_SHAPE_BAL: return (CATEGORY_SHAPE_OTH<<2);
|
77 |
|
|
case CATEGORY_SHAPE_TET:
|
78 |
|
|
case CATEGORY_SHAPE_OCT:
|
79 |
|
|
case CATEGORY_SHAPE_DOD:
|
80 |
|
|
case CATEGORY_SHAPE_ICO:
|
81 |
|
|
case CATEGORY_SHAPE_OTH: return (shape<<2);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
android.util.Log.e("D", "digestCategory: unknown shape "+shape);
|
85 |
|
|
return 0;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90 |
|
|
|
91 |
|
|
private int getImage(int cat)
|
92 |
|
|
{
|
93 |
|
|
int shape = (cat & 0x1f) >> 2;
|
94 |
|
|
|
95 |
|
|
switch(shape)
|
96 |
|
|
{
|
97 |
|
|
case CATEGORY_SHAPE_HEX: int axis = (cat & 0x3);
|
98 |
|
|
if( axis==CATEGORY_AXIS_FACE>>3 ) return R.drawable.shape_hex_face;
|
99 |
|
|
else if( axis==CATEGORY_AXIS_CORN>>3 ) return R.drawable.shape_hex_corn;
|
100 |
|
|
else if( axis==CATEGORY_AXIS_EDGE>>3 ) return R.drawable.shape_hex_edge;
|
101 |
|
|
else return R.drawable.shape_hex_other;
|
102 |
567a1955
|
leszek
|
case CATEGORY_SHAPE_TET: return R.drawable.shape_tet;
|
103 |
|
|
case CATEGORY_SHAPE_OCT: return R.drawable.shape_oct;
|
104 |
|
|
case CATEGORY_SHAPE_DOD: return R.drawable.shape_dod;
|
105 |
|
|
case CATEGORY_SHAPE_ICO: return R.drawable.shape_ico;
|
106 |
121f1ba9
|
leszek
|
case CATEGORY_SHAPE_BAL:
|
107 |
567a1955
|
leszek
|
case CATEGORY_SHAPE_OTH: return R.drawable.shape_oth;
|
108 |
121f1ba9
|
leszek
|
}
|
109 |
|
|
|
110 |
|
|
android.util.Log.e("D", "getImage: unknown shape "+shape);
|
111 |
|
|
return 0;
|
112 |
881697b3
|
leszek
|
}
|
113 |
|
|
|
114 |
48e61813
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
|
|
void buildIndices()
|
117 |
|
|
{
|
118 |
|
|
int numObjects = RubikObjectList.getNumObjects();
|
119 |
|
|
int[] cats = new int[numObjects];
|
120 |
|
|
|
121 |
|
|
for(int o=0; o<numObjects; o++)
|
122 |
|
|
{
|
123 |
|
|
RubikObject obj = RubikObjectList.getObject(o);
|
124 |
881697b3
|
leszek
|
int cat = obj==null ? 0 : obj.getCategory();
|
125 |
|
|
cats[o] = digestCategory(cat);
|
126 |
48e61813
|
leszek
|
}
|
127 |
|
|
|
128 |
|
|
buildSort(cats);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
|
|
|
133 |
|
|
void buildTitle()
|
134 |
|
|
{
|
135 |
|
|
mIconIDs = new int[mNumCategories];
|
136 |
|
|
|
137 |
|
|
for(int t=0; t<mNumCategories; t++)
|
138 |
|
|
{
|
139 |
|
|
int obj = mObjectIndices[t][0];
|
140 |
|
|
RubikObject object = RubikObjectList.getObject(obj);
|
141 |
881697b3
|
leszek
|
int cat = object==null ? 0 : object.getCategory();
|
142 |
|
|
int category = digestCategory(cat);
|
143 |
121f1ba9
|
leszek
|
mIconIDs[t] = getImage(category);
|
144 |
48e61813
|
leszek
|
}
|
145 |
|
|
}
|
146 |
|
|
}
|