Revision a31d25de
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
138 | 138 |
|
139 | 139 |
///////////////////////////////////////////////////////////// |
140 | 140 |
|
141 |
String getMoves(int pattern)
|
|
141 |
int[][] getMoves(int pattern)
|
|
142 | 142 |
{ |
143 | 143 |
if( pattern>=0 && pattern<numPatterns ) |
144 | 144 |
{ |
... | ... | |
146 | 146 |
if( p!=null ) return p.getMoves(); |
147 | 147 |
} |
148 | 148 |
|
149 |
return "";
|
|
149 |
return null;
|
|
150 | 150 |
} |
151 | 151 |
} |
152 | 152 |
|
... | ... | |
155 | 155 |
private static class Pattern implements RubikPostRender.ActionFinishedListener |
156 | 156 |
{ |
157 | 157 |
private String name; |
158 |
private String moves;
|
|
158 |
private int[][] moves;
|
|
159 | 159 |
private int curMove; |
160 | 160 |
private int numMove; |
161 | 161 |
|
... | ... | |
167 | 167 |
Pattern(String n, String m) |
168 | 168 |
{ |
169 | 169 |
name=n; |
170 |
moves=m; |
|
171 |
numMove = moves.length()/4; |
|
170 |
moves= movesParser(m); |
|
172 | 171 |
curMove=numMove; |
173 |
|
|
174 | 172 |
mCanRotate = true; |
175 | 173 |
} |
176 | 174 |
|
175 |
///////////////////////////////////////////////////////////// |
|
176 |
|
|
177 |
private int[][] movesParser(String moves) |
|
178 |
{ |
|
179 |
numMove = moves.length()/4; |
|
180 |
|
|
181 |
int digit0, digit1, digit2; |
|
182 |
int[][] result = new int[numMove][3]; |
|
183 |
|
|
184 |
for(int i=0; i<numMove; i++) |
|
185 |
{ |
|
186 |
digit0 = moves.charAt(4*i+1)-'0'; |
|
187 |
digit1 = moves.charAt(4*i+2)-'0'; |
|
188 |
digit2 = moves.charAt(4*i+3)-'0'; |
|
189 |
|
|
190 |
result[i][0] = (10*digit0+digit1)/32; |
|
191 |
result[i][1] = (10*digit0+digit1)%32; |
|
192 |
result[i][2] = 2-digit2; |
|
193 |
} |
|
194 |
|
|
195 |
return result; |
|
196 |
} |
|
197 |
|
|
177 | 198 |
///////////////////////////////////////////////////////////// |
178 | 199 |
|
179 | 200 |
String getName() |
... | ... | |
205 | 226 |
if( curMove>numMove ) |
206 | 227 |
{ |
207 | 228 |
curMove= 0; |
208 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
229 |
object.initializeObject(null);
|
|
209 | 230 |
} |
210 | 231 |
else |
211 | 232 |
{ |
... | ... | |
214 | 235 |
mCanRotate = false; |
215 | 236 |
mObject = object; |
216 | 237 |
|
217 |
String move = moves.substring(4*curMove-4,4*curMove); |
|
218 |
int a1=move.charAt(1)-'0'; |
|
219 |
int a2=move.charAt(2)-'0'; |
|
220 |
int a3=move.charAt(3)-'0'; |
|
221 |
|
|
222 |
int axis = (10*a1+a2)/32; |
|
223 |
int rowBitmap = (10*a1+a2)%32; |
|
224 |
int angle = (2-a3)*(360/object.getBasicAngle()); |
|
225 |
int numRot = Math.abs(2-a3); |
|
238 |
int axis =moves[curMove-1][0]; |
|
239 |
int rowBitmap=moves[curMove-1][1]; |
|
240 |
int bareAngle=moves[curMove-1][2]; |
|
241 |
int angle = bareAngle*(360/object.getBasicAngle()); |
|
242 |
int numRot = Math.abs(bareAngle); |
|
226 | 243 |
|
227 | 244 |
post.addRotation(this, axis, rowBitmap, angle, numRot*DURATION_MILLIS); |
228 | 245 |
} |
... | ... | |
245 | 262 |
if( curMove<0 ) |
246 | 263 |
{ |
247 | 264 |
curMove=numMove; |
248 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
265 |
object.initializeObject(moves); |
|
249 | 266 |
} |
250 | 267 |
else |
251 | 268 |
{ |
... | ... | |
254 | 271 |
mCanRotate = false; |
255 | 272 |
mObject = object; |
256 | 273 |
|
257 |
String move = moves.substring(4*curMove,4*curMove+4); |
|
258 |
int a1=move.charAt(1)-'0'; |
|
259 |
int a2=move.charAt(2)-'0'; |
|
260 |
int a3=move.charAt(3)-'0'; |
|
261 |
|
|
262 |
int axis = (10*a1+a2)/32; |
|
263 |
int rowBitmap = (10*a1+a2)%32; |
|
264 |
int angle = (2-a3)*(360/object.getBasicAngle()); |
|
265 |
int numRot = Math.abs(2-a3); |
|
274 |
int axis =moves[curMove][0]; |
|
275 |
int rowBitmap=moves[curMove][1]; |
|
276 |
int bareAngle=moves[curMove][2]; |
|
277 |
int angle = bareAngle*(360/object.getBasicAngle()); |
|
278 |
int numRot = Math.abs(bareAngle); |
|
266 | 279 |
|
267 | 280 |
post.addRotation(this, axis, rowBitmap, -angle, numRot*DURATION_MILLIS); |
268 | 281 |
} |
... | ... | |
276 | 289 |
|
277 | 290 |
///////////////////////////////////////////////////////////// |
278 | 291 |
|
279 |
String getMoves()
|
|
292 |
int[][] getMoves()
|
|
280 | 293 |
{ |
281 |
return moves.substring(0,4*curMove);
|
|
294 |
return moves; |
|
282 | 295 |
} |
283 | 296 |
|
284 | 297 |
///////////////////////////////////////////////////////////// |
... | ... | |
461 | 474 |
|
462 | 475 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
463 | 476 |
|
464 |
public String getMoves(int size, int cat, int pat)
|
|
477 |
public int[][] getMoves(int size, int cat, int pat)
|
|
465 | 478 |
{ |
466 | 479 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
467 | 480 |
{ |
... | ... | |
469 | 482 |
if( c!=null ) return c.getMoves(pat); |
470 | 483 |
} |
471 | 484 |
|
472 |
return "";
|
|
485 |
return null;
|
|
473 | 486 |
} |
474 | 487 |
} |
Also available in: Unified diff
Major progress with Prretty Patterns.
Two things remain:
1) looks like sometimes making/backing Moves in a Pattern gets stuck. ( Pattern.mCanRotate! )
2) we need to add RubikPatternList!