commit 1eafa9c6a0303b74832956f6753429620981ed90
Author: leszek <leszek@koltunski.pl>
Date:   Tue Mar 12 00:04:47 2024 +0100

    Fix the detection of the solved state.

diff --git a/src/main/java/org/distorted/objectlib/effects/objectchange/ObjectChangeEffect.java b/src/main/java/org/distorted/objectlib/effects/objectchange/ObjectChangeEffect.java
index 2333c42b..b40e4773 100644
--- a/src/main/java/org/distorted/objectlib/effects/objectchange/ObjectChangeEffect.java
+++ b/src/main/java/org/distorted/objectlib/effects/objectchange/ObjectChangeEffect.java
@@ -130,7 +130,7 @@ public abstract class ObjectChangeEffect extends BaseEffect implements EffectLis
 
     if( mPre!=null )
       {
-      int numFaces = mObject[1].getNumFaces();
+      int numFaces = mObject[1].getNumPuzzleFaces();
       mPre.setDefaultRotation(numFaces);
       }
 
diff --git a/src/main/java/org/distorted/objectlib/json/JsonWriter.java b/src/main/java/org/distorted/objectlib/json/JsonWriter.java
index 6c37e7ec..e384fb29 100644
--- a/src/main/java/org/distorted/objectlib/json/JsonWriter.java
+++ b/src/main/java/org/distorted/objectlib/json/JsonWriter.java
@@ -436,7 +436,7 @@ public class JsonWriter
     metadata.put("scrambles"  , meta.numScrambles() );
     metadata.put("shortname"  , object.getShortName() );
     metadata.put("resetmaps"  , object.shouldResetTextureMaps() );
-    metadata.put("num_faces"  , object.getNumFaces() );
+    metadata.put("num_faces"  , object.getNumPuzzleFaces() );
     metadata.put("price"      , meta.price() );
     metadata.put("category"   , meta.getCategory() );
 
diff --git a/src/main/java/org/distorted/objectlib/main/TwistyJson.java b/src/main/java/org/distorted/objectlib/main/TwistyJson.java
index 688745be..92354df8 100644
--- a/src/main/java/org/distorted/objectlib/main/TwistyJson.java
+++ b/src/main/java/org/distorted/objectlib/main/TwistyJson.java
@@ -404,7 +404,7 @@ public class TwistyJson extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int getNumFaces()
+  public int getNumPuzzleFaces()
     {
     return mReader.getNumFaces();
     }
diff --git a/src/main/java/org/distorted/objectlib/main/TwistyObject.java b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
index aeabfbcb..441d2022 100644
--- a/src/main/java/org/distorted/objectlib/main/TwistyObject.java
+++ b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
@@ -216,7 +216,7 @@ public abstract class TwistyObject
     mObjectQuats = getQuats();
     mNumQuats = mObjectQuats.length;
     mOrigPos = getCubitPositions(mNumLayers);
-    mNumPuzzleFaces = getNumFaces();
+    mNumPuzzleFaces = getNumPuzzleFaces();
     mRowOffsets = new float[mNumPuzzleFaces][3];
     mTmp = new float[4];
     mNumAxis = mAxis.length;
@@ -283,6 +283,7 @@ public abstract class TwistyObject
     int index = getSolvedFunctionIndex();
     mSolved = new TwistyObjectSolved(this,mOrigPos,index);
     mSolved.setupSolvedQuats(getSolvedQuats());
+    mSolved.setPuzzleFaceColor(mColorTable);
 
     mEffects.apply(quatEffect);
     mEffects.apply(scaleEffect);
@@ -1278,6 +1279,8 @@ public abstract class TwistyObject
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// this doesn't have to return the real, displayed color - but the default one (from Shape classes).
+// The real displayed color can be different because of the sticker color overrides in 'Config'.
 
   int getCubitFaceColor(int cubit, int face)
     {
@@ -1478,6 +1481,7 @@ public abstract class TwistyObject
       {
       createTexture(mTextureBorderMultiplier,mTextureCornerMultiplier);
       setTexture();
+      mSolved.setPuzzleFaceColor(mColorTable);
       }
     }
 
@@ -2177,7 +2181,7 @@ public abstract class TwistyObject
   // not only for JSON
   public abstract Static3D[] getRotationAxis();
   public abstract int[][] getBasicAngles();
-  public abstract int getNumFaces();
+  public abstract int getNumPuzzleFaces();
   public abstract int getFOV();
   public abstract String[][] getTutorials();
   }
diff --git a/src/main/java/org/distorted/objectlib/main/TwistyObjectSolved.java b/src/main/java/org/distorted/objectlib/main/TwistyObjectSolved.java
index aa7bfe16..b80509d5 100644
--- a/src/main/java/org/distorted/objectlib/main/TwistyObjectSolved.java
+++ b/src/main/java/org/distorted/objectlib/main/TwistyObjectSolved.java
@@ -44,9 +44,10 @@ class TwistyObjectSolved
     };
 
   private int[][] mSurfaceTable;
