Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / RubikObjectList.java @ 43382be6

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