Project

General

Profile

« Previous | Next » 

Revision 5bda8973

Added by Leszek Koltunski over 2 years 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/dialogs/RubikDialogScoresPagerAdapter.java
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
42 42

  
43
  private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
43
  private void prepareView()
44 44
    {
45
    if( level>RubikScreenPlay.LEVELS_SHOWN ) level=RubikScreenPlay.LEVELS_SHOWN;
45
    mAct.runOnUiThread(new Runnable()
46
      {
47
      @Override
48
      public void run()
49
        {
50
        for(int i=0; i<mNumTabs; i++)
51
          {
52
          mViews[i].prepareView(mAct);
53
          }
54
        }
55
      });
56
    try
57
      {
58
      Thread.sleep(150);
59
      }
60
    catch( InterruptedException ignored)
61
      {
46 62

  
63
      }
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
69
    {
47 70
    String title = level==RubikScreenPlay.LEVELS_SHOWN ?
48 71
                   mAct.getString(R.string.levelM) :
49 72
                   mAct.getString(R.string.lv_placeholder,level+1);
......
71 94

  
72 95
///////////////////////////////////////////////////////////////////////////////////////////////////
73 96

  
74
  private void getNext(int currentTab, int[] toDoTab, int[] lastTab)
97
  private void getNext(int currentTab, int[] toDoTab)
75 98
    {
76
    int MAX = RubikScreenPlay.LEVELS_SHOWN+1;
99
    int MAX = RubikScreenPlay.LEVELS_SHOWN;
77 100

  
78
    if( toDoTab[currentTab]<MAX )
101
    if( toDoTab[currentTab]<=MAX )
79 102
      {
80 103
      mToDoTab = currentTab;
81
      mToDoLvl = toDoTab[currentTab]<MAX-1 ? toDoTab[currentTab] : lastTab[currentTab]-1;
104
      mToDoLvl = toDoTab[currentTab];
82 105
      toDoTab[currentTab]++;
83 106
      }
84 107
    else
85 108
      {
86 109
      for(int tab=0; tab<mNumTabs; tab++)
87 110
        {
88
        if( toDoTab[tab]<MAX )
111
        if( toDoTab[tab]<=MAX )
89 112
          {
90 113
          mToDoTab = tab;
91
          mToDoLvl = toDoTab[tab]<MAX-1 ? toDoTab[tab] : lastTab[tab]-1;
114
          mToDoLvl = toDoTab[tab];
92 115
          toDoTab[tab]++;
93 116
          break;
94 117
          }
......
101 124
  public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
102 125
    {
103 126
    prepareView();
104

  
105 127
    int toDo=0;
106 128
    int[] toDoTab = new int[mNumTabs];
107
    int[] lastTab = new int[mNumTabs];
108 129

  
109 130
    for(int i=0; i<mNumTabs; i++)
110 131
      {
111
      lastTab[i]= RubikObjectList.getDBLevel(i);
112 132
      toDoTab[i]= 0;
113 133
      toDo += (RubikScreenPlay.LEVELS_SHOWN+1);
114 134
      }
......
116 136
    while( toDo>0 )
117 137
      {
118 138
      toDo--;
119
      getNext(mViewPager.getCurrentItem(), toDoTab, lastTab);
139
      getNext(mViewPager.getCurrentItem(), toDoTab);
120 140
      addSection( mToDoTab, mToDoLvl, mViews[mToDoTab], country[mToDoTab][mToDoLvl], name[mToDoTab][mToDoLvl], time[mToDoTab][mToDoLvl]);
121 141
      }
122 142
    }
......
165 185
      }
166 186
    }
167 187

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

  
170
  private void prepareView()
171
    {
172
    mAct.runOnUiThread(new Runnable()
173
      {
174
      @Override
175
      public void run()
176
        {
177
        for(int i=0; i<mNumTabs; i++)
178
          {
179
          mViews[i].prepareView(mAct);
180
          }
181
        }
182
      });
183
    try
184
      {
185
      Thread.sleep(150);
186
      }
187
    catch( InterruptedException ignored)
188
      {
189

  
190
      }
191
    }
192

  
193 188
///////////////////////////////////////////////////////////////////////////////////////////////////
194 189

  
195 190
  RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting, RubikDialogScores diag)
src/main/java/org/distorted/external/RubikNetwork.java
30 30
import org.distorted.objectlib.json.JsonWriter;
31 31
import org.distorted.objects.RubikObjectList;
32 32

  
33
import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
34 33
import static org.distorted.main.RubikActivity.SHOW_DOWNLOADED_DEBUG;
34
import static org.distorted.screens.RubikScreenPlay.LEVELS_SHOWN;
35 35

  
36 36
///////////////////////////////////////////////////////////////////////////////////////////////////
37 37

  
......
128 128
    {
129 129
    int newNum = RubikObjectList.getNumObjects();
130 130

  
131
    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][MAX_LEVEL][MAX_PLACES];
132
    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][MAX_LEVEL][MAX_PLACES];
133
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][MAX_LEVEL][MAX_PLACES];
134
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][MAX_LEVEL];
131
    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][LEVELS_SHOWN+1][MAX_PLACES];
