Project

General

Profile

« Previous | Next » 

Revision 7aae846c

Added by Leszek Koltunski almost 2 years ago

Crazy Planets: introduce cubit type and offset to the JSON; create (shared) mesh and all the JSONs.

View differences:

src/main/java/org/distorted/objectlib/json/JsonReader.java
32 32

  
33 33
import org.distorted.objectlib.helpers.ObjectFaceShape;
34 34
import org.distorted.objectlib.helpers.ObjectSignature;
35
import org.distorted.objectlib.main.Cubit;
35 36
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
36 37
import org.json.JSONArray;
37 38
import org.json.JSONException;
......
81 82
  private String mTutorialObject;
82 83
  private String[][] mTutorials;
83 84
  private ObjectSignature mSignature;
85
  private int[] mCubitType;
86
  private float[][] mCubitRowOffset;
84 87

  
85 88
  private static JsonReader mThis;
86 89

  
......
128 131

  
129 132
///////////////////////////////////////////////////////////////////////////////////////////////////
130 133

  
131
  private void parseMetadata2or3(JSONObject object) throws JSONException
134
  private void parseMetadata2or3or4(JSONObject object) throws JSONException
132 135
    {
133 136
    mLongName        = object.getString("longname");
134 137
    mShortName       = object.getString("shortname");
......
170 173
    mCubitVariant   = new int[numCubits];
171 174
    mPositions      = new float[numCubits][];
172 175
    mCubitFaceColor = new int[numCubits][];
176
    mCubitType      = new int[numCubits];
177
    mCubitRowOffset = new float[numCubits][];
173 178

  
174 179
    for(int i=0; i<numCubits; i++)
175 180
      {
......
192 197
      int numColor = jsonColor.length();
193 198
      mCubitFaceColor[i] = new int[numColor];
194 199
      for(int j=0; j<numColor; j++) mCubitFaceColor[i][j] = jsonColor.getInt(j);
200

  
201
      mCubitType[i] = (int)jsonCubit.optInt("type", Cubit.TYPE_NORMAL);
202
      float xoff = (float)jsonCubit.optDouble("offsetX", 0 );
203
      float yoff = (float)jsonCubit.optDouble("offsetY", 0 );
204
      float zoff = (float)jsonCubit.optDouble("offsetZ", 0 );
205
      mCubitRowOffset[i] = new float[] {xoff,yoff,zoff};
195 206
      }
196 207
    }
197 208

  
......
412 423

  
413 424
///////////////////////////////////////////////////////////////////////////////////////////////////
414 425

  
415
  private void parseAxis2or3(JSONArray object) throws JSONException
426
  private void parseAxis2or3or4(JSONArray object) throws JSONException
