Revision b35900ee
Added by Leszek Koltunski about 22 hours ago
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
39 | 39 |
private final int mIconID; |
40 | 40 |
private final String[][] mPatterns; |
41 | 41 |
private final int mPrice; |
42 |
private final int mSolverOrdinal;
|
|
42 |
private final int[] mSolverOrdinals;
|
|
43 | 43 |
private final int mObjectOrdinal; |
44 | 44 |
private final boolean mIsLocal; |
45 | 45 |
private final int mCategory, mYear; |
... | ... | |
81 | 81 |
int patternOrdinal = RubikPatternList.getOrdinal(mObjectIndex); |
82 | 82 |
mPatterns = RubikPatternList.getPatterns(patternOrdinal); |
83 | 83 |
|
84 |
mSolverOrdinal = SolvingList.getSolverOrdinal(mObjectOrdinal);
|
|
84 |
mSolverOrdinals= SolvingList.getSolverOrdinals(mObjectOrdinal);
|
|
85 | 85 |
mExtrasOrdinal = -1; |
86 | 86 |
|
87 | 87 |
mObjectVersion = meta.objectVersion(); |
... | ... | |
110 | 110 |
|
111 | 111 |
mPatterns = null; |
112 | 112 |
mExtrasOrdinal = -1; |
113 |
mSolverOrdinal = -1;
|
|
113 |
mSolverOrdinals= null;
|
|
114 | 114 |
mObjectOrdinal = -1; |
115 | 115 |
mIsLocal = true; |
116 | 116 |
|
... | ... | |
355 | 355 |
|
356 | 356 |
public boolean hasSolver() |
357 | 357 |
{ |
358 |
return mSolverOrdinal>=0;
|
|
358 |
return mSolverOrdinals!=null;
|
|
359 | 359 |
} |
360 | 360 |
|
361 | 361 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
362 | 362 |
|
363 |
public int getSolverOrdinal()
|
|
363 |
public int[] getSolverOrdinals()
|
|
364 | 364 |
{ |
365 |
return mSolverOrdinal; |
|
365 |
return mSolverOrdinals;
|
|
366 | 366 |
} |
367 | 367 |
|
368 | 368 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/solvers/SolvingList.java | ||
---|---|---|
70 | 70 |
|
71 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
72 | 72 |
|
73 |
public static int getSolverOrdinal(int objectOrdinal)
|
|
73 |
public static int[] getSolverOrdinals(int objectOrdinal)
|
|
74 | 74 |
{ |
75 |
int numSolvers = 0; |
|
76 |
|
|
75 | 77 |
for(int o=0; o<NUM_OBJECTS; o++) |
76 |
if( objects[o].mObjectOrdinal==objectOrdinal ) return o;
|
|
78 |
if( objects[o].mObjectOrdinal==objectOrdinal ) numSolvers++;
|
|
77 | 79 |
|
78 |
return -1; |
|
80 |
if( numSolvers>0 ) |
|
81 |
{ |
|
82 |
int[] ret = new int[numSolvers]; |
|
83 |
int index = 0; |
|
84 |
|
|
85 |
for(int o=0; o<NUM_OBJECTS; o++) |
|
86 |
if( objects[o].mObjectOrdinal==objectOrdinal ) ret[index++] = o; |
|
87 |
|
|
88 |
return ret; |
|
89 |
} |
|
90 |
|
|
91 |
return null; |
|
79 | 92 |
} |
80 | 93 |
|
81 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/solverui/ScreenSolver.java | ||
---|---|---|
55 | 55 |
private int mNumColors; |
56 | 56 |
private float mBitmapSize; |
57 | 57 |
private WeakReference<SolverActivity> mWeakAct; |
58 |
private SolvingList mList;
|
|
58 |
private int mObjectOrdinal;
|
|
59 | 59 |
|
60 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 61 |
|
... | ... | |
71 | 71 |
{ |
72 | 72 |
ObjectControl control = act.getControl(); |
73 | 73 |
control.setLock(false); |
74 |
control.solveOnly(); |
|
74 | 75 |
|
75 | 76 |
float width = act.getScreenWidthInPixels(); |
76 | 77 |
float heigh = act.getScreenHeightInPixels(); |
... | ... | |
78 | 79 |
mWeakAct = new WeakReference<>(act); |
79 | 80 |
mSolving = false; |
80 | 81 |
|
81 |
int solverIndex= act.getSolverOrdinal(); |
|
82 |
mList = SolvingList.getSolver(solverIndex); |
|
83 |
int currentObject = mList.getObjectOrdinal(); |
|
84 |
control.solveOnly(); |
|
85 |
generateFaceColors(currentObject); |
|
82 |
mObjectOrdinal = act.getObjectOrdinal(); |
|
83 |
generateFaceColors(mObjectOrdinal); |
|
86 | 84 |
|
87 | 85 |
final float BUTTON_RATIO = 0.75f; |
88 | 86 |
int sizeV = (int)(heigh*MainActivity.RATIO_BAR*BUTTON_RATIO); |
... | ... | |
292 | 290 |
}); |
293 | 291 |
} |
294 | 292 |
|
293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 |
|
|
295 |
private boolean solvePressed(SolverActivity act) |
|
296 |
{ |
|
297 |
int[] solverOrdinals = SolvingList.getSolverOrdinals(mObjectOrdinal); |
|
298 |
|
|
299 |
if( solverOrdinals!=null ) |
|
300 |
{ |
|
301 |
int len = solverOrdinals.length; |
|
302 |
|
|
303 |
if( len==1 ) |
|
304 |
{ |
|
305 |
SolvingList list = SolvingList.getSolver(solverOrdinals[0]); |
|
306 |
TwistyObject object = act.getObject(); |
|
307 |
SolvingThread solver = new SolvingThread( act.getInterface(), act.getResources(), object, list ); |
|
308 |
solver.start(); |
|
309 |
return true; |
|
310 |
} |
|
311 |
else |
|
312 |
{ |
|
313 |
// TODO |
|
314 |
return false; |
|
315 |
} |
|
316 |
} |
|
317 |
else // no solvers found - impossible! |
|
318 |
{ |
|
319 |
android.util.Log.e("D", "no solvers found for object "+mObjectOrdinal); |
|
320 |
return false; |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
295 | 324 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
296 | 325 |
|
297 | 326 |
private void setupSolveButton(final SolverActivity act) |
... | ... | |
304 | 333 |
@Override |
305 | 334 |
public void onClick(View v) |
306 | 335 |
{ |
307 |
if( !mSolving ) |
|
308 |
{ |
|
309 |
mSolving = true; |
|
310 |
TwistyObject object = act.getObject(); |
|
311 |
SolvingThread solver = new SolvingThread( act.getInterface(), act.getResources(), object, mList ); |
|
312 |
solver.start(); |
|
313 |
} |
|
336 |
if( !mSolving && solvePressed(act) ) mSolving = true; |
|
314 | 337 |
} |
315 | 338 |
}); |
316 | 339 |
} |
src/main/java/org/distorted/solverui/SolverActivity.java | ||
---|---|---|
29 | 29 |
import org.distorted.objects.RubikObject; |
30 | 30 |
import org.distorted.objects.RubikObjectList; |
31 | 31 |
import org.distorted.os.OSInterface; |
32 |
import org.distorted.solvers.SolvingList; |
|
33 | 32 |
|
34 | 33 |
import java.io.InputStream; |
35 | 34 |
|
... | ... | |
46 | 45 |
private static final int ACTIVITY_NUMBER = 4; |
47 | 46 |
private static final float RATIO_INSET= 0.09f; |
48 | 47 |
|
49 |
private int mSolverOrdinal; |
|
50 | 48 |
private int mObjectOrdinal; |
51 | 49 |
private boolean mDisplayMessageDialog; |
52 | 50 |
|
... | ... | |
61 | 59 |
|
62 | 60 |
Bundle b = getIntent().getExtras(); |
63 | 61 |
mObjectOrdinal = b!=null ? b.getInt("obj") : 0; |
64 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal); |
|
65 |
mSolverOrdinal = object==null ? -1 : object.getSolverOrdinal(); |
|
66 | 62 |
mDisplayMessageDialog = true; |
67 | 63 |
|
68 | 64 |
computeScreenDimensions(); |
... | ... | |
211 | 207 |
return view.getObjectControl(); |
212 | 208 |
} |
213 | 209 |
|
214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
215 |
|
|
216 |
public int getSolverOrdinal() |
|
217 |
{ |
|
218 |
return mSolverOrdinal; |
|
219 |
} |
|
220 |
|
|
221 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
222 | 211 |
|
223 | 212 |
public int getObjectOrdinal() |
Also available in: Unified diff
Beginning of support for more than one solver per object.