Revision 0b5e585c
Added by Leszek Koltunski almost 2 years ago
- ID 0b5e585cb8c00a1dd32b0f9da5a2c056eba34550
- Parent fad10885
src/main/java/org/distorted/objects/RubikObjectList.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
import org.distorted.external.RubikFiles; |
19 | 19 |
import org.distorted.main.RubikActivity; |
20 |
import org.distorted.objectlib.json.JsonReader; |
|
20 | 21 |
import org.distorted.objectlib.main.ObjectSignatures; |
21 | 22 |
import org.distorted.objectlib.main.ObjectType; |
22 | 23 |
|
... | ... | |
28 | 29 |
|
29 | 30 |
public class RubikObjectList |
30 | 31 |
{ |
32 |
public static final int NUM_DIFFICULTIES = 5; |
|
31 | 33 |
public static final int DEF_OBJECT= ObjectSignatures.CUBE_3; |
32 | 34 |
private static RubikObjectList mThis; |
33 | 35 |
private static int mNumObjects; |
... | ... | |
39 | 41 |
{ |
40 | 42 |
String shortName; |
41 | 43 |
boolean icon,object,extras; |
42 |
int numScrambles, objectMinor, extrasMinor; |
|
44 |
int numScrambles, difficulty, objectMinor, extrasMinor;
|
|
43 | 45 |
|
44 |
DownloadedObject(String sName, int scrambles, int oMinor, int eMinor, boolean i, boolean o, boolean e) |
|
46 |
DownloadedObject(String sName, int scrambles, int diff, int oMinor, int eMinor, boolean i, boolean o, boolean e)
|
|
45 | 47 |
{ |
46 | 48 |
shortName = sName; |
47 | 49 |
|
48 | 50 |
numScrambles= scrambles; |
51 |
difficulty = diff; |
|
49 | 52 |
objectMinor = oMinor; |
50 | 53 |
extrasMinor = eMinor; |
51 | 54 |
|
... | ... | |
56 | 59 |
} |
57 | 60 |
|
58 | 61 |
private static ArrayList<DownloadedObject> mDownloadedObjects; |
62 |
private static int[][] mDifficultyOrdinals; |
|
59 | 63 |
|
60 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 65 |
|
... | ... | |
130 | 134 |
return true; |
131 | 135 |
} |
132 | 136 |
|
137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
138 |
|
|
139 |
private static void createDifficultyList(int difficulty) |
|
140 |
{ |
|
141 |
int num=0; |
|
142 |
|
|
143 |
for(int i=0; i<mNumObjects; i++) |
|
144 |
{ |
|
145 |
RubikObject object = mObjects.get(i); |
|
146 |
if( object.getDifficulty()==difficulty ) num++; |
|
147 |
} |
|
148 |
|
|
149 |
if( num>0 ) |
|
150 |
{ |
|
151 |
mDifficultyOrdinals[difficulty] = new int[num]; |
|
152 |
num=0; |
|
153 |
|
|
154 |
for(int i=0; i<mNumObjects; i++) |
|
155 |
{ |
|
156 |
RubikObject object = mObjects.get(i); |
|
157 |
if( object.getDifficulty()==difficulty ) |
|
158 |
{ |
|
159 |
mDifficultyOrdinals[difficulty][num] = i; |
|
160 |
num++; |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
private static int figureOutDifficulty(Context context, String objectName) |
|
169 |
{ |
|
170 |
JsonReader reader = JsonReader.getInstance(); |
|
171 |
|
|
172 |
try |
|
173 |
{ |
|
174 |
reader.readNumScramblesAndComplexity(context,objectName); |
|
175 |
return reader.getComplexity(); |
|
176 |
} |
|
177 |
catch(Exception ex) |
|
178 |
{ |
|
179 |
android.util.Log.e("D", "exception "+ex.getMessage()+" trying to read complexity of a puzzle "+objectName); |
|
180 |
return 0; |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
133 | 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
134 | 185 |
// PUBLIC API |
135 | 186 |
|
136 |
public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, int objectMinor, |
|
187 |
public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, int difficulty, int objectMinor,
|
|
137 | 188 |
int extrasMinor, boolean icon, boolean object, boolean extras) |
138 | 189 |
{ |
139 | 190 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "New downloaded object "+shortName+" icon="+icon+" object="+object+" extras="+extras); |
... | ... | |
171 | 222 |
if( !object ) objectMinor=-1; |
172 | 223 |
if( !extras ) extrasMinor=-1; |
173 | 224 |
|
174 |
DownloadedObject obj = new DownloadedObject(shortName,numScrambles,objectMinor,extrasMinor,icon,object,extras); |
|
225 |
DownloadedObject obj = new DownloadedObject(shortName,numScrambles,difficulty,objectMinor,extrasMinor,icon,object,extras);
|
|
175 | 226 |
if ( internalAddDownloadedObject(obj) ) |
176 | 227 |
{ |
177 | 228 |
if( SHOW_DOWNLOADED_DEBUG ) android.util.Log.e("D", "Adding new downloaded object "+shortName+" icon="+obj.icon+" object="+obj.object+" extras="+obj.extras); |
... | ... | |
234 | 285 |
downloadedObjects.append(object.object ? "1":"0"); |
235 | 286 |
downloadedObjects.append(' '); |
236 | 287 |
downloadedObjects.append(object.extras ? "1":"0"); |
288 |
downloadedObjects.append(' '); |
|
289 |
downloadedObjects.append(object.difficulty); |
|
237 | 290 |
} |
238 | 291 |
|
239 | 292 |
String objects = downloadedObjects.toString(); |
... | ... | |
280 | 333 |
{ |
281 | 334 |
String[] parts = dObj.split(" "); |
282 | 335 |
|
283 |
if( parts.length==7 ) |
|
336 |
if( parts.length==7 || parts.length==8 )
|
|
284 | 337 |
{ |
285 | 338 |
String name = parts[0]; |
286 | 339 |
String scra = parts[1]; |
... | ... | |
290 | 343 |
String obje = parts[5]; |
291 | 344 |
String extr = parts[6]; |
292 | 345 |
|
346 |
int difficulty= parts.length==7 ? figureOutDifficulty(context,name) : Integer.parseInt(parts[7]); |
|
293 | 347 |
int scrambles = Integer.parseInt(scra); |
294 | 348 |
int oMinor = Integer.parseInt(objM); |
295 | 349 |
int eMinor = Integer.parseInt(extM); |
... | ... | |
298 | 352 |
boolean bObje = obje.equals("1"); |
299 | 353 |
boolean bExtr = extr.equals("1"); |
300 | 354 |
|
301 |
addDownloadedObject(context,name,scrambles,oMinor,eMinor,bIcon,bObje,bExtr); |
|
355 |
addDownloadedObject(context,name,scrambles,difficulty,oMinor,eMinor,bIcon,bObje,bExtr);
|
|
302 | 356 |
} |
303 | 357 |
} |
304 | 358 |
} |
... | ... | |
465 | 519 |
RubikObject object = getObject(objectOrdinal); |
466 | 520 |
return object!=null ? object.getExtrasMinor() : -1; |
467 | 521 |
} |
522 |
|
|
523 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
524 |
|
|
525 |
public static int[] produceListOfOrdinals(int difficulty) |
|
526 |
{ |
|
527 |
if( mDifficultyOrdinals==null ) |
|
528 |
{ |
|
529 |
mDifficultyOrdinals = new int[NUM_DIFFICULTIES][]; |
|
530 |
} |
|
531 |
|
|
532 |
if( difficulty>=0 && difficulty<NUM_DIFFICULTIES ) |
|
533 |
{ |
|
534 |
if( mDifficultyOrdinals[difficulty]==null ) createDifficultyList(difficulty); |
|
535 |
} |
|
536 |
|
|
537 |
return mDifficultyOrdinals[difficulty]; |
|
538 |
} |
|
539 |
|
|
468 | 540 |
} |
Also available in: Unified diff
Sort the objects in the object popup by difficulty level.