Project

General

Profile

Download (21.1 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / RubikObjectList.java @ 00fcfefa

1 a7d8c3cd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 f05e0259 Leszek Koltunski
// 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 a7d8c3cd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objects;
11
12 804293f0 Leszek Koltunski
import java.util.ArrayList;
13 5e048300 Leszek Koltunski
import java.util.Locale;
14 804293f0 Leszek Koltunski
15 81493402 Leszek Koltunski
import android.content.Context;
16 400ff34d Leszek Koltunski
import android.content.SharedPreferences;
17
18 81493402 Leszek Koltunski
import org.distorted.external.RubikFiles;
19 05c044a5 Leszek Koltunski
import org.distorted.external.RubikScores;
20 400ff34d Leszek Koltunski
import org.distorted.main.RubikActivity;
21 e4733ed7 Leszek Koltunski
import org.distorted.objectlib.main.ObjectSignatures;
22 a7d8c3cd Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
23
24 09cf2a36 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
25 a7d8c3cd Leszek Koltunski
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
26 e847c553 Leszek Koltunski
import static org.distorted.main.RubikActivity.SHOW_DOWNLOADED_DEBUG;
27 d7f0c07d Leszek Koltunski
import static org.distorted.screens.RubikScreenPlay.LEVELS_SHOWN;
28 a7d8c3cd Leszek Koltunski
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30
31
public class RubikObjectList
32
{
33 e4733ed7 Leszek Koltunski
  public static final int DEF_OBJECT= ObjectSignatures.CUBE_3;
34 506f7ceb Leszek Koltunski
  private static RubikObjectList mThis;
35 a7d8c3cd Leszek Koltunski
  private static int mNumObjects;
36 fcf7320f Leszek Koltunski
  private static int mNumExtras;
37 a7d8c3cd Leszek Koltunski
  private static ArrayList<RubikObject> mObjects;
38 400ff34d Leszek Koltunski
  private static int mObject = DEF_OBJECT;
39 a7d8c3cd Leszek Koltunski
40 314e9ff0 Leszek Koltunski
  public static class DownloadedObject
41 506f7ceb Leszek Koltunski
    {
42
    String shortName;
43 80f574a1 Leszek Koltunski
    boolean icon,object,extras,free;
44 84d746d7 Leszek Koltunski
    int numScrambles, objectMinor, extrasMinor;
45 506f7ceb Leszek Koltunski
46 80f574a1 Leszek Koltunski
    DownloadedObject(String sName, int scrambles, boolean isFree, int oMinor, int eMinor, boolean i, boolean o, boolean e)
47 506f7ceb Leszek Koltunski
      {
48
      shortName = sName;
49 84d746d7 Leszek Koltunski
50
      numScrambles= scrambles;
51 80f574a1 Leszek Koltunski
      free        = isFree;
52 84d746d7 Leszek Koltunski
      objectMinor = oMinor;
53
      extrasMinor = eMinor;
54
55 506f7ceb Leszek Koltunski
      icon   = i;
56
      object = o;
57
      extras = e;
58
      }
59
    }
60
61
  private static ArrayList<DownloadedObject> mDownloadedObjects;
62 7e97ea45 Leszek Koltunski
  /*
63 9b763e1c Leszek Koltunski
  private static String mFreeSolvedObjects;
64
  private static String mFreeBoughtObjects;
65 6142069a Leszek Koltunski
  private static int mNumFreeSolved;
66 7e97ea45 Leszek Koltunski
  */
67 a7d8c3cd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
  private RubikObjectList()
70
    {
71 6142069a Leszek Koltunski
    mNumObjects    = 0;
72
    mNumExtras     = 0;
73 7e97ea45 Leszek Koltunski
    //mNumFreeSolved = 0;
74 804293f0 Leszek Koltunski
75 506f7ceb Leszek Koltunski
    mObjects           = new ArrayList<>();
76
    mDownloadedObjects = new ArrayList<>();
77 a7d8c3cd Leszek Koltunski
78
    createBuiltinObjects();
79
    }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83
  private void createBuiltinObjects()
84
    {
85
    for(int i=0; i<NUM_OBJECTS; i++)
86
      {
87
      ObjectType type = ObjectType.getObject(i);
88 d433b50e Leszek Koltunski
      RubikObject obj = new RubikObject(type);
89 a7d8c3cd Leszek Koltunski
      mObjects.add(obj);
90
      mNumObjects++;
91 804293f0 Leszek Koltunski
92 e847c553 Leszek Koltunski
      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "creating local object "+type.name() );
93 84d746d7 Leszek Koltunski
94 314e9ff0 Leszek Koltunski
      if( obj.hasExtras() )
95 804293f0 Leszek Koltunski
        {
96 e847c553 Leszek Koltunski
        if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "has extras "+mNumExtras );
97 84d746d7 Leszek Koltunski
98 fcf7320f Leszek Koltunski
        obj.setExtrasOrdinal(mNumExtras);
99
        mNumExtras++;
100 84d746d7 Leszek Koltunski
        }
101
      else
102
        {
103 e847c553 Leszek Koltunski
        if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "no extras");
104 804293f0 Leszek Koltunski
        }
105 a7d8c3cd Leszek Koltunski
      }
