Project

General

Profile

« Previous | Next » 

Revision 5bda8973

Added by Leszek Koltunski over 1 year ago

New way to store records, comopletely independent on the number of scrambles.
Do away with the weird 'getDBLevel' thing.

View differences:

src/main/java/org/distorted/external/RubikScores.java
19 19
import com.google.firebase.crashlytics.FirebaseCrashlytics;
20 20

  
21 21
import org.distorted.main.BuildConfig;
22
import org.distorted.objectlib.main.ObjectType;
22 23
import org.distorted.objects.RubikObject;
23 24
import org.distorted.objects.RubikObjectList;
24 25

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

  
27 28
///////////////////////////////////////////////////////////////////////////////////////////////////
28 29
// hold my own scores, and some other statistics.
29 30

  
30 31
public class RubikScores
31 32
  {
33
  public static final int MAX_RECORD = 10;
32 34
  public static final int MULT = 1000000;
33 35
  public static final long NO_RECORD = Long.MAX_VALUE;
34 36
  private static RubikScores mThis;
......
324 326
    int numObjects = RubikObjectList.getNumObjects();
325 327
    StringBuilder builder = new StringBuilder();
326 328

  
327
    for(int level=0; level<MAX_LEVEL; level++)
329
    for(int level=0; level<=MAX_RECORD; level++)
328 330
      {
329 331
      builder.setLength(0);
330 332

  
......
361 363
  public synchronized void restorePreferences(SharedPreferences preferences)
362 364
    {
363 365
    String recordStr, subStr, nameStr, timeStr, submStr, errorStr="";
364
    int start, end, equals, comma, object, subm;
366
    int start, end, equals, comma, ordinal, subm;
365 367
    long time;
366 368
    boolean thereWasError = false;
367 369
    int numObjects = RubikObjectList.getNumObjects();
368 370

  
369
    for(int level=0; level<MAX_LEVEL; level++)
371
    for(int level=0; level<=MAX_SCRAMBLES; level++)
370 372
      {
373
      recordStr = preferences.getString("scores_record"+level, null);
374
      if( recordStr==null ) continue;
371 375
      start = end = 0;
372
      recordStr = preferences.getString("scores_record"+level, "");
373 376

  
374 377
      while( end!=-1 )
375 378
        {
......
389 392
          timeStr = subStr.substring(equals+1,comma);
390 393
          submStr = subStr.substring(comma+1);
391 394

  
392
          object = RubikObjectList.getOrdinal(nameStr);
395
          ordinal = RubikObjectList.getOrdinal(nameStr);
393 396

  
394
          if( object>=0 && object<numObjects )
397
          if( ordinal>=0 && ordinal<numObjects )
395 398
            {
396 399
            time = Long.parseLong(timeStr);
397 400
            subm = Integer.parseInt(submStr);
398 401

  
399 402
            if( subm>=0 && subm<=1 )
400 403
              {
404
              int staticNumScrambles = ObjectType.getStaticNumScrambles(ordinal);
405

  
406
              if( level==MAX_RECORD )
407
                {
408
                android.util.Log.e("D", "object: "+nameStr+" level="+level+" RECORD DETECTED!");
409
                }
410

  
411
              if( level>=staticNumScrambles )
412
                {
413
                android.util.Log.e("D", "object: "+nameStr+" level="+level+" RECORD DETECTED!");
414
                level = MAX_RECORD;
415
                }
416

  
401 417
              MapValue value = new MapValue(time,subm);
402
              int key = mapKey(object,level);
418
              int key = mapKey(ordinal,level);
403 419
              mMap.put(key,value);
404 420
              }
405 421
            else
......
410 426
            }
411 427
          else
412 428
            {
413
            errorStr += ("error2: object="+object+" obj: "+nameStr+"\n");
429
            errorStr += ("error2: object="+ordinal+" obj: "+nameStr+"\n");
414 430
            thereWasError = true;
415 431
            }
416 432
          }

Also available in: Unified diff