416 427
    {
417 428
    int numAxis = object.length();
418 429

  
......
611 622

  
612 623
///////////////////////////////////////////////////////////////////////////////////////////////////
613 624

  
614
  private void parseVersion2or3(JSONObject object) throws JSONException
625
  private void parseVersion2or3or4(JSONObject object) throws JSONException
615 626
    {
616 627
    JSONObject metadata    = object.getJSONObject("metadata");
617
    parseMetadata2or3(metadata);
628
    parseMetadata2or3or4(metadata);
618 629
    JSONObject mesh        = object.getJSONObject("mesh");
619 630
    parseMesh(mesh);
620 631
    JSONArray axis         = object.getJSONArray("axis");
621
    parseAxis2or3(axis);
632
    parseAxis2or3or4(axis);
622 633
    JSONArray quats        = object.getJSONArray("quats");
623 634
    parseQuats(quats);
624 635
    JSONObject scrambling  = object.getJSONObject("scrambling");
......
661 672

  
662 673
///////////////////////////////////////////////////////////////////////////////////////////////////
663 674

  
664
  private void parseVersion2or3Metadata(JSONObject object) throws JSONException
675
  private void parseVersion2or3or4Metadata(JSONObject object) throws JSONException
665 676
    {
666 677
    JSONObject metadata = object.getJSONObject("metadata");
667
    parseMetadata2or3(metadata);
678
    parseMetadata2or3or4(metadata);
668 679
    }
669 680

  
670 681
///////////////////////////////////////////////////////////////////////////////////////////////////
......
688 699
        {
689 700
        parseVersion1(object);
690 701
        }
691
      else if( major==2 || major==3 )
702
      else if( major==2 || major==3 || major==4 )
692 703
        {
693
        parseVersion2or3(object);
704
        parseVersion2or3or4(object);
694 705
        }
695 706
      else
696 707
        {
......
728 739
        {
729 740
        parseVersion1Metadata(object);
730 741
        }
731
      else if( major==2 || major==3 )
742
      else if( major==2 || major==3 || major==4 )
732 743
        {
733
        parseVersion2or3Metadata(object);
744
        parseVersion2or3or4Metadata(object);
734 745
        }
735 746
      else
736 747
        {
......
766 777
      stream.close();
767 778

  
768 779
      JSONObject object = new JSONObject(contents.toString());
769
      int major = object.getInt("major");
770

  
771
      if( major==1 || major==2 || major==3 )
772
        {
773
        JSONObject metadata = object.getJSONObject("metadata");
774
        return metadata.getInt("scrambles");
775
        }
776
      else
777
        {
778
        android.util.Log.e("readNumScrambles", "Unknown version "+major);
779
        }
780
      JSONObject metadata = object.getJSONObject("metadata");
781
      return metadata.getInt("scrambles");
780 782
      }
781 783
    catch(FileNotFoundException ex)
782 784
      {
......
964 966
    return colors.length>face ? colors[face] : -1;
965 967
    }
966 968

  
969
///////////////////////////////////////////////////////////////////////////////////////////////////
970

  
971
  public int[] getCubitTypes()
972
    {
973
    return mCubitType;
974
    }
975

  
976
///////////////////////////////////////////////////////////////////////////////////////////////////
977

  
978
  public float[][] getCubitOffsets()
979
    {
980
    return mCubitRowOffset;
981
    }
982

  
967 983
///////////////////////////////////////////////////////////////////////////////////////////////////
968 984

  
969 985
  public int getCubitFaceFace(int cubit, int face)
src/main/java/org/distorted/objectlib/json/JsonWriter.java
43 43

  
44 44
public class JsonWriter
45 45
{
46
  public static final int VERSION_OBJECT_MAJOR = 3;
46
  public static final int VERSION_OBJECT_MAJOR = 4;
47 47
  public static final int VERSION_OBJECT_MINOR = 0;
48 48
  public static final int VERSION_EXTRAS_MAJOR = 1;
49 49
  public static final int VERSION_EXTRAS_MINOR = 0;
......
71 71
    for(int c=0; c<numCubits; c++)
72 72
      {
73 73
      JSONObject cubit = new JSONObject();
74
      Static4D rotQuat  = object.getCubitQuats(c,numLayers);
75
      int variant       = object.getCubitVariant(c,numLayers);
74
      Static4D rotQuat = object.getCubitQuats(c,numLayers);
75
      int variant      = object.getCubitVariant(c,numLayers);
76
      int type         = object.getCubitType(c);
77
      float[] offset   = object.getCubitOffset(c);
76 78

  
77 79
      JSONArray pos = new JSONArray();
78 80
      int numPos = positions[c].length;
......
83 85
      cubit.put("qz", rotQuat.get2() );
84 86
      cubit.put("qw", rotQuat.get3() );
85 87
      cubit.put("variant", variant );
88
      cubit.put("type", type);
89
      cubit.put("offsetX", offset[0]);
90
      cubit.put("offsetY", offset[1]);
91
      cubit.put("offsetZ", offset[2]);
86 92

  
87 93
      JSONArray colors = new JSONArray();
88 94

  
src/main/java/org/distorted/objectlib/main/Cubit.java
259 259

  
260 260
///////////////////////////////////////////////////////////////////////////////////////////////////
261 261

  
262
  public int getCubitType()
262
  public int getType()
263 263
    {
264 264
    return mCubitType;
265 265
    }
266 266

  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

  
269
  public float[] getOffset()
270
    {
271
    return mRowOffset;
272
    }
273

  
267 274
///////////////////////////////////////////////////////////////////////////////////////////////////
268 275

  
269 276
  public int getRotRow(int axisIndex)
src/main/java/org/distorted/objectlib/main/ObjectSignatures.java
75 75
  public static final int MIXU_3 = ObjectType.MIXU_3.ordinal();
76 76
  public static final int MIXP_3 = ObjectType.MIXP_3.ordinal();
77 77
  public static final int CRA1_3 = ObjectType.CRA1_3.ordinal();
78
  public static final int CRA2_3 = ObjectType.CRA2_3.ordinal();
79
  public static final int CRA3_3 = ObjectType.CRA3_3.ordinal();
80
  public static final int CRA4_3 = ObjectType.CRA4_3.ordinal();
81
  public static final int CRA5_3 = ObjectType.CRA5_3.ordinal();
82
  public static final int CRA6_3 = ObjectType.CRA6_3.ordinal();
83
  public static final int CRA7_3 = ObjectType.CRA7_3.ordinal();
84
  public static final int CRA8_3 = ObjectType.CRA8_3.ordinal();
85
  public static final int CRA9_3 = ObjectType.CRA9_3.ordinal();
78 86
  }
src/main/java/org/distorted/objectlib/main/TwistyJson.java
43 43
    super(jsonStream, meshState, iconMode, quat, move, scale, meshStream);
44 44
    }
45 45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  @Override
49
  public int getCubitRotationType(int cubitIndex)
50
    {
51
    return mReader.getCubitTypes()[cubitIndex];
52
    }
53

  
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

  
56
  @Override
57
  public float[] getCubitRowOffset(int cubitIndex)
58
    {
59
    return mReader.getCubitOffsets()[cubitIndex];
60
    }
61

  
46 62
///////////////////////////////////////////////////////////////////////////////////////////////////
47 63

  
48 64
  @Override
src/main/java/org/distorted/objectlib/main/TwistyObject.java
1134 1134
            index = mCubits[j].postRotateCubit(quat);
1135 1135
            setCubitQuat(j,mCubits[j].computeAssociation(),index);
1136 1136
            }
1137
          else if( mCubits[j].getCubitType()==Cubit.TYPE_FOLLOWER )
1137
          else if( mCubits[j].getType()==Cubit.TYPE_FOLLOWER )
1138 1138
            {
1139 1139
            mCubits[j].adjustRotRowPostRotateADecider();
1140 1140
            setCubitQuat(j,mCubits[j].computeAssociation(),mCubits[j].mQuatIndex);
......
1336 1336
        int index = mCubits[i].postRotateCubit(quat);
1337 1337
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1338 1338
        }
1339
      else if( mCubits[i].getCubitType()==Cubit.TYPE_FOLLOWER )
1339
      else if( mCubits[i].getType()==Cubit.TYPE_FOLLOWER )
1340 1340
        {
1341 1341
        mCubits[i].adjustRotRowPostRotateADecider();
1342 1342
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
......
1811 1811
    return mEffects;
1812 1812
    }
1813 1813

  
1814
///////////////////////////////////////////////////////////////////////////////////////////////////
1815

  
1816
  public int getCubitType(int cubit)
1817
    {
1818
    return mCubits[cubit].getType();
1819
    }
1820

  
1821
///////////////////////////////////////////////////////////////////////////////////////////////////
1822

  
1823
  public float[] getCubitOffset(int cubit)
1824
    {
1825
    return mCubits[cubit].getOffset();
1826
    }
1827

  
1814 1828
///////////////////////////////////////////////////////////////////////////////////////////////////
1815 1829
// PUBLIC API
1816 1830
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff