private void ResolveConflict(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData,
                                 ISavedGameMetadata unmerged, byte[] unmergedData)
    {
        if (originalData == null)
        {
            resolver.ChooseMetadata(unmerged);
        }
        else if (unmergedData == null)
        {
            resolver.ChooseMetadata(original);
        }
        else
        {
            string originalStr = Encoding.ASCII.GetString(originalData);
            string unmergedStr = Encoding.ASCII.GetString(unmergedData);

            int[] originalArray = JsonUtil.JsonStringToArray(originalStr, "SaveKey", str => int.Parse(str));
            int[] unmergedArray = JsonUtil.JsonStringToArray(unmergedStr, "SaveKey", str => int.Parse(str));

            for (int i = 0; i < originalArray.Length; i++)
            {
                if (originalArray[i] > unmergedArray[i])
                {
                    resolver.ChooseMetadata(original);
                    return;
                }
                else if (unmergedArray[i] > originalArray[i])
                {
                    resolver.ChooseMetadata(unmerged);
                    return;
                }
            }
            resolver.ChooseMetadata(original);
        }
    }
Пример #2
0
    private void ResolveConflict(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData,
                                 ISavedGameMetadata unmerged, byte[] unmergedData)
    {
        if (originalData == null)
        {
            resolver.ChooseMetadata(unmerged);
            Debug.Log("(Hangry)unmerged data chosen due to null!");
        }
        else if (unmergedData == null)
        {
            resolver.ChooseMetadata(original);
            Debug.Log("(Hangry)original data chosen due to null!");
        }
        else
        {
            //decoding byte data into string
            string originalStr = Encoding.UTF8.GetString(originalData);
            string unmergedStr = Encoding.UTF8.GetString(unmergedData);

            //parsing
            int[] originalArray = JsonUtil.JsonStringToArray(originalStr, "myKey", str => int.Parse(str));
            int[] unmergedArray = JsonUtil.JsonStringToArray(unmergedStr, "myKey", str => int.Parse(str));

            for (int i = 0; i < originalArray.Length; i++)
            {
                //if original score is greater than unmerged
                if (originalArray[i] > unmergedArray[i])
                {
                    Debug.Log("(Hangry)original data chosen, better!");
                    resolver.ChooseMetadata(original);
                    return;
                }
                //else (unmerged score is greater than original)
                else if (unmergedArray[i] > originalArray[i])
                {
                    Debug.Log("(Hangry)unmerged data chosen, vbettter!");

                    resolver.ChooseMetadata(unmerged);
                    return;
                }
            }
            //if return doesn't get called, original and unmerged are identical
            //we can keep either one
            Debug.Log("(Hangry)original data chosen, same!");

            resolver.ChooseMetadata(original);
        }
    }
Пример #3
0
        internal void ShowResolveConflict()
        {
            this.DrawTitle("RESOLVE SAVE GAME CONFLICT");
            this.DrawStatus();

            if (this.mConflictResolver == null)
            {
                Status = "No pending conflict";
                SetUI(Ui.SavedGame);
                return;
            }

            string msg = "Original: " + mConflictOriginal.Filename + ":" + mConflictOriginal.Description + "\n" +
                         "Data: " + mConflictOriginalData;

            GUI.Label(CalcGrid(0, 1, 2, 2), msg);

            msg = "Unmerged: " + mConflictUnmerged.Filename + ":" + mConflictUnmerged.Description + "\n" +
                  "Data: " + mConflictUnmergedData;
            GUI.Label(CalcGrid(0, 2, 2, 2), msg);

            if (GUI.Button(CalcGrid(0, 3), "Use Original"))
            {
                mConflictResolver.ChooseMetadata(mConflictOriginal);
                SetStandBy("Choosing original, retrying open");
                SetUI(Ui.SavedGame);
            }
            else if (GUI.Button(CalcGrid(1, 3), "Use Unmerged"))
            {
                mConflictResolver.ChooseMetadata(mConflictUnmerged);
                SetStandBy("Choosing unmerged, retrying open");
                SetUI(Ui.SavedGame);
            }
            else if (GUI.Button(CalcGrid(0, 4), "Use new data"))
            {
                SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
                builder = builder.WithUpdatedDescription(mConflictOriginal.Description + " (resolved).");
                mConflictResolver.ResolveConflict(mConflictOriginal, builder.Build(),
                                                  System.Text.ASCIIEncoding.Default.GetBytes(mSavedGameFileContent + " resolved"));
            }

            if (GUI.Button(CalcGrid(1, 7), "Back"))
            {
                SetUI(Ui.SavedGame);
                ShowEffect(true);
            }
        }
    private void ResolveConflict(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData,
                                 ISavedGameMetadata unmerged, byte[] unmergedData)
    {
        if (originalData == null)
        {
            resolver.ChooseMetadata(unmerged);
        }
        else if (unmergedData == null)
        {
            resolver.ChooseMetadata(original);
        }
        else
        {
            //decoding byte data into string
            string originalStr = Encoding.ASCII.GetString(originalData);
            string unmergedStr = Encoding.ASCII.GetString(unmergedData);

            //parsing
            int originalNum = int.Parse(originalStr);
            int unmergedNum = int.Parse(unmergedStr);

            //if original score is greater than unmerged
            if (originalNum > unmergedNum)
            {
                resolver.ChooseMetadata(original);
                return;
            }
            //else (unmerged score is greater than original)
            else if (unmergedNum > originalNum)
            {
                resolver.ChooseMetadata(unmerged);
                return;
            }

            //if return doesn't get called, original and unmerged are identical
            //we can keep either one
            resolver.ChooseMetadata(original);
        }
    }
Пример #5
0
    private void ResolveConflict(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData,
                                 ISavedGameMetadata unmerged, byte[] unmergedData)
    {
        if (originalData == null)
        {
            resolver.ChooseMetadata(unmerged);
        }
        else if (unmergedData == null)
        {
            resolver.ChooseMetadata(original);
        }

        else
        {
            BinaryFormatter bf          = null;
            MemoryStream    memStream   = null;
            GameData        originalObj = null;
            GameData        unmergedObj = null;

            // Deserialize originalData
            bf        = new BinaryFormatter();
            memStream = new MemoryStream();
            memStream.Write(originalData, 0, originalData.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            originalObj = (GameData)bf.Deserialize(memStream);

            // Deserialize unmergedData
            bf        = new BinaryFormatter();
            memStream = new MemoryStream();
            memStream.Write(unmergedData, 0, unmergedData.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            unmergedObj = (GameData)bf.Deserialize(memStream);

            // resolving strategy: pick the one with highest totalItemsPurchasedToDate
            // if both totalItemsPurchasedToDate are equal, pick the one with higher caughtCount
            if (originalObj.GetTotalItemsPurchasedToDate() > unmergedObj.GetTotalItemsPurchasedToDate())
            {
                resolver.ChooseMetadata(original);
                return;
            }
            else if (unmergedObj.GetTotalItemsPurchasedToDate() > originalObj.GetTotalItemsPurchasedToDate())
            {
                resolver.ChooseMetadata(unmerged);
                return;
            }
            else
            {
                if (originalObj.GetCaughtTotal() > unmergedObj.GetCaughtTotal())
                {
                    resolver.ChooseMetadata(original);
                }
                else
                {
                    resolver.ChooseMetadata(unmerged);
                }
            }
        }
    }
    void ShowResolveConflict()
    {
        DrawTitle("RESOLVE SAVE GAME CONFLICT");
        DrawStatus();

        if (mConflictResolver == null)
        {
            mStatus = "No pending conflict";
            mUi     = Ui.SavedGame;
            return;
        }

        GUI.Label(CalcGrid(0, 1, 2, 2),
                  "Original: " + mConflictOriginal.Filename + ":" + mConflictOriginal.Description + "\n" +
                  "Data: " + mConflictOriginalData);

        GUI.Label(CalcGrid(0, 2, 2, 2),
                  "Unmerged: " + mConflictUnmerged.Filename + ":" + mConflictUnmerged.Description + "\n" +
                  "Data: " + mConflictUnmergedData);

        if (GUI.Button(CalcGrid(0, 3), "Use Original"))
        {
            mConflictResolver.ChooseMetadata(mConflictOriginal);
            SetStandBy("Choosing original, retrying open");
            mUi = Ui.SavedGame;
        }
        else if (GUI.Button(CalcGrid(1, 3), "Use Unmerged"))
        {
            mConflictResolver.ChooseMetadata(mConflictUnmerged);
            SetStandBy("Choosing unmerged, retrying open");
            mUi = Ui.SavedGame;
        }

        if (GUI.Button(CalcGrid(1, 7), "Back"))
        {
            mUi = Ui.SavedGame;
        }
    }
Пример #7
0
    private void ResolveConflict(
        IConflictResolver resolver,
        ISavedGameMetadata original,
        byte[] originalData,
        ISavedGameMetadata unmerged,
        byte[] unmergedData)
    {
        if (originalData == null)
        {
            resolver.ChooseMetadata(unmerged);
        }
        else if (unmergedData == null)
        {
            resolver.ChooseMetadata(original);
        }
        else
        {
            string originalString = Encoding.ASCII.GetString(originalData);
            string unmergedString = Encoding.ASCII.GetString(unmergedData);

            // TODO: Compare the save
            resolver.ChooseMetadata(unmerged);
        }
    }
Пример #8
0
 void OnSavedGameOpenedAndReadConflictResolve(IConflictResolver resolver, ISavedGameMetadata original,
                                              byte[] originalData, ISavedGameMetadata unmerged, byte[] unmergedData)
 {
     resolver.ChooseMetadata(original);
 }
Пример #9
0
 static void OnSavedGameOpenedAndWriteConflictResolve(IConflictResolver resolver, ISavedGameMetadata original,
                                                      byte[] originalData, ISavedGameMetadata unmerged, byte[] unmergedData)
 {
     resolver.ChooseMetadata(unmerged);
 }
Пример #10
0
    /// <summary>
    /// Callback for resolving metadata conflict.
    /// </summary>
    private void ResolveConflict(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData, ISavedGameMetadata unmerged, byte[] unmergedData)
    {
        Debug.Log("[GPGS BUG] ResolveConflict entered.");
        if (originalData == null)
        {
            Debug.Log("[GPGS BUG] ResolveConflict: originalData null. Choose unmerged.");
            resolver.ChooseMetadata(unmerged);
        }
        else if (unmergedData == null)
        {
            Debug.Log("[GPGS BUG] ResolveConflict: unmergedData null. Choose original.");
            resolver.ChooseMetadata(original);
        }
        else
        {
            // deserialising byte data into Save Data
            SaveData originalSaveData = DeserialiseSaveData(originalData);
            SaveData unmergedSaveData = DeserialiseSaveData(unmergedData);

            #region Old Timestamp-based Validation
            //// getting Timestamp
            //DateTime originalTimestamp = originalSaveData.Timestamp;
            //DateTime unmergedTimestamp = unmergedSaveData.Timestamp;

            //// if original Timestamp is more recent than unmerged Timestamp
            //if (originalTimestamp > unmergedTimestamp)
            //{
            //    resolver.ChooseMetadata(original);
            //    return;
            //}
            //// unmerged Timestamp is more recent than original
            //else if (unmergedTimestamp > originalTimestamp)
            //{
            //    resolver.ChooseMetadata(unmerged);
            //    return;
            //}
            //// if return doesn't get called, original and unmerged are identical
            //// can keep either one
            //resolver.ChooseMetadata(original);
            #endregion

            // getting last level
            int originalLastLevel = originalSaveData.LastLevelNumber;
            int unmergedLastLevel = originalSaveData.LastLevelNumber;

            // if original last level is farther than unmerged last level
            if (originalLastLevel > unmergedLastLevel)
            {
                resolver.ChooseMetadata(original);
                return;
            }
            // if unmerged last level is farther than original last level
            else if (unmergedLastLevel > originalLastLevel)
            {
                resolver.ChooseMetadata(unmerged);
                return;
            }

            // if return doesn't get called, original and unmerged last levels are identical
            // getting stars
            int originalStars = 0;
            int unmergedStars = 0;

            foreach (var levelSaveData in originalSaveData.levelSaveData)
            {
                originalStars += levelSaveData.stars;
            }

            foreach (var levelSaveData in unmergedSaveData.levelSaveData)
            {
                unmergedStars += levelSaveData.stars;
            }

            // if original stars is more than unmerged stars
            if (originalStars > unmergedStars)
            {
                Debug.Log("[GPGS BUG] ResolveConflict: originalStars more. Choose original.");
                resolver.ChooseMetadata(original);
                return;
            }
            // if unmerged stars is more than original stars
            else if (unmergedStars > originalStars)
            {
                Debug.Log("[GPGS BUG] ResolveConflict: unmergedStars more. Choose unmerged.");
                resolver.ChooseMetadata(unmerged);
                return;
            }

            // if return doesn't get called, original and unmerged are identical
            // can choose either one
            Debug.Log("[GPGS BUG] ResolveConflict: identical. Choose original.");
            resolver.ChooseMetadata(original);
        }
    }
Пример #11
0
    private void ConflictCallback(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData, ISavedGameMetadata unmerged, byte[] unmergedData)
    {
        LoadingText("Conflict detected");
        if (originalData == null)
        {
            resolver.ChooseMetadata(unmerged);
        }
        else if (unmergedData == null)
        {
            resolver.ChooseMetadata(original);
        }
        else
        {
            //decoding byte data into string
            string originalStr = Encoding.ASCII.GetString(originalData);
            string unmergedStr = Encoding.ASCII.GetString(unmergedData);

            JSONSaveData originalJson;
            JSONSaveData unmergedJson;
            //parsing
            try
            {
                originalJson = JsonUtility.FromJson <JSONSaveData>(originalStr);
            }
            catch (System.Exception e)
            {
                originalJson = null;
                Debug.Log("Error on original" + e);
                throw;
            };

            try
            {
                unmergedJson = JsonUtility.FromJson <JSONSaveData>(unmergedStr);
            }
            catch (System.Exception e)
            {
                unmergedJson = null;
                Debug.Log("Error on unmerged" + e);
                throw;
            };

            if (originalJson == null)
            {
                if (unmergedJson == null)
                {
                    JSONSaveData.currentSave = LoadGameLocal();
                }
                else
                {
                    resolver.ChooseMetadata(unmerged);
                }
            }
            else
            {
                if (unmergedJson == null)
                {
                    resolver.ChooseMetadata(original);
                }
                else
                {
                    //Comparison
                    if (originalJson.playTime >= unmergedJson.playTime)
                    {
                        resolver.ChooseMetadata(original);
                    }
                    else
                    {
                        resolver.ChooseMetadata(unmerged);
                    }
                }
            }
        }
        LoadingText("Conflict resolved");
    }