1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.objects;
|
21
|
|
22
|
import org.distorted.objectlib.main.ObjectConstants;
|
23
|
import org.distorted.objectlib.main.ObjectType;
|
24
|
|
25
|
import java.util.ArrayList;
|
26
|
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
|
27
|
|
28
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29
|
|
30
|
public class RubikObjectList
|
31
|
{
|
32
|
public static int MAX_LEVEL;
|
33
|
|
34
|
private static RubikObjectList mType;
|
35
|
private static int mNumObjects;
|
36
|
private static ArrayList<RubikObject> mObjects;
|
37
|
|
38
|
static
|
39
|
{
|
40
|
int max = Integer.MIN_VALUE;
|
41
|
|
42
|
for (int i=0; i<NUM_OBJECTS; i++)
|
43
|
{
|
44
|
int cur = getDBLevel(i);
|
45
|
if( cur>max ) max = cur;
|
46
|
}
|
47
|
|
48
|
MAX_LEVEL = max;
|
49
|
}
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
private RubikObjectList()
|
54
|
{
|
55
|
mNumObjects = 0;
|
56
|
mObjects = new ArrayList<>();
|
57
|
|
58
|
createBuiltinObjects();
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
private void createBuiltinObjects()
|
64
|
{
|
65
|
for(int i=0; i<NUM_OBJECTS; i++)
|
66
|
{
|
67
|
ObjectType type = ObjectType.getObject(i);
|
68
|
RubikObject obj = new RubikObject(type);
|
69
|
mObjects.add(obj);
|
70
|
mNumObjects++;
|
71
|
}
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
// PUBLIC API
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
// historically older versions of the app had lower 'maxScrambles' in case of several objects and
|
78
|
// those got remembered in the server-side DB already, so we need to keep using them. This function
|
79
|
// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have
|
80
|
// those two values the same.
|
81
|
|
82
|
public static int getDBLevel(int ordinal)
|
83
|
{
|
84
|
if( ordinal==ObjectConstants.CUBE_3 ) return 16;
|
85
|
if( ordinal==ObjectConstants.CUBE_4 ) return 20;
|
86
|
if( ordinal==ObjectConstants.CUBE_5 ) return 24;
|
87
|
if( ordinal==ObjectConstants.PYRA_4 ) return 15;
|
88
|
if( ordinal==ObjectConstants.PYRA_5 ) return 20;
|
89
|
if( ordinal==ObjectConstants.MEGA_5 ) return 35;
|
90
|
if( ordinal==ObjectConstants.DIAM_2 ) return 10;
|
91
|
if( ordinal==ObjectConstants.DIAM_3 ) return 18;
|
92
|
if( ordinal==ObjectConstants.REDI_3 ) return 14;
|
93
|
if( ordinal==ObjectConstants.HELI_3 ) return 18;
|
94
|
if( ordinal==ObjectConstants.SKEW_3 ) return 17;
|
95
|
if( ordinal==ObjectConstants.REX_3 ) return 16;
|
96
|
if( ordinal==ObjectConstants.MIRR_3 ) return 16;
|
97
|
|
98
|
ObjectType type = ObjectType.getObject(ordinal);
|
99
|
return type.getNumScramble();
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
public static RubikObject getObject(int ordinal)
|
105
|
{
|
106
|
if( mType==null ) mType = new RubikObjectList();
|
107
|
return ordinal>=0 && ordinal<mNumObjects ? mObjects.get(ordinal) : null;
|
108
|
}
|
109
|
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
public static int getNumObjects()
|
113
|
{
|
114
|
if( mType==null ) mType = new RubikObjectList();
|
115
|
return mNumObjects;
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
|
120
|
public static int getOrdinal(String name)
|
121
|
{
|
122
|
if( mType==null ) mType = new RubikObjectList();
|
123
|
|
124
|
for(int i=0; i<mNumObjects; i++)
|
125
|
{
|
126
|
RubikObject obj = mObjects.get(i);
|
127
|
|
128
|
if( obj.getName().equals(name) ) return i;
|
129
|
}
|
130
|
|
131
|
return -1;
|
132
|
}
|
133
|
}
|