106
    }
107
108 506f7ceb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110 84d746d7 Leszek Koltunski
  private static boolean internalAddDownloadedObject(DownloadedObject object)
111 506f7ceb Leszek Koltunski
    {
112 314e9ff0 Leszek Koltunski
    String name = object.shortName;
113
114
    for(RubikObject ro : mObjects )
115 84d746d7 Leszek Koltunski
      if( ro.getLowerName().equals(name) )
116 314e9ff0 Leszek Koltunski
        {
117 84d746d7 Leszek Koltunski
        return ro.updateObject(object);
118 314e9ff0 Leszek Koltunski
        }
119
120 84d746d7 Leszek Koltunski
    RubikObject obj = new RubikObject(object);
121
    mObjects.add(obj);
122
    mNumObjects++;
123 7e97ea45 Leszek Koltunski
    /*
124 6142069a Leszek Koltunski
    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 7e97ea45 Leszek Koltunski
    */
133 e847c553 Leszek Koltunski
    if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "creating downloaded object "+obj.getUpperName() );
134 84d746d7 Leszek Koltunski
135
    if( obj.hasExtras() )
136 314e9ff0 Leszek Koltunski
      {
137 e847c553 Leszek Koltunski
      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "has extras "+mNumExtras );
138 506f7ceb Leszek Koltunski
139 84d746d7 Leszek Koltunski
      obj.setExtrasOrdinal(mNumExtras);
140
      mNumExtras++;
141
      }
142
    else
143
      {
144 e847c553 Leszek Koltunski
      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "no extras");
145 314e9ff0 Leszek Koltunski
      }
146 84d746d7 Leszek Koltunski
147
    return true;
148 506f7ceb Leszek Koltunski
    }
149
150 6142069a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
151 05c044a5 Leszek Koltunski
152 6142069a Leszek Koltunski
  private static void restoreFreedObjects(SharedPreferences preferences)
153
    {
154 05c044a5 Leszek Koltunski
    /*
155 6142069a Leszek Koltunski
    mFreeSolvedObjects = preferences.getString("rol_freeSolved", "");
156
    mFreeBoughtObjects = preferences.getString("rol_freeBought", "");
157
158
    if( SHOW_SOLVED_DEBUG )
159
      {
160
      android.util.Log.e("D", "freeSolved: "+mFreeSolvedObjects);
161
      android.util.Log.e("D", "freeBought: "+mFreeBoughtObjects);
162
      }
163
164
    if( mFreeBoughtObjects.length()>0 )
165
      {
166
      if( mFreeBoughtObjects.charAt(0)=='*' )
167
        {
168
        for(int i=0; i<mNumObjects; i++)
169
          {
170
          RubikObject o = mObjects.get(i);
171
          o.markFree();
172
          }
173
        }
174
      else
175
        {
176
        String[] objs = mFreeBoughtObjects.split(",");
177
178
        for( String obj : objs )
179
          {
180
          RubikObject o = getObject(obj);
181
          if( o!=null ) o.markFree();
182
          }
183
        }
184
      }
185
186
    if( mFreeSolvedObjects.length()>0 )
187
      {
188
      String[] objs = mFreeSolvedObjects.split(",");
189
      mNumFreeSolved = objs.length;
190
191
      for( String obj : objs )
192
        {
193
        RubikObject o = getObject(obj);
194
        if( o!=null ) o.markFree();
195
        }
196
      }
197 05c044a5 Leszek Koltunski
     */
198 6142069a Leszek Koltunski
    }
199
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202
  private static int getNumUnclaimedSolves()
203
    {
204 05c044a5 Leszek Koltunski
    /*
205 6142069a Leszek Koltunski
    RubikScores scores = RubikScores.getInstance();
206
    int numMAXes = scores.numberOfSolvedMAXes();
207
    return numMAXes-mNumFreeSolved;
208 05c044a5 Leszek Koltunski
     */
209
210
    return 0;
211 6142069a Leszek Koltunski
    }
212
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
215
  private static int markAllSolvedAsFree()
216
    {
217
    RubikScores scores = RubikScores.getInstance();
218
    int numObjects = RubikObjectList.getNumObjects();
219
    int ret = 0;
220
221
    for(int obj=0; obj<numObjects; obj++)
222
      {
223
      RubikObject object = getObject(obj);
224
225 05c044a5 Leszek Koltunski
      if( object!=null && !object.isFree() && scores.isSolved(obj,LEVELS_SHOWN) )
226 6142069a Leszek Koltunski
        {
227
        solveObject(object.getUpperName());
228
        ret++;
229
        }
230
      }
231
232
    return ret;
233
    }
234
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237
  private static void markAsFree(int numToBeMarked)
238
    {
239
    int numObjects = RubikObjectList.getNumObjects();
240
241
    for(int obj=0; obj<numObjects && numToBeMarked>0; obj++)
242
      {
243
      RubikObject object = getObject(obj);
244
245
      if( object!=null && !object.isFree() )
246
        {
247
        solveObject(object.getUpperName());
248
        numToBeMarked--;
249
        }
250
      }
251
    }
252
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255
  public static boolean solveObject(RubikObject object, String shortName)
256
    {
257 05c044a5 Leszek Koltunski
    /*
258 6142069a Leszek Koltunski
    if( object!=null && !object.isFree() )
259
      {
260
      if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as solved");
261
      object.markFree();
262
      String add = mFreeSolvedObjects.length()==0 ? shortName : (","+shortName);
263
      mFreeSolvedObjects += add;
264
      mNumFreeSolved++;
265
      return true;
266
      }
267 05c044a5 Leszek Koltunski
    */
268 6142069a Leszek Koltunski
    return false;
269
    }
270 05c044a5 Leszek Koltunski
271 a7d8c3cd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
272
// PUBLIC API
273 806329e3 Leszek Koltunski
274 80f574a1 Leszek Koltunski
  public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, boolean isFree, int objectMinor,
275 81493402 Leszek Koltunski
                                         int extrasMinor, boolean icon, boolean object, boolean extras)
276 806329e3 Leszek Koltunski
    {
277 c89c3b1b Leszek Koltunski
    if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "New downloaded object "+shortName+" icon="+icon+" object="+object+" extras="+extras);
278
279 506f7ceb Leszek Koltunski
    for( DownloadedObject obj : mDownloadedObjects )
280
      {
281
      if( obj.shortName.equals(shortName) )
282
        {
283
        obj.icon  |= icon;
284
        obj.object|= object;
285
        obj.extras|= extras;
286
287 c89c3b1b Leszek Koltunski
        if( !obj.object ) objectMinor=-1;
288
        if( !obj.extras ) extrasMinor=-1;
289
290
        obj.objectMinor = objectMinor;
291
        obj.extrasMinor = extrasMinor;
292
293
        if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Updating downloaded object "+shortName+" icon="+obj.icon+" object="+obj.object+" extras="+obj.extras);
294 506f7ceb Leszek Koltunski
295 41a5dd89 Leszek Koltunski
        try
296
          {
297
          RubikActivity ract = (RubikActivity)context;
298
          ract.reloadObject(shortName);
299
          }
300
        catch(Exception ex)
301
          {
302
          android.util.Log.e("D", "exception trying to reload object: "+ex.getMessage() );
303
          }
304
305 ac1900c3 Leszek Koltunski
        return false;
306 506f7ceb Leszek Koltunski
        }
307
      }
