Project

General

Profile

« Previous | Next » 

Revision 0c233a9a

Added by Leszek Koltunski over 1 year ago

Partly merge the 'iap' branch.

View differences:

src/main/java/org/distorted/external/RubikScores.java
21 21
import org.distorted.main.BuildConfig;
22 22
import org.distorted.objects.RubikObject;
23 23
import org.distorted.objects.RubikObjectList;
24
import org.distorted.screens.RubikScreenPlay;
24 25

  
25 26
import static org.distorted.objectlib.main.ObjectType.MAX_SCRAMBLES;
26 27

  
......
29 30

  
30 31
public class RubikScores
31 32
  {
33
  public static final int RECORD_FIRST   = 0;
34
  public static final int RECORD_NEW     = 1;
35
  public static final int RECORD_NOT_NEW = 2;
36

  
32 37
  public static final int MAX_RECORD = 10;
33 38
  public static final int MULT = 1000000;
34 39
  public static final long NO_RECORD = Long.MAX_VALUE;
......
40 45
  private int mNumPlays;
41 46
  private int mNumWins;
42 47
  private int mDeviceID;
48
  private int mNumStars;
43 49

  
44 50
  private static class MapValue
45 51
    {
......
70 76
    mNumRuns = -1;
71 77
    mDeviceID= -1;
72 78
    mNumWins =  0;
79
    mNumStars=  0;
73 80
    }
74 81

  
75 82
///////////////////////////////////////////////////////////////////////////////////////////////////
......
228 235
    return mNumWins;
229 236
    }
230 237

  
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
  public void changeNumStars(int stars)
241
    {
242
    mNumStars += stars;
243
    }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
  public int getNumStars()
248
    {
249
    return mNumStars;
250
    }
251

  
231 252
///////////////////////////////////////////////////////////////////////////////////////////////////
232 253

  
233 254
  public void setName(String newName)
......
237 258

  
238 259
///////////////////////////////////////////////////////////////////////////////////////////////////
239 260

  
240
  public synchronized boolean setRecord(int object, int level, long record)
261
  public synchronized int setRecord(int object, int level, long record)
241 262
    {
242 263
    int key = mapKey(object,level);
243 264
    MapValue oldValue = mMap.get(key);
......
246 267
      {
247 268
      MapValue value = new MapValue(record,0);
248 269
      mMap.put(key,value);
249
      return true;
270
      return RECORD_FIRST;
250 271
      }
251 272

  
252 273
    long oldRecord = oldValue.record;
......
255 276
      {
256 277
      MapValue value = new MapValue(record,0);
257 278
      mMap.put(key,value);
258
      return true;
279
      return RECORD_NEW;
259 280
      }
260 281

  
261
    return false;
282
    return RECORD_NOT_NEW;
262 283
    }
284

  
263 285
///////////////////////////////////////////////////////////////////////////////////////////////////
264 286

  
265 287
  public synchronized long getRecord(int object, int level)
......
355 377
    editor.putInt("scores_numRuns" , mNumRuns );
356 378
    editor.putInt("scores_deviceid", mDeviceID);
357 379
    editor.putInt("scores_review"  , mNumWins );
380
    editor.putInt("scores_review"  , mNumWins );   // legacy name
381
    editor.putInt("scores_numStars", mNumStars );
358 382
    }
359 383

  
360 384
///////////////////////////////////////////////////////////////////////////////////////////////////
......
425 449
    mNumRuns        = preferences.getInt("scores_numRuns" , 0);
426 450
    mDeviceID       = preferences.getInt("scores_deviceid",-1);
427 451
    mNumWins        = preferences.getInt("scores_review"  , 0);
452
    mNumStars       = preferences.getInt("scores_numStars", 0);
428 453

  
429 454
    if( mDeviceID==-1 ) mDeviceID = privateGetDeviceID();
430 455

  
431 456
    if( thereWasError ) recordDBError(errorStr);
432 457
    }
433 458

  
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

  
461
  public int numberOfSolvedMAXes()
462
    {
463
    int numObjects = RubikObjectList.getNumObjects();
464
    int ret=0, level = RubikScreenPlay.LEVELS_SHOWN;
465

  
466
    for(int obj=0; obj<numObjects; obj++)
467
      {
468
      if( isSolved(obj,level) ) ret++;
469
      }
470

  
471
    return ret;
472
    }
473

  
434 474
///////////////////////////////////////////////////////////////////////////////////////////////////
435 475

  
436 476
  public void recordDBError(String message)

Also available in: Unified diff