1 |
a7d8c3cd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
400ff34d
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
23 |
|
|
|
24 |
|
|
import org.distorted.main.RubikActivity;
|
25 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectConstants;
|
26 |
a7d8c3cd
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectType;
|
27 |
400ff34d
|
Leszek Koltunski
|
import org.distorted.screens.RubikScreenPlay;
|
28 |
|
|
import org.distorted.screens.ScreenList;
|
29 |
a7d8c3cd
|
Leszek Koltunski
|
|
30 |
|
|
import java.util.ArrayList;
|
31 |
f12e4de9
|
Leszek Koltunski
|
|
32 |
09cf2a36
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
33 |
a7d8c3cd
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
public class RubikObjectList
|
38 |
|
|
{
|
39 |
400ff34d
|
Leszek Koltunski
|
public static final int DEF_OBJECT= ObjectConstants.CUBE_3;
|
40 |
|
|
|
41 |
d433b50e
|
Leszek Koltunski
|
public static int MAX_LEVEL;
|
42 |
|
|
|
43 |
a7d8c3cd
|
Leszek Koltunski
|
private static RubikObjectList mType;
|
44 |
|
|
private static int mNumObjects;
|
45 |
|
|
private static ArrayList<RubikObject> mObjects;
|
46 |
400ff34d
|
Leszek Koltunski
|
private static int mObject = DEF_OBJECT;
|
47 |
a7d8c3cd
|
Leszek Koltunski
|
|
48 |
d433b50e
|
Leszek Koltunski
|
static
|
49 |
|
|
{
|
50 |
|
|
int max = Integer.MIN_VALUE;
|
51 |
|
|
|
52 |
|
|
for (int i=0; i<NUM_OBJECTS; i++)
|
53 |
|
|
{
|
54 |
|
|
int cur = getDBLevel(i);
|
55 |
|
|
if( cur>max ) max = cur;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
MAX_LEVEL = max;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
a7d8c3cd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
private RubikObjectList()
|
64 |
|
|
{
|
65 |
|
|
mNumObjects = 0;
|
66 |
|
|
mObjects = new ArrayList<>();
|
67 |
|
|
|
68 |
|
|
createBuiltinObjects();
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
|
73 |
|
|
private void createBuiltinObjects()
|
74 |
|
|
{
|
75 |
|
|
for(int i=0; i<NUM_OBJECTS; i++)
|
76 |
|
|
{
|
77 |
|
|
ObjectType type = ObjectType.getObject(i);
|
78 |
d433b50e
|
Leszek Koltunski
|
RubikObject obj = new RubikObject(type);
|
79 |
a7d8c3cd
|
Leszek Koltunski
|
mObjects.add(obj);
|
80 |
|
|
mNumObjects++;
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
// PUBLIC API
|
86 |
d433b50e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87 |
|
|
// historically older versions of the app had lower 'maxScrambles' in case of several objects and
|
88 |
|
|
// those got remembered in the server-side DB already, so we need to keep using them. This function
|
89 |
|
|
// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have
|
90 |
|
|
// those two values the same.
|
91 |
|
|
|
92 |
|
|
public static int getDBLevel(int ordinal)
|
93 |
|
|
{
|
94 |
|
|
if( ordinal==ObjectConstants.CUBE_3 ) return 16;
|
95 |
|
|
if( ordinal==ObjectConstants.CUBE_4 ) return 20;
|
96 |
|
|
if( ordinal==ObjectConstants.CUBE_5 ) return 24;
|
97 |
|
|
if( ordinal==ObjectConstants.PYRA_4 ) return 15;
|
98 |
|
|
if( ordinal==ObjectConstants.PYRA_5 ) return 20;
|
99 |
|
|
if( ordinal==ObjectConstants.MEGA_5 ) return 35;
|
100 |
|
|
if( ordinal==ObjectConstants.DIAM_2 ) return 10;
|
101 |
|
|
if( ordinal==ObjectConstants.DIAM_3 ) return 18;
|
102 |
|
|
if( ordinal==ObjectConstants.REDI_3 ) return 14;
|
103 |
|
|
if( ordinal==ObjectConstants.HELI_3 ) return 18;
|
104 |
|
|
if( ordinal==ObjectConstants.SKEW_3 ) return 17;
|
105 |
|
|
if( ordinal==ObjectConstants.REX_3 ) return 16;
|
106 |
|
|
if( ordinal==ObjectConstants.MIRR_3 ) return 16;
|
107 |
|
|
|
108 |
|
|
ObjectType type = ObjectType.getObject(ordinal);
|
109 |
|
|
return type.getNumScramble();
|
110 |
|
|
}
|
111 |
|
|
|
112 |
f12e4de9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
|
114 |
|
|
public static void setMeshState(int ordinal, int state)
|
115 |
|
|
{
|
116 |
|
|
if( ordinal>=0 && ordinal<mNumObjects ) mObjects.get(ordinal).setMeshState(state);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
public static int getMeshState(int ordinal)
|
122 |
|
|
{
|
123 |
|
|
return (ordinal>=0 && ordinal<mNumObjects) ? mObjects.get(ordinal).getMeshState() : MESH_NICE;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
400ff34d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127 |
|
|
|
128 |
|
|
public static void savePreferences(SharedPreferences.Editor editor)
|
129 |
|
|
{
|
130 |
f12e4de9
|
Leszek Koltunski
|
RubikObject obj = getObject(mObject);
|
131 |
|
|
if( obj!=null ) editor.putString("rol_objName", obj.getName() );
|
132 |
|
|
}
|
133 |
400ff34d
|
Leszek Koltunski
|
|
134 |
f12e4de9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
|
|
|
136 |
|
|
public static void saveMeshState(SharedPreferences.Editor editor)
|
137 |
|
|
{
|
138 |
|
|
for(int i=0; i<mNumObjects; i++)
|
139 |
400ff34d
|
Leszek Koltunski
|
{
|
140 |
f12e4de9
|
Leszek Koltunski
|
RubikObject obj = getObject(i);
|
141 |
|
|
|
142 |
|
|
if( obj!=null )
|
143 |
|
|
{
|
144 |
|
|
String name = obj.getName();
|
145 |
|
|
editor.putInt("rol_"+name, obj.getMeshState() );
|
146 |
|
|
}
|
147 |
400ff34d
|
Leszek Koltunski
|
}
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
|
152 |
|
|
public static void restorePreferences(SharedPreferences preferences)
|
153 |
|
|
{
|
154 |
|
|
RubikObject object = getObject(DEF_OBJECT);
|
155 |
|
|
String defName = object==null ? "CUBE_3" : object.getName();
|
156 |
f12e4de9
|
Leszek Koltunski
|
String objName= preferences.getString("rol_objName",defName);
|
157 |
400ff34d
|
Leszek Koltunski
|
mObject = getOrdinal(objName);
|
158 |
|
|
|
159 |
|
|
if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
f12e4de9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
|
|
public static void restoreMeshState(SharedPreferences preferences)
|
165 |
|
|
{
|
166 |
|
|
for(int i=0; i<mNumObjects; i++)
|
167 |
|
|
{
|
168 |
|
|
RubikObject obj = getObject(i);
|
169 |
|
|
|
170 |
|
|
if( obj!=null )
|
171 |
|
|
{
|
172 |
|
|
String name = obj.getName();
|
173 |
|
|
int meshState= preferences.getInt("rol_"+name,MESH_NICE);
|
174 |
|
|
obj.setMeshState(meshState);
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
400ff34d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180 |
|
|
|
181 |
|
|
public static boolean setCurrObject(RubikActivity act, int ordinal)
|
182 |
|
|
{
|
183 |
|
|
if( mObject!=ordinal )
|
184 |
|
|
{
|
185 |
|
|
mObject = ordinal;
|
186 |
|
|
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
187 |
|
|
play.setCurrObject(act);
|
188 |
|
|
return true;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
return false;
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195 |
|
|
|
196 |
|
|
public static int getCurrObject()
|
197 |
|
|
{
|
198 |
|
|
return mObject;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
d433b50e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
a7d8c3cd
|
Leszek Koltunski
|
|
203 |
|
|
public static RubikObject getObject(int ordinal)
|
204 |
|
|
{
|
205 |
|
|
if( mType==null ) mType = new RubikObjectList();
|
206 |
|
|
return ordinal>=0 && ordinal<mNumObjects ? mObjects.get(ordinal) : null;
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210 |
|
|
|
211 |
|
|
public static int getNumObjects()
|
212 |
|
|
{
|
213 |
|
|
if( mType==null ) mType = new RubikObjectList();
|
214 |
|
|
return mNumObjects;
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218 |
|
|
|
219 |
|
|
public static int getOrdinal(String name)
|
220 |
|
|
{
|
221 |
|
|
if( mType==null ) mType = new RubikObjectList();
|
222 |
|
|
|
223 |
|
|
for(int i=0; i<mNumObjects; i++)
|
224 |
|
|
{
|
225 |
|
|
RubikObject obj = mObjects.get(i);
|
226 |
|
|
|
227 |
|
|
if( obj.getName().equals(name) ) return i;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
return -1;
|
231 |
|
|
}
|
232 |
|
|
}
|