24 |
24 |
import org.distorted.objectlib.helpers.ObjectStickerOverride;
|
25 |
25 |
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
26 |
26 |
import org.distorted.objectlib.main.Cubit;
|
|
27 |
import org.distorted.objectlib.main.TwistyObject;
|
27 |
28 |
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
|
28 |
29 |
import org.json.JSONArray;
|
29 |
30 |
import org.json.JSONException;
|
... | ... | |
435 |
436 |
|
436 |
437 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
437 |
438 |
|
438 |
|
private void parseScrambling(JSONObject object) throws JSONException
|
|
439 |
private int getAlgorithmIndex(int ax, int layer, int angle)
|
439 |
440 |
{
|
440 |
|
mScrambleType = object.getInt("scrambleType");
|
|
441 |
int numAlgs = mAlgorithms.length;
|
441 |
442 |
|
442 |
|
if( mScrambleType==0 )
|
|
443 |
for(int alg=0; alg<numAlgs; alg++)
|
|
444 |
{
|
|
445 |
int[] algorithm = mAlgorithms[alg];
|
|
446 |
if( algorithm.length>=3 && algorithm[0]==ax && algorithm[1]==layer && algorithm[2]==angle ) return alg;
|
|
447 |
}
|
|
448 |
|
|
449 |
return -1;
|
|
450 |
}
|
|
451 |
|
|
452 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
453 |
|
|
454 |
private int[] produceEdge(int[][] scramblingData)
|
|
455 |
{
|
|
456 |
int index=0, length=0;
|
|
457 |
int numAxis = scramblingData.length;
|
|
458 |
for (int[] scramblingDatum : scramblingData) length += scramblingDatum.length;
|
|
459 |
|
|
460 |
int[] ret = new int[2*length/3];
|
|
461 |
|
|
462 |
for(int ax=0; ax<numAxis; ax++)
|
443 |
463 |
{
|
444 |
|
JSONArray jsonAlgorithms = object.getJSONArray("algorithms");
|
445 |
|
int numAlgs = jsonAlgorithms.length();
|
446 |
|
mAlgorithms = new int[numAlgs][];
|
|
464 |
int[] data = scramblingData[ax];
|
|
465 |
int num = data.length/3;
|
447 |
466 |
|
448 |
|
for(int i=0; i<numAlgs; i++)
|
|
467 |
for(int j=0; j<num; j++)
|
449 |
468 |
{
|
450 |
|
JSONArray jsonAlg = jsonAlgorithms.getJSONArray(i);
|
451 |
|
int numEntries = jsonAlg.length();
|
452 |
|
mAlgorithms[i] = new int[numEntries];
|
453 |
|
for(int j=0; j<numEntries; j++) mAlgorithms[i][j] = jsonAlg.getInt(j);
|
|
469 |
int layer = data[3*j];
|
|
470 |
int angle = data[3*j+1];
|
|
471 |
int state = data[3*j+2];
|
|
472 |
|
|
473 |
ret[2*index ] = getAlgorithmIndex(ax,layer,angle);
|
|
474 |
ret[2*index+1] = state;
|
|
475 |
index++;
|
454 |
476 |
}
|
|
477 |
}
|
455 |
478 |
|
456 |
|
JSONArray jsonEdges = object.getJSONArray("edges");
|
457 |
|
int numEdges = jsonEdges.length();
|
458 |
|
mEdges = new int[numEdges][];
|
|
479 |
return ret;
|
|
480 |
}
|
|
481 |
|
|
482 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
459 |
483 |
|
460 |
|
for(int i=0; i<numEdges; i++)
|
|
484 |
private void parseScrambling6(JSONObject object) throws JSONException
|
|
485 |
{
|
|
486 |
JSONArray jsonStates = object.getJSONArray("scrambleStates");
|
|
487 |
int numStates = jsonStates.length();
|
|
488 |
int[][][] scramblingData = new int[numStates][][];
|
|
489 |
|
|
490 |
for(int i=0; i<numStates; i++)
|
|
491 |
{
|
|
492 |
JSONArray jsonState = jsonStates.getJSONArray(i);
|
|
493 |
int numAxis = jsonState.length();
|
|
494 |
scramblingData[i] = new int[numAxis][];
|
|
495 |
|
|
496 |
for(int j=0; j<numAxis; j++)
|
461 |
497 |
{
|
462 |
|
JSONArray jsonEdge = jsonEdges.getJSONArray(i);
|
463 |
|
int numEntries = jsonEdge.length();
|
464 |
|
mEdges[i] = new int[numEntries];
|
465 |
|
for(int j=0; j<numEntries; j++) mEdges[i][j] = jsonEdge.getInt(j);
|
|
498 |
JSONArray jsonData = jsonState.getJSONArray(j);
|
|
499 |
int numData = jsonData.length();
|
|
500 |
scramblingData[i][j] = new int[numData];
|
|
501 |
for(int k=0; k<numData; k++) scramblingData[i][j][k] = jsonData.getInt(k);
|
466 |
502 |
}
|
467 |
503 |
}
|
|
504 |
|
|
505 |
mAlgorithms = TwistyObject.staticGetAlgorithms(mBasicAngle);
|
|
506 |
mEdges = new int[numStates][];
|
|
507 |
for(int i=0; i<numStates; i++) mEdges[i] = produceEdge(scramblingData[i]);
|
|
508 |
}
|
|
509 |
|
|
510 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
511 |
|
|
512 |
private void parseScrambling7orMore(JSONObject object) throws JSONException
|
|
513 |
{
|
|
514 |
JSONArray jsonAlgorithms = object.getJSONArray("algorithms");
|
|
515 |
int numAlgs = jsonAlgorithms.length();
|
|
516 |
mAlgorithms = new int[numAlgs][];
|
|
517 |
|
|
518 |
for(int i=0; i<numAlgs; i++)
|
|
519 |
{
|
|
520 |
JSONArray jsonAlg = jsonAlgorithms.getJSONArray(i);
|
|
521 |
int numEntries = jsonAlg.length();
|
|
522 |
mAlgorithms[i] = new int[numEntries];
|
|
523 |
for(int j=0; j<numEntries; j++) mAlgorithms[i][j] = jsonAlg.getInt(j);
|
|
524 |
}
|
|
525 |
|
|
526 |
JSONArray jsonEdges = object.getJSONArray("edges");
|
|
527 |
int numEdges = jsonEdges.length();
|
|
528 |
mEdges = new int[numEdges][];
|
|
529 |
|
|
530 |
for(int i=0; i<numEdges; i++)
|
|
531 |
{
|
|
532 |
JSONArray jsonEdge = jsonEdges.getJSONArray(i);
|
|
533 |
int numEntries = jsonEdge.length();
|
|
534 |
mEdges[i] = new int[numEntries];
|
|
535 |
for(int j=0; j<numEntries; j++) mEdges[i][j] = jsonEdge.getInt(j);
|
|
536 |
}
|
|
537 |
}
|
|
538 |
|
|
539 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
540 |
|
|
541 |
private void parseScrambling(JSONObject object, int major) throws JSONException
|
|
542 |
{
|
|
543 |
mScrambleType = object.getInt("scrambleType");
|
|
544 |
|
|
545 |
if( mScrambleType==0 )
|
|
546 |
{
|
|
547 |
if( major==6 ) parseScrambling6(object);
|
|
548 |
else parseScrambling7orMore(object);
|
|
549 |
}
|
468 |
550 |
}
|
469 |
551 |
|
470 |
552 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
554 |
636 |
|
555 |
637 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
556 |
638 |
|
557 |
|
private void parseFile(JSONObject object) throws JSONException
|
|
639 |
private void parseFile(JSONObject object, int major) throws JSONException
|
558 |
640 |
{
|
559 |
641 |
JSONObject metadata = object.getJSONObject("metadata");
|
560 |
642 |
parseMetadata(metadata);
|
... | ... | |
565 |
647 |
JSONArray quats = object.getJSONArray("quats");
|
566 |
648 |
parseQuats(quats);
|
567 |
649 |
JSONObject scrambling = object.getJSONObject("scrambling");
|
568 |
|
parseScrambling(scrambling);
|
|
650 |
parseScrambling(scrambling,major);
|
569 |
651 |
JSONObject touchcontrol= object.getJSONObject("touchcontrol");
|
570 |
652 |
parseTouchcontrol(touchcontrol);
|
571 |
653 |
JSONArray colors = object.getJSONArray("colors");
|
... | ... | |
613 |
695 |
|
614 |
696 |
if( major>=6 )
|
615 |
697 |
{
|
616 |
|
parseFile(object);
|
|
698 |
parseFile(object,major);
|
617 |
699 |
}
|
618 |
700 |
else
|
619 |
701 |
{
|
Make it possible to (fully!) read version 6 JSONs - some users might have Pyraminx Duo v. 6 already downloaded!