308
309 c89c3b1b Leszek Koltunski
    if( !object ) objectMinor=-1;
310
    if( !extras ) extrasMinor=-1;
311
312 80f574a1 Leszek Koltunski
    DownloadedObject obj = new DownloadedObject(shortName,numScrambles,isFree,objectMinor,extrasMinor,icon,object,extras);
313 c89c3b1b Leszek Koltunski
    if ( internalAddDownloadedObject(obj) )
314 84d746d7 Leszek Koltunski
      {
315 c89c3b1b Leszek Koltunski
      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Adding new downloaded object "+shortName+" icon="+obj.icon+" object="+obj.object+" extras="+obj.extras);
316
      mDownloadedObjects.add(obj);
317 ac1900c3 Leszek Koltunski
      return true;
318 84d746d7 Leszek Koltunski
      }
319 81493402 Leszek Koltunski
    else
320
      {
321
      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "New downloaded object "+shortName+" is already built-in, deleting");
322
      RubikFiles files = RubikFiles.getInstance();
323
      files.deleteIcon(context,shortName);
324
      files.deleteJsonObject(context,shortName);
325
      files.deleteJsonExtras(context,shortName);
326 ac1900c3 Leszek Koltunski
      return false;
327 81493402 Leszek Koltunski
      }
328 806329e3 Leszek Koltunski
    }
329
330 f12e4de9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
331
332
  public static void setMeshState(int ordinal, int state)
333
    {
334
    if( ordinal>=0 && ordinal<mNumObjects ) mObjects.get(ordinal).setMeshState(state);
335
    }
336
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338
339
  public static int getMeshState(int ordinal)
340
    {
341
    return (ordinal>=0 && ordinal<mNumObjects) ? mObjects.get(ordinal).getMeshState() : MESH_NICE;
342
    }
343
344 9b763e1c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
345
346
  public static void saveMeshState(SharedPreferences.Editor editor)
347
    {
348
    for(int i=0; i<mNumObjects; i++)
349
      {
350
      RubikObject obj = getObject(i);
351
352
      if( obj!=null )
353
        {
354
        String name = obj.getUpperName();
355
        editor.putInt("rol_"+name, obj.getMeshState() );
356
        }
357
      }
358
    }
359 05c044a5 Leszek Koltunski
360 7480fbab Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
361
362
  public static boolean allAlreadyBought()
363
    {
364 05c044a5 Leszek Koltunski
    //return mFreeBoughtObjects.equals("*");
365
    return false;
366 7480fbab Leszek Koltunski
    }
367
368 24679c47 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
369
370
  public static boolean thereAreLockedObjects()
371
    {
372
    for(int i=0; i<mNumObjects; i++)
373
      {
374
      RubikObject o = mObjects.get(i);
375
      if( !o.isFree() ) return true;
376
      }
377
378
    return false;
379
    }
380
381 7480fbab Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
382
383
  public static boolean objectAlreadyBought(String shortName)
384
    {
385
    RubikObject o = getObject(shortName);
386
    return ( o!=null && o.isFree() );
387
    }
388
389 9b763e1c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
390
391
  public static void buyAll()
392
    {
393 05c044a5 Leszek Koltunski
    /*
394 9b763e1c Leszek Koltunski
    mFreeBoughtObjects = "*";
395 6142069a Leszek Koltunski
    if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "all objects marked as bought");
396 9b763e1c Leszek Koltunski
397
    for(int i=0; i<mNumObjects; i++)
398
      {
399
      RubikObject o = mObjects.get(i);
400
      o.markFree();
401
      }
402 05c044a5 Leszek Koltunski
    */
403 9b763e1c Leszek Koltunski
    }
404
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407
  public static boolean buyObject(String shortName)
408
    {
409 05c044a5 Leszek Koltunski
    /*
410 9b763e1c Leszek Koltunski
    RubikObject o = getObject(shortName);
411
412
    if( o!=null && !o.isFree() )
413
      {
414 6142069a Leszek Koltunski
      if( SHOW_SOLVED_DEBUG ) android.util.Log.e("D", "object "+shortName+" marked as bought");
415 9b763e1c Leszek Koltunski
      o.markFree();
416 7480fbab Leszek Koltunski
      String add = mFreeBoughtObjects.length()==0 ? shortName : (","+shortName);
417
      mFreeBoughtObjects += add;
418 9b763e1c Leszek Koltunski
      return true;
419
      }
420 05c044a5 Leszek Koltunski
    */
421 9b763e1c Leszek Koltunski
    return false;
422
    }
423
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
426
  public static boolean solveObject(String shortName)
427
    {
428 6142069a Leszek Koltunski
    RubikObject object = getObject(shortName);
429
    return solveObject(object,shortName);
430 9b763e1c Leszek Koltunski
    }
431 05c044a5 Leszek Koltunski
432 400ff34d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
433
434
  public static void savePreferences(SharedPreferences.Editor editor)
435
    {
436 f12e4de9 Leszek Koltunski
    RubikObject obj = getObject(mObject);
437 84d746d7 Leszek Koltunski
    if( obj!=null ) editor.putString("rol_objName", obj.getUpperName() );
438 506f7ceb Leszek Koltunski
439
    int numDownloaded = mDownloadedObjects.size();
440
441
    if( numDownloaded>0 )
442
      {
443
      StringBuilder downloadedObjects = new StringBuilder();
444
445
      for(int i=0; i<numDownloaded; i++)
446
        {
447
        if( i>0 ) downloadedObjects.append(',');
448
449
        DownloadedObject object = mDownloadedObjects.get(i);
450
        downloadedObjects.append(object.shortName);
451
        downloadedObjects.append(' ');
452 84d746d7 Leszek Koltunski
        downloadedObjects.append(object.numScrambles);
453
        downloadedObjects.append(' ');
454
        downloadedObjects.append(object.objectMinor);
455
        downloadedObjects.append(' ');
456
        downloadedObjects.append(object.extrasMinor);
457
        downloadedObjects.append(' ');
458 506f7ceb Leszek Koltunski
        downloadedObjects.append(object.icon   ? "1":"0");
459
        downloadedObjects.append(' ');
460
        downloadedObjects.append(object.object ? "1":"0");
461
        downloadedObjects.append(' ');
462
        downloadedObjects.append(object.extras ? "1":"0");
463 80f574a1 Leszek Koltunski
        downloadedObjects.append(' ');
464
        downloadedObjects.append(object.free ? "true":"false");
465 506f7ceb Leszek Koltunski
        }
466
467 84d746d7 Leszek Koltunski
      String objects = downloadedObjects.toString();
468 e847c553 Leszek Koltunski
      if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "saving: "+objects);
469 84d746d7 Leszek Koltunski
      editor.putString("rol_downloaded", objects );
470 506f7ceb Leszek Koltunski
      }
471 7e9139c1 Leszek Koltunski
    else
472
      {
473
      editor.putString("rol_downloaded", "" );
474
      }
475 7e97ea45 Leszek Koltunski
/*
476 9b763e1c Leszek Koltunski
    editor.putString("rol_freeSolved", mFreeSolvedObjects);
477
    editor.putString("rol_freeBought", mFreeBoughtObjects);
478 6142069a Leszek Koltunski
479
    if( SHOW_SOLVED_DEBUG )
480
      {
481
      android.util.Log.e("D", "saving solved objects: "+mFreeSolvedObjects);
482
      android.util.Log.e("D", "saving bought objects: "+mFreeBoughtObjects);
483
      }
484 7e97ea45 Leszek Koltunski
 */
485 400ff34d Leszek Koltunski
    }
486
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488
489 7480fbab Leszek Koltunski
  public static void restorePreferences(Context context, SharedPreferences preferences, boolean justStarted)
490 400ff34d Leszek Koltunski
    {
491 526a5906 Leszek Koltunski
    if( mThis==null ) mThis = new RubikObjectList();
492
493 506f7ceb Leszek Koltunski
    String downloaded = preferences.getString("rol_downloaded","");
494
495 e847c553 Leszek Koltunski
    if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", downloaded);
496 506f7ceb Leszek Koltunski
497
    if( !downloaded.equals(""))
498
      {
499
      String[] dObjects = downloaded.split(",");
500
501
      for(String dObj : dObjects)
502
        {
503
        String[] parts = dObj.split(" ");
504 80f574a1 Leszek Koltunski
        int length = parts.length;
505 506f7ceb Leszek Koltunski
506 80f574a1 Leszek Koltunski
        if( length==7 || length==8 )
507 506f7ceb Leszek Koltunski
          {
508
          String name = parts[0];
509 84d746d7 Leszek Koltunski
          String scra = parts[1];
510
          String objM = parts[2];
511
          String extM = parts[3];
512
          String icon = parts[4];
513
          String obje = parts[5];
514
          String extr = parts[6];
515 80f574a1 Leszek Koltunski
          boolean isFree = (length==7 || Boolean.parseBoolean(parts[7]));
516 84d746d7 Leszek Koltunski
517
          int scrambles = Integer.parseInt(scra);
518
          int oMinor    = Integer.parseInt(objM);
519
          int eMinor    = Integer.parseInt(extM);
520 506f7ceb Leszek Koltunski
521
          boolean bIcon = icon.equals("1");
522
          boolean bObje = obje.equals("1");
523
          boolean bExtr = extr.equals("1");
524
525 80f574a1 Leszek Koltunski
          addDownloadedObject(context,name,scrambles,isFree,oMinor,eMinor,bIcon,bObje,bExtr);
526 506f7ceb Leszek Koltunski
          }
527
        }
528
      }
529 d9d2c5fb Leszek Koltunski
530
    RubikObject object = getObject(DEF_OBJECT);
531
    String defName = object==null ? "CUBE_3" : object.getUpperName();
532
    String objName= preferences.getString("rol_objName",defName);
533
    mObject = getOrdinal(objName);
534
    if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT;
535 9b763e1c Leszek Koltunski
536 05c044a5 Leszek Koltunski
    if( justStarted) restoreFreedObjects(preferences);
537 400ff34d Leszek Koltunski
    }
538
539 f12e4de9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
540
541
  public static void restoreMeshState(SharedPreferences preferences)
542
    {
543
    for(int i=0; i<mNumObjects; i++)
544
      {
545
      RubikObject obj = getObject(i);
546
547
      if( obj!=null )
548
        {
549 84d746d7 Leszek Koltunski
        String name  = obj.getUpperName();
550 f12e4de9 Leszek Koltunski
        int meshState= preferences.getInt("rol_"+name,MESH_NICE);
551
        obj.setMeshState(meshState);
552
        }
553
      }
554
    }
555
556 6142069a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
557 05c044a5 Leszek Koltunski
558 6142069a Leszek Koltunski
  public static void setObjectFreeState()
559
    {
560
    int numUnclaimed = getNumUnclaimedSolves();
561
562
    if( numUnclaimed>0 )
563
      {
564
      int marked = markAllSolvedAsFree();
565
      int stillUnclaimed = numUnclaimed-marked;
566
      if( stillUnclaimed>0) markAsFree(stillUnclaimed);
567
      }
568
    }
569 05c044a5 Leszek Koltunski
570 400ff34d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
571
572 1088a219 Leszek Koltunski
  public static boolean setCurrObject(int ordinal)
573 400ff34d Leszek Koltunski
    {
574
    if( mObject!=ordinal )
575
      {
576
      mObject = ordinal;
577
      return true;
578
      }
579
580
    return false;
581
    }
582
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
585
  public static int getCurrObject()
586
    {
587
    return mObject;
588
    }
589
590 69b66386 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
591
592
  public static String getCurrentName()
593
    {
594
    RubikObject object = mObjects.get(mObject);
595
    return object==null ? "" : object.getUpperName();
596
    }
597
598 d433b50e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
599 a7d8c3cd Leszek Koltunski
600
  public static RubikObject getObject(int ordinal)
601
    {
602 506f7ceb Leszek Koltunski
    if( mThis==null ) mThis = new RubikObjectList();
603 a7d8c3cd Leszek Koltunski
    return ordinal>=0 && ordinal<mNumObjects ? mObjects.get(ordinal) : null;
604
    }
605
606 41a5dd89 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
607
608
  public static RubikObject getObject(String shortUpperName)
609
    {
610
    if( mThis==null ) mThis = new RubikObjectList();
611
612
    for(int i=0; i<mNumObjects; i++)
613
      {
614
      RubikObject object = mObjects.get(i);
615
      if( object.getUpperName().equals(shortUpperName) )
616
        {
617
        return object;
618
        }
619
      }
620
621
    return null;
622
    }
623
624 a7d8c3cd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
625
626
  public static int getNumObjects()
627
    {
628 506f7ceb Leszek Koltunski
    if( mThis==null ) mThis = new RubikObjectList();
629 a7d8c3cd Leszek Koltunski
    return mNumObjects;
630
    }
631
632
///////////////////////////////////////////////////////////////////////////////////////////////////
633
634
  public static int getOrdinal(String name)
635
    {
636 506f7ceb Leszek Koltunski
    if( mThis==null ) mThis = new RubikObjectList();
637 a7d8c3cd Leszek Koltunski
638 5e048300 Leszek Koltunski
    String lowerName = name.toLowerCase(Locale.ENGLISH);
639 84d746d7 Leszek Koltunski
640 a7d8c3cd Leszek Koltunski
    for(int i=0; i<mNumObjects; i++)
641
      {
642
      RubikObject obj = mObjects.get(i);
643 84d746d7 Leszek Koltunski
      if( obj.getLowerName().equals(lowerName) ) return i;
644 a7d8c3cd Leszek Koltunski
      }
645
646
    return -1;
647
    }
648 804293f0 Leszek Koltunski
649 fcf7320f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
650
651
  public static int getNumExtrasObjects()
652
    {
653
    return mNumExtras;
654
    }
655
656 804293f0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
657
658
  public static int getNumTutorialObjects()
659
    {
660 fcf7320f Leszek Koltunski
    return mNumExtras;
661 804293f0 Leszek Koltunski
    }
662
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664
665 fcf7320f Leszek Koltunski
  public static int getObjectOrdinal(int extrasOrdinal)
666 804293f0 Leszek Koltunski
    {
667 fcf7320f Leszek Koltunski
    for(int i=extrasOrdinal; i<mNumObjects; i++)
668 804293f0 Leszek Koltunski
      {
669
      RubikObject object = getObject(i);
670 fcf7320f Leszek Koltunski
      int extOrd = object!=null ? object.getExtrasOrdinal() : -1;
671
      if( extOrd==extrasOrdinal ) return i;
672 804293f0 Leszek Koltunski
      }
673
674
    return -1;
675
    }
676
677 fcf7320f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
678
679
  public static int getExtrasOrdinal(int objectOrdinal)
680
    {
681
    RubikObject object = getObject(objectOrdinal);
682
    return object!=null ? object.getExtrasOrdinal() : -1;
683
    }
684
685 804293f0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
686
687
  public static int getTutorialOrdinal(int objectOrdinal)
688
    {
689
    RubikObject object = getObject(objectOrdinal);
690 fcf7320f Leszek Koltunski
    return object!=null ? object.getExtrasOrdinal() : -1;
691
    }
692
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694
695
  public static int getLocalObjectMinor(int objectOrdinal)
696
    {
697
    RubikObject object = getObject(objectOrdinal);
698
    return object!=null ? object.getObjectMinor() : -1;
699
    }
700
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702
703
  public static int getLocalExtrasMinor(int objectOrdinal)
704
    {
705
    RubikObject object = getObject(objectOrdinal);
706
    return object!=null ? object.getExtrasMinor() : -1;
707 804293f0 Leszek Koltunski
    }
708 a7d8c3cd Leszek Koltunski
}