Project

General

Profile

« Previous | Next » 

Revision 8e1231ae

Added by Leszek Koltunski about 4 years ago

Saving Cube state: done

View differences:

src/main/java/org/distorted/object/RubikCube.java
373 373
      }
374 374

  
375 375
///////////////////////////////////////////////////////////////////////////////////////////////////
376
// mSize already saved as RubikStatePlay.mButton
376 377

  
377 378
   public void savePreferences(SharedPreferences.Editor editor)
378 379
     {
379
     android.util.Log.e("cube", "saving Preferences");
380
     float qx,qy,qz,qw;
381

  
382
     for(int x=0; x<mSize; x++)
383
        for(int y=0; y<mSize; y++)
384
          for(int z=0; z<mSize; z++)
385
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
386
              {
387
              qx = mQuatScramble[x][y][z].get0();
388
              qy = mQuatScramble[x][y][z].get1();
389
              qz = mQuatScramble[x][y][z].get2();
390
              qw = mQuatScramble[x][y][z].get3();
391

  
392
              editor.putFloat("qx_"+x+"_"+y+"_"+z, qx);
393
              editor.putFloat("qy_"+x+"_"+y+"_"+z, qy);
394
              editor.putFloat("qz_"+x+"_"+y+"_"+z, qz);
395
              editor.putFloat("qw_"+x+"_"+y+"_"+z, qw);
396
              }
380 397
     }
381 398

  
382 399
///////////////////////////////////////////////////////////////////////////////////////////////////
383 400

  
384 401
   public void restorePreferences(SharedPreferences preferences)
385 402
     {
386
     android.util.Log.e("cube", "restoring Preferences");
403
     float qx,qy,qz,qw;
404

  
405
     for(int x=0; x<mSize; x++)
406
        for(int y=0; y<mSize; y++)
407
          for(int z=0; z<mSize; z++)
408
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
409
              {
410
              qx = preferences.getFloat("qx_"+x+"_"+y+"_"+z, 0.0f);
411
              qy = preferences.getFloat("qy_"+x+"_"+y+"_"+z, 0.0f);
412
              qz = preferences.getFloat("qz_"+x+"_"+y+"_"+z, 0.0f);
413
              qw = preferences.getFloat("qw_"+x+"_"+y+"_"+z, 1.0f);
414

  
415
              mQuatScramble[x][y][z].set(qx,qy,qz,qw);
416
              modifyCurrentPosition(x, y, z, mQuatScramble[x][y][z]);
417
              }
387 418
     }
388 419

  
389 420
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff