Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / RubikObjectList.java @ 05c044a5

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