132
    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][LEVELS_SHOWN+1][MAX_PLACES];
133
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][LEVELS_SHOWN+1][MAX_PLACES];
134
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][LEVELS_SHOWN+1];
135 135

  
136 136
    if( mUpdates==null ) mUpdates = new RubikUpdates();
137 137

  
......
185 185
      }
186 186

  
187 187
    for(int i=0; i<mNumObjects; i++)
188
      for(int j=0; j<MAX_LEVEL; j++)
188
      for(int j=0; j<=LEVELS_SHOWN; j++)
189 189
        {
190 190
        mPlaces[i][j] = 0;
191 191
        }
......
234 234

  
235 235
        if( country.equals("do") ) country = "dm"; // see RubikScores.setCountry()
236 236

  
237
        if(level>=0 && level<MAX_LEVEL)
237
        if( level>LEVELS_SHOWN ) level = LEVELS_SHOWN;
238

  
239
        if(level>=0)
238 240
          {
239 241
          int p = mPlaces[object][level];
240 242
          mPlaces[object][level]++;
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
          }
src/main/java/org/distorted/objects/RubikObjectList.java
29 29
public class RubikObjectList
30 30
{
31 31
  public static final int DEF_OBJECT= ObjectSignatures.CUBE_3;
32
  public static int MAX_LEVEL;
33

  
34 32
  private static RubikObjectList mThis;
35 33
  private static int mNumObjects;
36 34
  private static int mNumExtras;
......
59 57

  
60 58
  private static ArrayList<DownloadedObject> mDownloadedObjects;
61 59

  
62
  static
63
    {
64
    int max = Integer.MIN_VALUE;
65

  
66
    for (int i=0; i<NUM_OBJECTS; i++)
67
      {
68
      int cur = getDBLevel(i);
69
      if( cur>max ) max = cur;
70
      }
71

  
72
    MAX_LEVEL = max;
73
    }
74

  
75 60
///////////////////////////////////////////////////////////////////////////////////////////////////
76 61

  
77 62
  private RubikObjectList()
......
147 132

  
148 133
///////////////////////////////////////////////////////////////////////////////////////////////////
149 134
// PUBLIC API
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
// historically older versions of the app had lower 'maxScrambles' in case of several objects and
152
// those got remembered in the server-side DB already, so we need to keep using them. This function
153
// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have
154
// those two values the same.
155
//
156
// all of those need to be > RubikStatePlay.LEVELS_SHOWN.
157

  
158
  public static int getDBLevel(int ordinal)
159
    {
160
    if( ordinal== ObjectSignatures.CUBE_3 ) return 16;
161
    if( ordinal== ObjectSignatures.CUBE_4 ) return 20;
162
    if( ordinal== ObjectSignatures.CUBE_5 ) return 24;
163
    if( ordinal== ObjectSignatures.BAN2_3 ) return 16;
164
    if( ordinal== ObjectSignatures.BAN4_3 ) return 16;
165
    if( ordinal== ObjectSignatures.PYRA_4 ) return 15;
166
    if( ordinal== ObjectSignatures.PYRA_5 ) return 20;
167
    if( ordinal== ObjectSignatures.MEGA_5 ) return 35;
168
    if( ordinal== ObjectSignatures.DIAM_2 ) return 10;
169
    if( ordinal== ObjectSignatures.DIAM_3 ) return 18;
170
    if( ordinal== ObjectSignatures.REDI_3 ) return 14;
171
    if( ordinal== ObjectSignatures.HELI_3 ) return 18;
172
    if( ordinal== ObjectSignatures.SKEW_3 ) return 17;
173
    if( ordinal== ObjectSignatures.REX_3  ) return 16;
174
    if( ordinal== ObjectSignatures.MIRR_3 ) return 16;
175
    if( ordinal== ObjectSignatures.IVY_2  ) return  9;
176
    if( ordinal== ObjectSignatures.DIN4_3 ) return  9;
177

  
178
    // in 1.9.6 & 1.9.7 there is a bug with downloadable objects (in this very function!):
179
    // All of those have DBLevel equal to CUBE_3's DBlevel (in 1.9.7!), i.e. 17.
180
    // This will be a problem when we release a new version of the app which has some of the
181
    // previously downloadable objects built-in. Thus: in case of those, we need to keep using
182
    // 17.
183

  
184
    if( ObjectType.wasDownloadableButNowIsBuiltIn(ordinal) )
185
      {
186
      return 17;
187
      }
188

  
189
    return ObjectType.getObject(ordinal).getNumScramble();
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193 135

  
194 136
  public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, int objectMinor,
195 137
                                         int extrasMinor, boolean icon, boolean object, boolean extras)

Also available in: Unified diff