1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Distorted is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.objectlib.json;
|
21
|
|
22
|
import java.io.BufferedReader;
|
23
|
import java.io.IOException;
|
24
|
import java.io.InputStream;
|
25
|
import java.io.InputStreamReader;
|
26
|
import java.nio.charset.StandardCharsets;
|
27
|
|
28
|
import org.distorted.objectlib.helpers.ObjectFaceShape;
|
29
|
import org.json.JSONArray;
|
30
|
import org.json.JSONException;
|
31
|
import org.json.JSONObject;
|
32
|
|
33
|
import org.distorted.library.type.Static3D;
|
34
|
import org.distorted.library.type.Static4D;
|
35
|
|
36
|
import org.distorted.objectlib.helpers.ObjectShape;
|
37
|
import org.distorted.objectlib.helpers.ObjectSticker;
|
38
|
import org.distorted.objectlib.helpers.ScrambleState;
|
39
|
import org.distorted.objectlib.main.ObjectType;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
public class JsonReader
|
44
|
{
|
45
|
private ScrambleState[] mStates;
|
46
|
private int[][] mSolvedQuats;
|
47
|
private Static4D[] mQuats;
|
48
|
private int mSolvedFuncIndex;
|
49
|
private int mNumStickerTypes;
|
50
|
private float[][] mCuts;
|
51
|
private boolean[][] mLayerRotatable;
|
52
|
private int mMovementType, mMovementSplit;
|
53
|
private int[][][] mEnabled;
|
54
|
private float[] mDist3D;
|
55
|
private int mNumCubitFaces, mNumFaces, mNumFaceColors;
|
56
|
private float[][] mPositions;
|
57
|
private ObjectShape[] mShapes;
|
58
|
private ObjectFaceShape[] mFaceShapes;
|
59
|
private Static4D[] mCubitQuats;
|
60
|
private int mNumCubitVariants;
|
61
|
private int[] mCubitVariant;
|
62
|
private int[][] mVariantFaceColor, mCubitFaceColor;
|
63
|
private ObjectSticker[] mObjectSticker;
|
64
|
private Static3D[] mAxis;
|
65
|
private int[] mBasicAngle;
|
66
|
private String mLongName, mShortName, mInventor;
|
67
|
private int mYearOfInvention, mComplexity;
|
68
|
private int[] mNumLayers;
|
69
|
private float mSize;
|
70
|
private int mScrambleType, mNumScrambles;
|
71
|
private int[] mColor;
|
72
|
private ObjectType mType;
|
73
|
private boolean mResetMaps;
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
private void parseMetadata(JSONObject object) throws JSONException
|
78
|
{
|
79
|
mLongName = object.getString("longname");
|
80
|
mShortName = object.getString("shortname");
|
81
|
mInventor = object.getString("inventor");
|
82
|
mYearOfInvention = object.getInt("year");
|
83
|
mComplexity = object.getInt("complexity");
|
84
|
mSize = (float)object.getDouble("size");
|
85
|
mSolvedFuncIndex = object.getInt("solved_func");
|
86
|
mNumScrambles = object.getInt("scrambles");
|
87
|
mResetMaps = object.getBoolean("resetmaps");
|
88
|
mNumFaces = object.getInt("num_faces");
|
89
|
|
90
|
int ordinal = ObjectType.getOrdinal(mShortName);
|
91
|
mType = ordinal>=0 ? ObjectType.getObject(ordinal) : null;
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
private void parseCubits(JSONArray object) throws JSONException
|
97
|
{
|
98
|
int numCubits = object.length();
|
99
|
|
100
|
mCubitQuats = new Static4D[numCubits];
|
101
|
mCubitVariant = new int[numCubits];
|
102
|
mPositions = new float[numCubits][];
|
103
|
mCubitFaceColor = new int[numCubits][];
|
104
|
mSolvedQuats = new int[numCubits][];
|
105
|
|
106
|
for(int i=0; i<numCubits; i++)
|
107
|
{
|
108
|
JSONObject jsonCubit = object.getJSONObject(i);
|
109
|
|
110
|
float qx = (float)jsonCubit.getDouble("qx");
|
111
|
float qy = (float)jsonCubit.getDouble("qy");
|
112
|
float qz = (float)jsonCubit.getDouble("qz");
|
113
|
float qw = (float)jsonCubit.getDouble("qw");
|
114
|
|
115
|
mCubitQuats[i] = new Static4D(qx,qy,qz,qw);
|
116
|
mCubitVariant[i] = jsonCubit.getInt("variant");
|
117
|
|
118
|
JSONArray jsonCenter = jsonCubit.getJSONArray("centers");
|
119
|
int numCenter = jsonCenter.length();
|
120
|
mPositions[i] = new float[numCenter];
|
121
|
for(int j=0; j<numCenter; j++) mPositions[i][j] = (float)jsonCenter.getDouble(j);
|
122
|
|
123
|
JSONArray jsonColor = jsonCubit.getJSONArray("colors");
|
124
|
int numColor = jsonColor.length();
|
125
|
mCubitFaceColor[i] = new int[numColor];
|
126
|
for(int j=0; j<numColor; j++) mCubitFaceColor[i][j] = jsonColor.getInt(j);
|
127
|
|
128
|
try
|
129
|
{
|
130
|
JSONArray jsonSolved = jsonCubit.getJSONArray("solvedQuats");
|
131
|
int numSolved = jsonSolved.length();
|
132
|
mSolvedQuats[i] = new int[numSolved];
|
133
|
for(int j=0; j<numSolved; j++) mSolvedQuats[i][j] = jsonSolved.getInt(j);
|
134
|
}
|
135
|
catch( JSONException ex )
|
136
|
{
|
137
|
// ignore
|
138
|
}
|
139
|
}
|
140
|
}
|
141
|
|
142
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143
|
|
144
|
private void parseShapes(JSONArray object) throws JSONException
|
145
|
{
|
146
|
mNumCubitVariants = object.length();
|
147
|
mVariantFaceColor = new int[mNumCubitVariants][];
|
148
|
mShapes = new ObjectShape[mNumCubitVariants];
|
149
|
mFaceShapes = new ObjectFaceShape[mNumCubitVariants];
|
150
|
float[][][] verts = new float[mNumCubitVariants][][];
|
151
|
float[][][] bands = new float[mNumCubitVariants][][];
|
152
|
float[][][] corners = new float[mNumCubitVariants][][];
|
153
|
float[][][] centers = new float[mNumCubitVariants][][];
|
154
|
float[][] convexity = new float[mNumCubitVariants][];
|
155
|
int[][] cornerIndices = new int[mNumCubitVariants][];
|
156
|
int[][] centerIndices = new int[mNumCubitVariants][];
|
157
|
int[][] bandIndices = new int[mNumCubitVariants][];
|
158
|
int[][][] vertIndices = new int[mNumCubitVariants][][];
|
159
|
|
160
|
mNumCubitFaces = -1;
|
161
|
|
162
|
for(int i=0; i<mNumCubitVariants; i++)
|
163
|
{
|
164
|
JSONObject jsonShape = object.getJSONObject(i);
|
165
|
|
166
|
////// vertices /////////////////////////////////////////////////
|
167
|
JSONArray jsonVertices= jsonShape.getJSONArray("vertices");
|
168
|
int numVertices = jsonVertices.length();
|
169
|
verts[i] = new float[numVertices][3];
|
170
|
cornerIndices[i] = new int[numVertices];
|
171
|
centerIndices[i] = new int[numVertices];
|
172
|
|
173
|
for(int j=0; j<numVertices; j++)
|
174
|
{
|
175
|
JSONObject vert = jsonVertices.getJSONObject(j);
|
176
|
verts[i][j][0] = (float)vert.getDouble("x");
|
177
|
verts[i][j][1] = (float)vert.getDouble("y");
|
178
|
verts[i][j][2] = (float)vert.getDouble("z");
|
179
|
cornerIndices[i][j] = vert.getInt("cornerIndex");
|
180
|
centerIndices[i][j] = vert.getInt("centerIndex");
|
181
|
}
|
182
|
|
183
|
////// faces ////////////////////////////////////////////////////
|
184
|
JSONArray jsonFaces= jsonShape.getJSONArray("faces");
|
185
|
int numFaces = jsonFaces.length();
|
186
|
mVariantFaceColor[i] = new int[numFaces];
|
187
|
bandIndices[i] = new int[numFaces];
|
188
|
vertIndices[i] = new int[numFaces][];
|
189
|
|
190
|
if( mNumCubitFaces<numFaces ) mNumCubitFaces=numFaces;
|
191
|
|
192
|
for(int j=0; j<numFaces; j++)
|
193
|
{
|
194
|
JSONObject jsonFace = jsonFaces.getJSONObject(j);
|
195
|
mVariantFaceColor[i][j] = jsonFace.getInt("sticker");
|
196
|
bandIndices[i][j] = jsonFace.getInt("bandIndex");
|
197
|
JSONArray vertices = jsonFace.getJSONArray("vertexIndices");
|
198
|
int numV = vertices.length();
|
199
|
vertIndices[i][j] = new int[numV];
|
200
|
for(int k=0; k<numV; k++) vertIndices[i][j][k] = vertices.getInt(k);
|
201
|
}
|
202
|
|
203
|
////// bands ////////////////////////////////////////////////////
|
204
|
JSONArray jsonBands= jsonShape.getJSONArray("bands");
|
205
|
int numBands = jsonBands.length();
|
206
|
bands[i] = new float[numBands][7];
|
207
|
|
208
|
for(int j=0; j<numBands; j++)
|
209
|
{
|
210
|
JSONObject jsonBand = jsonBands.getJSONObject(j);
|
211
|
|
212
|
bands[i][j][0] = (float)jsonBand.getDouble("height");
|
213
|
bands[i][j][1] = (float)jsonBand.getDouble("angle");
|
214
|
bands[i][j][2] = (float)jsonBand.getDouble("distanceToCenter");
|
215
|
bands[i][j][3] = (float)jsonBand.getDouble("distanceToFlat");
|
216
|
bands[i][j][4] = (float)jsonBand.getDouble("numOfBands");
|
217
|
bands[i][j][5] = (float)jsonBand.getDouble("extraI");
|
218
|
bands[i][j][6] = (float)jsonBand.getDouble("extraJ");
|
219
|
}
|
220
|
|
221
|
////// cornerPush ///////////////////////////////////////////////
|
222
|
JSONArray jsonCornerPush= jsonShape.optJSONArray("cornerPush");
|
223
|
|
224
|
if( jsonCornerPush!=null )
|
225
|
{
|
226
|
int numCornerP = jsonCornerPush.length();
|
227
|
corners[i] = new float[numCornerP][2];
|
228
|
|
229
|
for(int j=0; j<numCornerP; j++)
|
230
|
{
|
231
|
JSONObject jsonC = jsonCornerPush.getJSONObject(j);
|
232
|
corners[i][j][0] = (float)jsonC.getDouble("strength");
|
233
|
corners[i][j][1] = (float)jsonC.getDouble("radius");
|
234
|
}
|
235
|
}
|
236
|
|
237
|
////// centerPush ///////////////////////////////////////////////
|
238
|
JSONArray jsonCenterPush= jsonShape.optJSONArray("centerPush");
|
239
|
|
240
|
if( jsonCenterPush!=null )
|
241
|
{
|
242
|
int numCenterP = jsonCenterPush.length();
|
243
|
centers[i] = new float[numCenterP][3];
|
244
|
|
245
|
for(int j=0; j<numCenterP; j++)
|
246
|
{
|
247
|
JSONObject jsonC = jsonCenterPush.getJSONObject(j);
|
248
|
centers[i][j][0] = (float)jsonC.getDouble("x");
|
249
|
centers[i][j][1] = (float)jsonC.getDouble("y");
|
250
|
centers[i][j][2] = (float)jsonC.getDouble("z");
|
251
|
}
|
252
|
}
|
253
|
|
254
|
////// convexity ///////////////////////////////////////////////
|
255
|
JSONObject jsonConvexity = jsonShape.optJSONObject("convexity");
|
256
|
|
257
|
if( jsonConvexity!=null )
|
258
|
{
|
259
|
convexity[i] = new float[3];
|
260
|
convexity[i][0] = (float)jsonConvexity.getDouble("x");
|
261
|
convexity[i][1] = (float)jsonConvexity.getDouble("y");
|
262
|
convexity[i][2] = (float)jsonConvexity.getDouble("z");
|
263
|
}
|
264
|
}
|
265
|
|
266
|
for(int i=0; i<mNumCubitVariants; i++)
|
267
|
{
|
268
|
mShapes[i] = new ObjectShape(verts[i],vertIndices[i]);
|
269
|
mFaceShapes[i] = new ObjectFaceShape(bands[i],bandIndices[i],corners[i],cornerIndices[i],centers[i],centerIndices[i],convexity[i] );
|
270
|
}
|
271
|
}
|
272
|
|
273
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274
|
|
275
|
private void parseStickers(JSONArray object) throws JSONException
|
276
|
{
|
277
|
mNumStickerTypes = object.length();
|
278
|
mObjectSticker = new ObjectSticker[mNumStickerTypes];
|
279
|
|
280
|
for(int i=0; i<mNumStickerTypes; i++)
|
281
|
{
|
282
|
JSONObject sticker = object.getJSONObject(i);
|
283
|
float stroke = (float)sticker.getDouble("stroke");
|
284
|
JSONArray vertices = sticker.getJSONArray("vertices");
|
285
|
int numVertices = vertices.length();
|
286
|
|
287
|
float[] coords = new float[2*numVertices];
|
288
|
float[] curvatures = new float[numVertices];
|
289
|
float[] radii = new float[numVertices];
|
290
|
|
291
|
for(int j=0; j<numVertices; j++)
|
292
|
{
|
293
|
JSONObject vertex = vertices.getJSONObject(j);
|
294
|
|
295
|
coords[2*j ] = (float)vertex.getDouble("x");
|
296
|
coords[2*j+1] = (float)vertex.getDouble("y");
|
297
|
curvatures[j] = (float)vertex.getDouble("angle");
|
298
|
radii[j] = (float)vertex.getDouble("radius");
|
299
|
}
|
300
|
|
301
|
mObjectSticker[i] = new ObjectSticker(coords,curvatures,radii,stroke);
|
302
|
}
|
303
|
}
|
304
|
|
305
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306
|
|
307
|
private void parseMesh(JSONObject object) throws JSONException
|
308
|
{
|
309
|
JSONArray cubits = object.getJSONArray("cubits");
|
310
|
parseCubits(cubits);
|
311
|
JSONArray shapes = object.getJSONArray("shapes");
|
312
|
parseShapes(shapes);
|
313
|
JSONArray stickers = object.getJSONArray("stickers");
|
314
|
parseStickers(stickers);
|
315
|
}
|
316
|
|
317
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
318
|
|
319
|
private void parseAxis(JSONArray object) throws JSONException
|
320
|
{
|
321
|
int numAxis = object.length();
|
322
|
|
323
|
mBasicAngle = new int[numAxis];
|
324
|
mAxis = new Static3D[numAxis];
|
325
|
mCuts = new float[numAxis][];
|
326
|
mLayerRotatable = new boolean[numAxis][];
|
327
|
mNumLayers = new int[numAxis];
|
328
|
|
329
|
for(int i=0; i<numAxis; i++)
|
330
|
{
|
331
|
JSONObject jsonAx = object.getJSONObject(i);
|
332
|
|
333
|
mBasicAngle[i] = jsonAx.getInt("basicAngle");
|
334
|
|
335
|
float x = (float)jsonAx.getDouble("x");
|
336
|
float y = (float)jsonAx.getDouble("y");
|
337
|
float z = (float)jsonAx.getDouble("z");
|
338
|
|
339
|
mAxis[i] = new Static3D(x,y,z);
|
340
|
|
341
|
JSONArray jsonCuts = jsonAx.getJSONArray("cuts");
|
342
|
int numCuts = jsonCuts.length();
|
343
|
mCuts[i] = new float[numCuts];
|
344
|
for(int j=0; j<numCuts; j++) mCuts[i][j] = (float)jsonCuts.getDouble(j);
|
345
|
|
346
|
JSONArray jsonRota = jsonAx.getJSONArray("rotatable");
|
347
|
int numRota = jsonRota.length();
|
348
|
mLayerRotatable[i] = new boolean[numRota];
|
349
|
for(int j=0; j<numRota; j++) mLayerRotatable[i][j] = jsonRota.getBoolean(j);
|
350
|
|
351
|
mNumLayers[i] = numRota;
|
352
|
}
|
353
|
}
|
354
|
|
355
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
356
|
|
357
|
private void parseQuats(JSONArray object) throws JSONException
|
358
|
{
|
359
|
int numQuats = object.length();
|
360
|
mQuats = new Static4D[numQuats];
|
361
|
|
362
|
for(int i=0; i<numQuats; i++)
|
363
|
{
|
364
|
JSONObject jsonQuat = object.getJSONObject(i);
|
365
|
|
366
|
float x = (float)jsonQuat.getDouble("x");
|
367
|
float y = (float)jsonQuat.getDouble("y");
|
368
|
float z = (float)jsonQuat.getDouble("z");
|
369
|
float w = (float)jsonQuat.getDouble("w");
|
370
|
|
371
|
mQuats[i] = new Static4D(x,y,z,w);
|
372
|
}
|
373
|
}
|
374
|
|
375
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
376
|
|
377
|
private void parseScrambling(JSONObject object) throws JSONException
|
378
|
{
|
379
|
mScrambleType = object.getInt("scrambleType");
|
380
|
|
381
|
if( mScrambleType==0 )
|
382
|
{
|
383
|
JSONArray jsonStates = object.getJSONArray("scrambleStates");
|
384
|
int numStates = jsonStates.length();
|
385
|
mStates = new ScrambleState[numStates];
|
386
|
|
387
|
for(int i=0; i<numStates; i++)
|
388
|
{
|
389
|
JSONArray jsonState = jsonStates.getJSONArray(i);
|
390
|
int numAxis = jsonState.length();
|
391
|
int[][] scramblingData = new int[numAxis][];
|
392
|
|
393
|
for(int j=0; j<numAxis; j++)
|
394
|
{
|
395
|
JSONArray jsonData = jsonState.getJSONArray(j);
|
396
|
int numData = jsonData.length();
|
397
|
scramblingData[j] = new int[numData];
|
398
|
for(int k=0; k<numData; k++) scramblingData[j][k] = jsonData.getInt(k);
|
399
|
}
|
400
|
|
401
|
mStates[i] = new ScrambleState(scramblingData);
|
402
|
}
|
403
|
}
|
404
|
}
|
405
|
|
406
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
407
|
|
408
|
private void parseTouchcontrol(JSONObject object) throws JSONException
|
409
|
{
|
410
|
mMovementType = object.getInt("movementType");
|
411
|
mMovementSplit= object.getInt("movementSplit");
|
412
|
|
413
|
JSONArray jsonEnabled = object.getJSONArray("enabledAxis");
|
414
|
int numFace = jsonEnabled.length();
|
415
|
|
416
|
mEnabled = new int[numFace][][];
|
417
|
|
418
|
for(int i=0; i<numFace; i++)
|
419
|
{
|
420
|
JSONArray jsonSection = jsonEnabled.getJSONArray(i);
|
421
|
int numSection = jsonSection.length();
|
422
|
mEnabled[i] = new int[numSection][];
|
423
|
|
424
|
for(int j=0; j<numSection; j++)
|
425
|
{
|
426
|
JSONArray jsonAx = jsonSection.getJSONArray(j);
|
427
|
int numAxis = jsonAx.length();
|
428
|
mEnabled[i][j] = new int[numAxis];
|
429
|
for(int k=0; k<numAxis; k++) mEnabled[i][j][k] = jsonAx.getInt(k);
|
430
|
}
|
431
|
}
|
432
|
|
433
|
try
|
434
|
{
|
435
|
JSONArray jsonDist = object.getJSONArray("dist3D");
|
436
|
int num = jsonDist.length();
|
437
|
mDist3D = new float[num];
|
438
|
for(int j=0; j<num; j++) mDist3D[j] = (float)jsonDist.getDouble(j);
|
439
|
}
|
440
|
catch( JSONException ex )
|
441
|
{
|
442
|
// ignore, the object does not have a 'dist3D' which is possible.
|
443
|
}
|
444
|
}
|
445
|
|
446
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
447
|
|
448
|
private void parseColors(JSONArray object) throws JSONException
|
449
|
{
|
450
|
mNumFaceColors = object.length();
|
451
|
mColor = new int[mNumFaceColors];
|
452
|
for(int i=0; i<mNumFaceColors; i++) mColor[i] = object.getInt(i);
|
453
|
}
|
454
|
|
455
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
456
|
|
457
|
private void parseVersion1(JSONObject object) throws JSONException
|
458
|
{
|
459
|
JSONObject metadata = object.getJSONObject("metadata");
|
460
|
parseMetadata(metadata);
|
461
|
JSONObject mesh = object.getJSONObject("mesh");
|
462
|
parseMesh(mesh);
|
463
|
JSONArray axis = object.getJSONArray("axis");
|
464
|
parseAxis(axis);
|
465
|
JSONArray quats = object.getJSONArray("quats");
|
466
|
parseQuats(quats);
|
467
|
JSONObject scrambling = object.getJSONObject("scrambling");
|
468
|
parseScrambling(scrambling);
|
469
|
JSONObject touchcontrol= object.getJSONObject("touchcontrol");
|
470
|
parseTouchcontrol(touchcontrol);
|
471
|
JSONArray colors = object.getJSONArray("colors");
|
472
|
parseColors(colors);
|
473
|
}
|
474
|
|
475
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476
|
|
477
|
private void parseVersion1Metadata(JSONObject object) throws JSONException
|
478
|
{
|
479
|
JSONObject metadata = object.getJSONObject("metadata");
|
480
|
parseMetadata(metadata);
|
481
|
}
|
482
|
|
483
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
484
|
|
485
|
public void parseJsonFile(InputStream jsonStream)
|
486
|
{
|
487
|
BufferedReader br = new BufferedReader(new InputStreamReader(jsonStream, StandardCharsets.UTF_8));
|
488
|
|
489
|
try
|
490
|
{
|
491
|
StringBuilder contents = new StringBuilder();
|
492
|
String tmp;
|
493
|
while( (tmp = br.readLine()) != null) contents.append(tmp);
|
494
|
br.close();
|
495
|
jsonStream.close();
|
496
|
|
497
|
JSONObject object = new JSONObject(contents.toString());
|
498
|
int major = object.getInt("major");
|
499
|
|
500
|
if( major==1 )
|
501
|
{
|
502
|
parseVersion1(object);
|
503
|
}
|
504
|
else
|
505
|
{
|
506
|
android.util.Log.e("readJsonFile", "Unknown version "+major);
|
507
|
}
|
508
|
}
|
509
|
catch(IOException e)
|
510
|
{
|
511
|
android.util.Log.e("readJsonFile", "Error reading JSON file: "+e.toString());
|
512
|
}
|
513
|
catch( JSONException e )
|
514
|
{
|
515
|
android.util.Log.e("parseJsonFile", "Error parsing JSON file: "+e.toString());
|
516
|
}
|
517
|
}
|
518
|
|
519
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
520
|
|
521
|
public void parseJsonFileMetadata(InputStream jsonStream)
|
522
|
{
|
523
|
BufferedReader br = new BufferedReader(new InputStreamReader(jsonStream, StandardCharsets.UTF_8));
|
524
|
|
525
|
try
|
526
|
{
|
527
|
StringBuilder contents = new StringBuilder();
|
528
|
String tmp;
|
529
|
while( (tmp = br.readLine()) != null) contents.append(tmp);
|
530
|
br.close();
|
531
|
jsonStream.close();
|
532
|
|
533
|
JSONObject object = new JSONObject(contents.toString());
|
534
|
int major = object.getInt("major");
|
535
|
|
536
|
if( major==1 )
|
537
|
{
|
538
|
parseVersion1Metadata(object);
|
539
|
}
|
540
|
else
|
541
|
{
|
542
|
android.util.Log.e("readJsonFileQuick", "Unknown version "+major);
|
543
|
}
|
544
|
}
|
545
|
catch(IOException e)
|
546
|
{
|
547
|
android.util.Log.e("readJsonFileQuick", "Error reading JSON file: "+e.toString());
|
548
|
}
|
549
|
catch( JSONException e )
|
550
|
{
|
551
|
android.util.Log.e("parseJsonFileQuick", "Error parsing JSON file: "+e.toString());
|
552
|
}
|
553
|
}
|
554
|
|
555
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
556
|
|
557
|
public ScrambleState[] getScrambleStates()
|
558
|
{
|
559
|
return mStates;
|
560
|
}
|
561
|
|
562
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
563
|
|
564
|
public int[] getSolvedQuats(int cubit)
|
565
|
{
|
566
|
return mSolvedQuats[cubit];
|
567
|
}
|
568
|
|
569
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
570
|
|
571
|
public Static4D[] getQuats()
|
572
|
{
|
573
|
return mQuats;
|
574
|
}
|
575
|
|
576
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
577
|
|
578
|
public int getSolvedFunctionIndex()
|
579
|
{
|
580
|
return mSolvedFuncIndex;
|
581
|
}
|
582
|
|
583
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
584
|
|
585
|
public int getNumStickerTypes()
|
586
|
{
|
587
|
return mNumStickerTypes;
|
588
|
}
|
589
|
|
590
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
591
|
|
592
|
public float[][] getCuts()
|
593
|
{
|
594
|
return mCuts;
|
595
|
}
|
596
|
|
597
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
598
|
|
599
|
public boolean[][] getLayerRotatable()
|
600
|
{
|
601
|
return mLayerRotatable;
|
602
|
}
|
603
|
|
604
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
605
|
|
606
|
public int getMovementType()
|
607
|
{
|
608
|
return mMovementType;
|
609
|
}
|
610
|
|
611
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
612
|
|
613
|
public int getMovementSplit()
|
614
|
{
|
615
|
return mMovementSplit;
|
616
|
}
|
617
|
|
618
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
619
|
|
620
|
public int[][][] getEnabled()
|
621
|
{
|
622
|
return mEnabled;
|
623
|
}
|
624
|
|
625
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
626
|
|
627
|
public float[] getDist3D()
|
628
|
{
|
629
|
return mDist3D;
|
630
|
}
|
631
|
|
632
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
633
|
|
634
|
public int getNumCubitFaces()
|
635
|
{
|
636
|
return mNumCubitFaces;
|
637
|
}
|
638
|
|
639
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
640
|
|
641
|
public float[][] getCubitPositions()
|
642
|
{
|
643
|
return mPositions;
|
644
|
}
|
645
|
|
646
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
647
|
|
648
|
public ObjectShape getObjectShape(int variant)
|
649
|
{
|
650
|
return mShapes[variant];
|
651
|
}
|
652
|
|
653
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
654
|
|
655
|
public ObjectFaceShape getObjectFaceShape(int variant)
|
656
|
{
|
657
|
return mFaceShapes[variant];
|
658
|
}
|
659
|
|
660
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
661
|
|
662
|
public Static4D getCubitQuats(int cubit)
|
663
|
{
|
664
|
return mCubitQuats[cubit];
|
665
|
}
|
666
|
|
667
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
668
|
|
669
|
public int getNumCubitVariants()
|
670
|
{
|
671
|
return mNumCubitVariants;
|
672
|
}
|
673
|
|
674
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
675
|
|
676
|
public int getCubitVariant(int cubit)
|
677
|
{
|
678
|
return mCubitVariant[cubit];
|
679
|
}
|
680
|
|
681
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
682
|
|
683
|
public int getVariantFaceColor(int variant, int face)
|
684
|
{
|
685
|
int[] colors = mVariantFaceColor[variant];
|
686
|
return colors.length>face ? colors[face] : -1;
|
687
|
}
|
688
|
|
689
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
690
|
|
691
|
public int getCubitFaceColor(int cubit, int face)
|
692
|
{
|
693
|
return mCubitFaceColor[cubit][face];
|
694
|
}
|
695
|
|
696
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
697
|
|
698
|
public int getNumScrambles()
|
699
|
{
|
700
|
return mNumScrambles;
|
701
|
}
|
702
|
|
703
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
704
|
|
705
|
public ObjectSticker retSticker(int sticker)
|
706
|
{
|
707
|
return mObjectSticker[sticker];
|
708
|
}
|
709
|
|
710
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
711
|
|
712
|
public Static3D[] getRotationAxis()
|
713
|
{
|
714
|
return mAxis;
|
715
|
}
|
716
|
|
717
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
718
|
|
719
|
public int[] getBasicAngle()
|
720
|
{
|
721
|
return mBasicAngle;
|
722
|
}
|
723
|
|
724
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
725
|
|
726
|
public ObjectType intGetObjectType()
|
727
|
{
|
728
|
return mType;
|
729
|
}
|
730
|
|
731
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
732
|
|
733
|
public String getObjectName()
|
734
|
{
|
735
|
return mLongName;
|
736
|
}
|
737
|
|
738
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
739
|
|
740
|
public String getShortName()
|
741
|
{
|
742
|
return mShortName;
|
743
|
}
|
744
|
|
745
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
746
|
|
747
|
public String getInventor()
|
748
|
{
|
749
|
return mInventor;
|
750
|
}
|
751
|
|
752
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
753
|
|
754
|
public int getYearOfInvention()
|
755
|
{
|
756
|
return mYearOfInvention;
|
757
|
}
|
758
|
|
759
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
760
|
|
761
|
public int getComplexity()
|
762
|
{
|
763
|
return mComplexity;
|
764
|
}
|
765
|
|
766
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
767
|
|
768
|
public int getNumFaces()
|
769
|
{
|
770
|
return mNumFaces;
|
771
|
}
|
772
|
|
773
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
774
|
|
775
|
public int getNumFaceColors()
|
776
|
{
|
777
|
return mNumFaceColors;
|
778
|
}
|
779
|
|
780
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
781
|
|
782
|
public int[] getNumLayers()
|
783
|
{
|
784
|
return mNumLayers;
|
785
|
}
|
786
|
|
787
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
788
|
|
789
|
public float getSize()
|
790
|
{
|
791
|
return mSize;
|
792
|
}
|
793
|
|
794
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
795
|
|
796
|
public int getScrambleType()
|
797
|
{
|
798
|
return mScrambleType;
|
799
|
}
|
800
|
|
801
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
802
|
|
803
|
public int getColor(int face)
|
804
|
{
|
805
|
return mColor[face];
|
806
|
}
|
807
|
|
808
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
809
|
|
810
|
public boolean shouldResetTextureMaps()
|
811
|
{
|
812
|
return mResetMaps;
|
813
|
}
|
814
|
}
|