Project

General

Profile

« Previous | Next » 

Revision 00fcfefa

Added by Leszek Koltunski about 2 years ago

All users who are upgrading from a version <1.11.4, where there was no concept of 'stars', get all their stars.

View differences:

src/main/java/org/distorted/external/RubikScores.java
24 24
import org.distorted.screens.RubikScreenPlay;
25 25

  
26 26
import static org.distorted.objectlib.main.ObjectType.MAX_SCRAMBLES;
27
import static org.distorted.screens.RubikScreenPlay.LEVELS_SHOWN;
27 28

  
28 29
///////////////////////////////////////////////////////////////////////////////////////////////////
29 30
// hold my own scores, and some other statistics.
......
249 250
    return mNumStars;
250 251
    }
251 252

  
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

  
255
  public void correctNumStars()
256
    {
257
    int numObjects = RubikObjectList.getNumObjects();
258

  
259
    for(int obj=0; obj<numObjects; obj++)
260
      {
261
      for(int level=0; level<=RubikScreenPlay.LEVELS_SHOWN; level++)
262
        {
263
        if( isSolved(obj,level) )
264
          {
265
          int numStars = computeNumStars(level+1);
266
          mNumStars += numStars;
267
          }
268
        }
269
      }
270
    }
271

  
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

  
274
  public int computeNumStars(int level)
275
    {
276
    return level>=LEVELS_SHOWN ? 50 : level;
277
    }
278

  
252 279
///////////////////////////////////////////////////////////////////////////////////////////////////
253 280

  
254 281
  public void setName(String newName)
src/main/java/org/distorted/main/RubikActivity.java
390 390
        FirebaseAnalytics analytics = getAnalytics();
391 391
        analytics.setUserId(scores.getName());
392 392
        }
393

  
394
      // all old users upgrading from version <1.11.4, where there was no concept of 'stars',
395
      // get all the stars they have earned
396
      int numStars = scores.getNumStars();
397

  
398
      if( numStars==0 && upgradingFromVersionWithNoStars(oldVersion) )
399
        {
400
        scores.correctNumStars();
401
        }
402
      }
403

  
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

  
406
    private boolean upgradingFromVersionWithNoStars(String version)
407
      {
408
      if( version!=null )
409
        {
410
        try
411
          {
412
          int dot = version.indexOf('.',2);
413

  
414
          if( dot>2 )
415
            {
416
            String middle = version.substring(2,dot);
417
            int middleInt = Integer.parseInt(middle);
418

  
419
            if( middleInt<11 ) return true;
420
            if( middleInt==11 )
421
              {
422
              String end = version.substring(dot+1);
423
              int endInt = Integer.parseInt(end);
424
              return endInt<4;
425
              }
426
            }
427
          }
428
        catch(Exception ignored) {}
429
        }
430

  
431
      return false;
393 432
      }
394 433

  
395 434
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/main/RubikObjectLibInterface.java
450 450
        case RECORD_FIRST  : RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
451 451
                             int level = play.getLevel();
452 452
                             RubikScores scores = RubikScores.getInstance();
453
                             int newStars = RubikObjectList.computeNumStars(level);
453
                             int newStars = scores.computeNumStars(level);
454 454
                             scores.changeNumStars(newStars);
455 455
                             RubikDialogNewRecord d1 = new RubikDialogNewRecord();
456 456
                             d1.setArguments(bundle);
src/main/java/org/distorted/objects/RubikObjectList.java
147 147
    return true;
148 148
    }
149 149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

  
152
  public static int computeNumStars(int level)
153
    {
154
    return level>=LEVELS_SHOWN ? 50 : level;
155
    }
156

  
157 150
///////////////////////////////////////////////////////////////////////////////////////////////////
158 151

  
159 152
  private static void restoreFreedObjects(SharedPreferences preferences)

Also available in: Unified diff