16 |
16 |
import android.content.SharedPreferences;
|
17 |
17 |
|
18 |
18 |
import org.distorted.external.RubikFiles;
|
|
19 |
import org.distorted.external.RubikScores;
|
19 |
20 |
import org.distorted.main.RubikActivity;
|
20 |
21 |
import org.distorted.objectlib.main.ObjectSignatures;
|
21 |
22 |
import org.distorted.objectlib.main.ObjectType;
|
|
23 |
import org.distorted.screens.RubikScreenPlay;
|
22 |
24 |
|
23 |
25 |
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
24 |
26 |
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
|
25 |
27 |
import static org.distorted.main.RubikActivity.SHOW_DOWNLOADED_DEBUG;
|
|
28 |
import static org.distorted.main.RubikActivity.SHOW_SOLVED_DEBUG;
|
26 |
29 |
|
27 |
30 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
31 |
|
... | ... | |
59 |
62 |
private static ArrayList<DownloadedObject> mDownloadedObjects;
|
60 |
63 |
private static String mFreeSolvedObjects;
|
61 |
64 |
private static String mFreeBoughtObjects;
|
|
65 |
private static int mNumFreeSolved;
|
62 |
66 |
|
63 |
67 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
68 |
|
65 |
69 |
private RubikObjectList()
|
66 |
70 |
{
|
67 |
|
mNumObjects= 0;
|
68 |
|
mNumExtras = 0;
|
|
71 |
mNumObjects = 0;
|
|
72 |
mNumExtras = 0;
|
|
73 |
mNumFreeSolved = 0;
|
69 |
74 |
|
70 |
75 |
mObjects = new ArrayList<>();
|
71 |
76 |
mDownloadedObjects = new ArrayList<>();
|
... | ... | |
116 |
121 |
mObjects.add(obj);
|
117 |
122 |
mNumObjects++;
|
118 |
123 |
|
|
124 |
int numUnclaimed = getNumUnclaimedSolves();
|
|
125 |
|
|
126 |
if( numUnclaimed>0 && !obj.isFree() )
|
|
127 |
{
|
|
128 |
String objname = obj.getUpperName();
|
|
129 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "downloadedObject: "+objname+" making it solved. Unclaimed: "+numUnclaimed);
|
|
130 |
solveObject(obj,objname);
|
|
131 |
}
|
|
132 |
|
119 |
133 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "creating downloaded object "+obj.getUpperName() );
|
120 |
134 |
|
121 |
135 |
if( obj.hasExtras() )
|
... | ... | |
133 |
147 |
return true;
|
134 |
148 |
}
|
135 |
149 |
|
|
150 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
151 |
|
|
152 |
private static void restoreFreedObjects(SharedPreferences preferences)
|
|
153 |
{
|
|
154 |
mFreeSolvedObjects = preferences.getString("rol_freeSolved", "");
|
|
155 |
mFreeBoughtObjects = preferences.getString("rol_freeBought", "");
|
|
156 |
|
|
157 |
if( SHOW_SOLVED_DEBUG )
|
|
158 |
{
|
|
159 |
android.util.Log.e("D", "freeSolved: "+mFreeSolvedObjects);
|
|
160 |
android.util.Log.e("D", "freeBought: "+mFreeBoughtObjects);
|
|
161 |
}
|
|
162 |
|
|
163 |
if( mFreeBoughtObjects.length()>0 )
|
|
164 |
{
|
|
165 |
if( mFreeBoughtObjects.charAt(0)=='*' )
|
|
166 |
{
|
|
167 |
for(int i=0; i<mNumObjects; i++)
|
|
168 |
{
|
|
169 |
RubikObject o = mObjects.get(i);
|
|
170 |
o.markFree();
|
|
171 |
}
|
|
172 |
}
|
|
173 |
else
|
|
174 |
{
|
|
175 |
String[] objs = mFreeBoughtObjects.split(",");
|
|
176 |
|
|
177 |
for( String obj : objs )
|
|
178 |
{
|
|
179 |
RubikObject o = getObject(obj);
|
|
180 |
if( o!=null ) o.markFree();
|
|
181 |
}
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
if( mFreeSolvedObjects.length()>0 )
|
|
186 |
{
|
|
187 |
String[] objs = mFreeSolvedObjects.split(",");
|
|
188 |
mNumFreeSolved = objs.length;
|
|
189 |
|
|
190 |
for( String obj : objs )
|
|
191 |
{
|
|
192 |
RubikObject o = getObject(obj);
|
|
193 |
if( o!=null ) o.markFree();
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
199 |
|
|
200 |
private static int getNumUnclaimedSolves()
|
|
201 |
{
|
|
202 |
RubikScores scores = RubikScores.getInstance();
|
|
203 |
int numMAXes = scores.numberOfSolvedMAXes();
|
|
204 |
return numMAXes-mNumFreeSolved;
|
|
205 |
}
|
|
206 |
|
|
207 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
208 |
|
|
209 |
private static int markAllSolvedAsFree()
|
|
210 |
{
|
|
211 |
RubikScores scores = RubikScores.getInstance();
|
|
212 |
int numObjects = RubikObjectList.getNumObjects();
|
|
213 |
int level = RubikScreenPlay.LEVELS_SHOWN;
|
|
214 |
int ret = 0;
|
|
215 |
|
|
216 |
for(int obj=0; obj<numObjects; obj++)
|
|
217 |
{
|
|
218 |
RubikObject object = getObject(obj);
|
|
219 |
|
|
220 |
if( object!=null && !object.isFree() && scores.isSolved(obj,level) )
|
|
221 |
{
|
|
222 |
solveObject(object.getUpperName());
|
|
223 |
ret++;
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|
|
227 |
return ret;
|
|
228 |
}
|
|
229 |
|
|
230 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
231 |
|
|
232 |
private static void markAsFree(int numToBeMarked)
|
|
233 |
{
|
|
234 |
int numObjects = RubikObjectList.getNumObjects();
|
|
235 |
|
|
236 |
for(int obj=0; obj<numObjects && numToBeMarked>0; obj++)
|
|
237 |
{
|
|
238 |
RubikObject object = getObject(obj);
|
|
239 |
|
|
240 |
if( object!=null && !object.isFree() )
|
|
241 |
{
|
|
242 |
solveObject(object.getUpperName());
|
|
243 |
numToBeMarked--;
|
|
244 |
}
|
|
245 |
}
|
|
246 |
}
|
|
247 |
|
|
248 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
249 |
|
|
250 |
public static boolean solveObject(RubikObject object, String shortName)
|
|
251 |
{
|
|
252 |
if( object!=null && !object.isFree() )
|
|
253 |
{
|
|
254 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as solved");
|
|
255 |
object.markFree();
|
|
256 |
String add = mFreeSolvedObjects.length()==0 ? shortName : (","+shortName);
|
|
257 |
mFreeSolvedObjects += add;
|
|
258 |
mNumFreeSolved++;
|
|
259 |
return true;
|
|
260 |
}
|
|
261 |
|
|
262 |
return false;
|
|
263 |
}
|
|
264 |
|
136 |
265 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137 |
266 |
// PUBLIC API
|
138 |
267 |
|
... | ... | |
242 |
371 |
public static void buyAll()
|
243 |
372 |
{
|
244 |
373 |
mFreeBoughtObjects = "*";
|
|
374 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "all objects marked as bought");
|
245 |
375 |
|
246 |
376 |
for(int i=0; i<mNumObjects; i++)
|
247 |
377 |
{
|
... | ... | |
258 |
388 |
|
259 |
389 |
if( o!=null && !o.isFree() )
|
260 |
390 |
{
|
|
391 |
if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as bought");
|
261 |
392 |
o.markFree();
|
262 |
393 |
String add = mFreeBoughtObjects.length()==0 ? shortName : (","+shortName);
|
263 |
394 |
mFreeBoughtObjects += add;
|
... | ... | |
271 |
402 |
|
272 |
403 |
public static boolean solveObject(String shortName)
|
273 |
404 |
{
|
274 |
|
RubikObject o = getObject(shortName);
|
275 |
|
|
276 |
|
if( o!=null && !o.isFree() )
|
277 |
|
{
|
278 |
|
o.markFree();
|
279 |
|
String add = mFreeSolvedObjects.length()==0 ? shortName : (","+shortName);
|
280 |
|
mFreeSolvedObjects += add;
|
281 |
|
return true;
|
282 |
|
}
|
283 |
|
|
284 |
|
return false;
|
|
405 |
RubikObject object = getObject(shortName);
|
|
406 |
return solveObject(object,shortName);
|
285 |
407 |
}
|
286 |
408 |
|
287 |
409 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
330 |
452 |
|
331 |
453 |
editor.putString("rol_freeSolved", mFreeSolvedObjects);
|
332 |
454 |
editor.putString("rol_freeBought", mFreeBoughtObjects);
|
|
455 |
|
|
456 |
if( SHOW_SOLVED_DEBUG )
|
|
457 |
{
|
|
458 |
android.util.Log.e("D", "saving solved objects: "+mFreeSolvedObjects);
|
|
459 |
android.util.Log.e("D", "saving bought objects: "+mFreeBoughtObjects);
|
|
460 |
}
|
333 |
461 |
}
|
334 |
462 |
|
335 |
463 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
381 |
509 |
mObject = getOrdinal(objName);
|
382 |
510 |
if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT;
|
383 |
511 |
|
384 |
|
if( justStarted )
|
385 |
|
{
|
386 |
|
mFreeSolvedObjects = preferences.getString("rol_freeSolved", "");
|
387 |
|
mFreeBoughtObjects = preferences.getString("rol_freeBought", "");
|
388 |
|
|
389 |
|
if( mFreeBoughtObjects.length()>0 )
|
390 |
|
{
|
391 |
|
if( mFreeBoughtObjects.charAt(0)=='*' )
|
392 |
|
{
|
393 |
|
for(int i=0; i<mNumObjects; i++)
|
394 |
|
{
|
395 |
|
RubikObject o = mObjects.get(i);
|
396 |
|
o.markFree();
|
397 |
|
}
|
398 |
|
}
|
399 |
|
else
|
400 |
|
{
|
401 |
|
String[] objs = mFreeBoughtObjects.split(",");
|
402 |
|
|
403 |
|
for( String obj : objs )
|
404 |
|
{
|
405 |
|
RubikObject o = getObject(obj);
|
406 |
|
if( o!=null ) o.markFree();
|
407 |
|
}
|
408 |
|
}
|
409 |
|
}
|
410 |
|
|
411 |
|
if( mFreeSolvedObjects.length()>0 )
|
412 |
|
{
|
413 |
|
String[] objs = mFreeSolvedObjects.split(",");
|
414 |
|
|
415 |
|
for( String obj : objs )
|
416 |
|
{
|
417 |
|
RubikObject o = getObject(obj);
|
418 |
|
if( o!=null ) o.markFree();
|
419 |
|
}
|
420 |
|
}
|
421 |
|
}
|
|
512 |
if( justStarted) restoreFreedObjects(preferences);
|
422 |
513 |
}
|
423 |
514 |
|
424 |
515 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
438 |
529 |
}
|
439 |
530 |
}
|
440 |
531 |
|
|
532 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
533 |
|
|
534 |
public static void setObjectFreeState()
|
|
535 |
{
|
|
536 |
int numUnclaimed = getNumUnclaimedSolves();
|
|
537 |
|
|
538 |
if( numUnclaimed>0 )
|
|
539 |
{
|
|
540 |
int marked = markAllSolvedAsFree();
|
|
541 |
int stillUnclaimed = numUnclaimed-marked;
|
|
542 |
if( stillUnclaimed>0) markAsFree(stillUnclaimed);
|
|
543 |
}
|
|
544 |
}
|
|
545 |
|
441 |
546 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
442 |
547 |
|
443 |
548 |
public static boolean setCurrObject(int ordinal)
|
Progress with marking objects as free.