Project

General

Profile

« Previous | Next » 

Revision 1d581993

Added by Leszek Koltunski about 2 years ago

Introduce ObjectSignature that can incorporate 192-bit signatures (for 5x5x5 bandaged cubes).
ObjectScrambler does not fully work yet.

View differences:

src/main/java/org/distorted/objectlib/json/JsonReader.java
31 31
import android.content.Context;
32 32

  
33 33
import org.distorted.objectlib.helpers.ObjectFaceShape;
34
import org.distorted.objectlib.helpers.ObjectSignature;
34 35
import org.json.JSONArray;
35 36
import org.json.JSONException;
36 37
import org.json.JSONObject;
......
78 79
  private boolean mResetMaps;
79 80
  private String mTutorialObject;
80 81
  private String[][] mTutorials;
81
  private long mSignature;
82
  private ObjectSignature mSignature;
82 83

  
83 84
  private static JsonReader mThis;
84 85

  
......
98 99

  
99 100
///////////////////////////////////////////////////////////////////////////////////////////////////
100 101

  
101
  private void parseMetadata(JSONObject object) throws JSONException
102
  private void parseMetadata1(JSONObject object) throws JSONException
102 103
    {
103 104
    mLongName        = object.getString("longname");
104 105
    mShortName       = object.getString("shortname");
......
112 113

  
113 114
    try
114 115
      {
115
      mSignature = object.getLong("signature");
116
      long signature = object.getLong("signature");
117
      mSignature = new ObjectSignature(signature);
116 118
      }
117 119
    catch(JSONException ex)
118 120
      {
119 121
      // objects older than Feb 2022 do not have the 'signature' field. They all use the ObjectType.ordinal
120 122
      // as their signature.
121
      mSignature = ObjectType.getOrdinal(mShortName);
123
      long signature = ObjectType.getOrdinal(mShortName);
124
      mSignature = new ObjectSignature(signature);
125
      }
126
    }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
  private void parseMetadata2(JSONObject object) throws JSONException
131
    {
132
    mLongName        = object.getString("longname");
133
    mShortName       = object.getString("shortname");
134
    mInventor        = object.getString("inventor");
135
    mYearOfInvention = object.getInt("year");
136
    mComplexity      = object.getInt("complexity");
137
    mSize            = (float)object.getDouble("size");
138
    mNumScrambles    = object.getInt("scrambles");
139
    mResetMaps       = object.getBoolean("resetmaps");
140
    mNumFaces        = object.getInt("num_faces");
141

  
142
    try
143
      {
144
      long signature1 = object.getLong("signature1");
145
      long signature2 = object.getLong("signature2");
146
      long signature3 = object.getLong("signature3");
147
      mSignature = new ObjectSignature(signature1,signature2,signature3);
148
      }
149
    catch(JSONException ex)
150
      {
151
      long signature = object.getLong("signature");
152
      mSignature = new ObjectSignature(signature);
122 153
      }
123 154
    }
124 155

  
......
554 585
  private void parseVersion1(JSONObject object) throws JSONException
555 586
    {
556 587
    JSONObject metadata    = object.getJSONObject("metadata");
557
    parseMetadata(metadata);
588
    parseMetadata1(metadata);
558 589
    JSONObject mesh        = object.getJSONObject("mesh");
559 590
    parseMesh(mesh);
560 591
    JSONArray axis         = object.getJSONArray("axis");
......
576 607
  private void parseVersion2(JSONObject object) throws JSONException
577 608
    {
578 609
    JSONObject metadata    = object.getJSONObject("metadata");
579
    parseMetadata(metadata);
610
    parseMetadata2(metadata);
580 611
    JSONObject mesh        = object.getJSONObject("mesh");
581 612
    parseMesh(mesh);
582 613
    JSONArray axis         = object.getJSONArray("axis");
......
615 646

  
616 647
///////////////////////////////////////////////////////////////////////////////////////////////////
617 648

  
618
  private void parseVersion1or2Metadata(JSONObject object) throws JSONException
649
  private void parseVersion1Metadata(JSONObject object) throws JSONException
650
    {
651
    JSONObject metadata = object.getJSONObject("metadata");
652
    parseMetadata1(metadata);
653
    }
654

  
655
///////////////////////////////////////////////////////////////////////////////////////////////////
656

  
657
  private void parseVersion2Metadata(JSONObject object) throws JSONException
619 658
    {
620 659
    JSONObject metadata = object.getJSONObject("metadata");
621
    parseMetadata(metadata);
660
    parseMetadata2(metadata);
622 661
    }
623 662

  
624 663
///////////////////////////////////////////////////////////////////////////////////////////////////
......
678 717
      JSONObject object = new JSONObject(contents.toString());
679 718
      int major = object.getInt("major");
680 719

  
681
      if( major==1 || major==2 )
720
      if( major==1 )
721
        {
722
        parseVersion1Metadata(object);
723
        }
724
      else if( major==2 )
682 725
        {
683
        parseVersion1or2Metadata(object);
726
        parseVersion2Metadata(object);
684 727
        }
685 728
      else
686 729
        {
......
951 994

  
952 995
///////////////////////////////////////////////////////////////////////////////////////////////////
953 996

  
954
  public long getSignature()
997
  public ObjectSignature getSignature()
955 998
    {
956 999
    return mSignature;
957 1000
    }

Also available in: Unified diff