Project

General

Profile

« Previous | Next » 

Revision c86f9f1f

Added by Leszek Koltunski over 4 years ago

Make the records independent of arrangement of Objects and their sizes in RubikObjectList.

View differences:

src/main/java/org/distorted/object/RubikObjectList.java
120 120
    return mNumAll;
121 121
    }
122 122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  public static int getOrdinal(String name)
126
    {
127
    for(int i=0; i<NUM_OBJECTS; i++)
128
      {
129
      if(objects[i].name().equals(name)) return i;
130
      }
131

  
132
    return -1;
133
    }
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

  
137
  public static int getSize(int ordinal, int size)
138
    {
139
    int[] sizes = objects[ordinal].getSizes();
140
    int len = sizes.length;
141

  
142
    for(int i=0; i<len; i++)
143
      {
144
      if( sizes[i]==size ) return i;
145
      }
146

  
147
    return -1;
148
    }
149

  
123 150
///////////////////////////////////////////////////////////////////////////////////////////////////
124 151

  
125 152
  RubikObjectList(int[] sizes, int[] iconIDs, RubikObjectMovement movement)
src/main/java/org/distorted/uistate/RubikStateSolving.java
118 118

  
119 119
  public void savePreferences(SharedPreferences.Editor editor)
120 120
    {
121
    for(int i=0; i<NUM_OBJECTS; i++)
122
      for(int j=0; j<MAX_SIZE; j++)
123
        for(int k=0; k<MAX_SCRAMBLE; k++)
121
    StringBuilder builder = new StringBuilder();
122
    RubikObjectList list;
123
    int[] sizes;
124
    int length;
125

  
126
    for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
127
      {
128
      builder.setLength(0);
129

  
130
      for(int object=0; object<NUM_OBJECTS; object++)
131
        {
132
        list = RubikObjectList.getObject(object);
133
        sizes = list.getSizes();
134
        length = sizes.length;
135

  
136
        for(int size=0; size<length; size++)
124 137
          {
125
          if( mRecords[i][j][k]!=NO_RECORD)
126
            {
127
            editor.putLong("record_"+i+"_"+j+"_"+k, mRecords[i][j][k]);
128
            }
138
          builder.append(list.name());
139
          builder.append("_");
140
          builder.append(sizes[size]);
141
          builder.append("=");
142
          builder.append(mRecords[object][size][scramble]);
143
          builder.append(" ");
129 144
          }
145
        }
146

  
147
      editor.putString("record"+scramble, builder.toString());
148
      }
130 149
    }
131 150

  
132 151
///////////////////////////////////////////////////////////////////////////////////////////////////
133 152

  
134 153
  public void restorePreferences(SharedPreferences preferences)
135 154
    {
136
    for(int i=0; i<NUM_OBJECTS; i++)
137
      for(int j=0; j<MAX_SIZE; j++)
138
        for(int k=0; k<MAX_SCRAMBLE; k++)
155
    String recordStr, subStr, nameStr, sizeStr, timeStr;
156
    int start, end, equals, underscore;
157
    int object, size, time;
158

  
159
    for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
160
      {
161
      start = end = 0;
162
      recordStr = preferences.getString("record"+scramble, "");
163

  
164
      //android.util.Log.e("solving", scramble+" record string: "+recordStr);
165

  
166
      while( end!=-1 )
167
        {
168
        end = recordStr.indexOf(" ", start);
169

  
170
        if( end==-1 ) subStr = recordStr.substring(start);
171
        else          subStr = recordStr.substring(start,end);
172

  
173
        start = end+1;
174

  
175
        underscore = subStr.indexOf("_");
176
        equals = subStr.indexOf("=");
177

  
178
        if( underscore>=0 && equals>=0 )
139 179
          {
140
          mRecords[i][j][k] = preferences.getLong("record_"+i+"_"+j+"_"+k, NO_RECORD );
180
          nameStr = subStr.substring(0,underscore);
181
          sizeStr = subStr.substring(underscore+1, equals);
182
          timeStr = subStr.substring(equals+1);
183

  
184
          object = RubikObjectList.getOrdinal(nameStr);
185
          size   = RubikObjectList.getSize(object,Integer.parseInt(sizeStr));
186
          time   = Integer.parseInt(timeStr);
187

  
188
          //android.util.Log.e("solving", "parsed: nameStr="+nameStr+" sizeStr="+sizeStr+" timeStr="+timeStr);
189
          mRecords[object][size][scramble] = time;
141 190
          }
191
        }
192
      }
142 193
    }
143 194

  
144 195
///////////////////////////////////////////////////////////////////////////////////////////////////
......
191 242
      int scramble= play.getPicker();
192 243
      int maxsize = RubikObjectList.getObject(object).getSizes().length;
193 244

  
194
      if( object>=0 && object< NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
245
      if( object>=0 && object< NUM_OBJECTS && size>=0 && size<maxsize && scramble>=1 && scramble<=MAX_SCRAMBLE )
195 246
        {
196
        if( mRecords[object][size][scramble]> timeTaken )
247
        if( mRecords[object][size][scramble-1]> timeTaken )
197 248
          {
198
          mRecords[object][size][scramble] = timeTaken;
249
          mRecords[object][size][scramble-1] = timeTaken;
199 250
          android.util.Log.e("solv","new record!");
200 251
          }
201 252
        }

Also available in: Unified diff