-  private int[][] mFaceColorTable;
+  private int[][] mTmpFaceColorTable;
   private int[][] mCubitFaceToSurfaceMap;
-  private int[][] mCubitFaceColor;
+  private int[][] mCubitFaceToPuzzleFaceMap;
+  private int[] mPuzzleFaceColor;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // remember about the double cover or unit quaternions!
@@ -324,7 +325,7 @@ class TwistyObjectSolved
     int numVariants = mParent.getNumCubitVariants(numLayers);
     ObjectShape[] shapes = new ObjectShape[numVariants];
     mCubitFaceToSurfaceMap = new int[numCubits][];
-    mCubitFaceColor = new int[numCubits][];
+    mCubitFaceToPuzzleFaceMap = new int[numCubits][];
 
     for(int v=0; v<numVariants; v++) shapes[v] = mParent.getObjectShape(v);
 
@@ -335,7 +336,7 @@ class TwistyObjectSolved
       int variant = mParent.getCubitVariant(c,numLayers);
       ObjectShape s = shapes[variant];
       int numFaces = s.getNumFaces();
-      mCubitFaceColor[c] = new int[numFaces];
+      mCubitFaceToPuzzleFaceMap[c] = new int[numFaces];
       mCubitFaceToSurfaceMap[c] = new int[numFaces];
       for(int f=0; f<numFaces; f++) mCubitFaceToSurfaceMap[c][f] = -1;
 
@@ -358,11 +359,11 @@ class TwistyObjectSolved
 
       for(int f=0; f<numFaces; f++)
         {
-        mCubitFaceColor[c][f] = mParent.getCubitFaceColor(c,f);
+        mCubitFaceToPuzzleFaceMap[c][f] = mParent.getCubitFaceColor(c,f);
 
-        if( !mParent.faceIsOuter(c,f) ) continue;
+        //android.util.Log.e("D", "cubit "+c+" face "+f+" puzzle face: "+ mCubitFaceToPuzzleFaceMap[c][f]);
 
-        //android.util.Log.e("D", "cubit "+c+" face "+f);
+        if( !mParent.faceIsOuter(c,f) ) continue;
 
         float[] surface  = new float[4];
         float[] rotPoint = new float[4];
@@ -400,12 +401,6 @@ class TwistyObjectSolved
             {
             float[] ts = multiplySurface(surface, mObjectQuats[q]);
             int ind = adjoinNewSurface(tmpSurfaces,ts);
-/*
-            if( ind==6 || ind==5 )
-              {
-              android.util.Log.e("D","SURFACE "+ind+": "+ts[0]+" "+ts[1]+" "+ts[2]+" "+ts[3] );
-              }
-*/
             indices[q] = ind;
             }
 
@@ -572,9 +567,9 @@ class TwistyObjectSolved
   private int surfaceColor(int filled, int surface)
     {
     for(int s=0; s<filled; s++)
-      if( mFaceColorTable[s][0] == surface ) return mFaceColorTable[s][1];
+      if( mTmpFaceColorTable[s][0] == surface ) return mTmpFaceColorTable[s][1];
 
-    return -1;
+    return 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -582,7 +577,7 @@ class TwistyObjectSolved
   private boolean isSolved2(TwistyObjectCubit[] cubits)
     {
     int filled = 0;
-    int max = mFaceColorTable.length;
+    int max = mTmpFaceColorTable.length;
 
     for(int c=0; c<mNumCubits; c++)
       {
@@ -595,24 +590,36 @@ class TwistyObjectSolved
 
         if( initSurface>=0 )
           {
-          int currSurface = mSurfaceTable[initSurface][quat];
-          int currColor = mCubitFaceColor[c][f];
-          int prevColor = surfaceColor(filled,currSurface);
+          int puzzleFace = mCubitFaceToPuzzleFaceMap[c][f];
+          int currSurface= mSurfaceTable[initSurface][quat];
+          int currColor  = puzzleFace>=0 ? mPuzzleFaceColor[puzzleFace] : 0;
+          int prevColor  = surfaceColor(filled,currSurface);
 
-          if( prevColor<0 )
+//android.util.Log.e("D", "cubit "+c+" face "+f+" puzzleFace: "+puzzleFace+" currColor: "+currColor+" prevColor: "+prevColor);
+
+          if( prevColor==0 )
             {
-            if( filled>=max ) return false;
-            mFaceColorTable[filled][0] = currSurface;
-            mFaceColorTable[filled][1] = currColor;
+            if( filled>=max )
+              {
+              //android.util.Log.e("D", "false1");
+              return false;
+              }
+            mTmpFaceColorTable[filled][0] = currSurface;
+            mTmpFaceColorTable[filled][1] = currColor;
             prevColor = currColor;
             filled++;
             }
 
-          if( prevColor!=currColor ) return false;
+          if( prevColor!=currColor )
+            {
+            //android.util.Log.e("D", "false2");
+            return false;
+            }
           }
         }
       }
 
+    // android.util.Log.e("D", "true");
     return true;
     }
 
@@ -697,11 +704,18 @@ class TwistyObjectSolved
     if( mFunctionIndex==2 )
       {
       computeSurfaceTable();
-      int numFaces = parent.getNumFaces();
-      mFaceColorTable = new int[numFaces][2];
+      int numFaces = parent.getNumPuzzleFaces();
+      mTmpFaceColorTable = new int[numFaces][2];
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void setPuzzleFaceColor(int[] color)
+    {
+    mPuzzleFaceColor = color;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   boolean isSolved(TwistyObjectCubit[] cubits)
diff --git a/src/main/java/org/distorted/objectlib/shape/ShapeDiamond.java b/src/main/java/org/distorted/objectlib/shape/ShapeDiamond.java
index 646af60c..bb7958c9 100644
--- a/src/main/java/org/distorted/objectlib/shape/ShapeDiamond.java
+++ b/src/main/java/org/distorted/objectlib/shape/ShapeDiamond.java
@@ -55,7 +55,7 @@ public abstract class ShapeDiamond extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public final int getNumFaces()
+  public final int getNumPuzzleFaces()
     {
     return NUM_FACES;
     }
diff --git a/src/main/java/org/distorted/objectlib/shape/ShapeDodecahedron.java b/src/main/java/org/distorted/objectlib/shape/ShapeDodecahedron.java
index 3964e964..8aa0a7e5 100644
--- a/src/main/java/org/distorted/objectlib/shape/ShapeDodecahedron.java
+++ b/src/main/java/org/distorted/objectlib/shape/ShapeDodecahedron.java
@@ -54,7 +54,7 @@ public abstract class ShapeDodecahedron extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public final int getNumFaces()
+  public final int getNumPuzzleFaces()
     {
     return NUM_FACES;
     }
diff --git a/src/main/java/org/distorted/objectlib/shape/ShapeHexahedron.java b/src/main/java/org/distorted/objectlib/shape/ShapeHexahedron.java
index fb3c8133..3b7cc9b1 100644
--- a/src/main/java/org/distorted/objectlib/shape/ShapeHexahedron.java
+++ b/src/main/java/org/distorted/objectlib/shape/ShapeHexahedron.java
@@ -41,7 +41,7 @@ public abstract class ShapeHexahedron extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public final int getNumFaces()
+  public final int getNumPuzzleFaces()
     {
     return NUM_FACES;
     }
diff --git a/src/main/java/org/distorted/objectlib/shape/ShapeIcosahedron.java b/src/main/java/org/distorted/objectlib/shape/ShapeIcosahedron.java
index 4d9472a3..d249f239 100644
--- a/src/main/java/org/distorted/objectlib/shape/ShapeIcosahedron.java
+++ b/src/main/java/org/distorted/objectlib/shape/ShapeIcosahedron.java
@@ -63,7 +63,7 @@ public abstract class ShapeIcosahedron extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public final int getNumFaces()
+  public final int getNumPuzzleFaces()
     {
     return NUM_FACES;
     }
diff --git a/src/main/java/org/distorted/objectlib/shape/ShapeOctahedron.java b/src/main/java/org/distorted/objectlib/shape/ShapeOctahedron.java
index 1769e9a9..1ef5c55a 100644
--- a/src/main/java/org/distorted/objectlib/shape/ShapeOctahedron.java
+++ b/src/main/java/org/distorted/objectlib/shape/ShapeOctahedron.java
@@ -42,7 +42,7 @@ public abstract class ShapeOctahedron extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public final int getNumFaces()
+  public final int getNumPuzzleFaces()
     {
     return NUM_FACES;
     }
diff --git a/src/main/java/org/distorted/objectlib/shape/ShapeTetrahedron.java b/src/main/java/org/distorted/objectlib/shape/ShapeTetrahedron.java
index b4fe4075..dd921f32 100644
--- a/src/main/java/org/distorted/objectlib/shape/ShapeTetrahedron.java
+++ b/src/main/java/org/distorted/objectlib/shape/ShapeTetrahedron.java
@@ -40,7 +40,7 @@ public abstract class ShapeTetrahedron extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public final int getNumFaces()
+  public final int getNumPuzzleFaces()
     {
     return NUM_FACES;
     }
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlSquare.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlSquare.java
index f931bf66..06e7ba05 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlSquare.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlSquare.java
@@ -35,7 +35,7 @@ public class TouchControlSquare extends TouchControlShapeChanging
     {
     super(object);
 
-    mNumFaces = object.getNumFaces();
+    mNumFaces = object.getNumPuzzleFaces();
     mFaceAxis = TouchControlHexahedron.FACE_AXIS;
     mTmp4  = new float[mNumFaces][4];
     mTmp2  = new float[mNumFaces][2];
