Google Play保存的游戏冲突显示错误的快照

时间:2016-01-28 19:07:23

标签: android conflict google-play-games

我在我的应用中使用不同的存档游戏。 “硬币”,“水平”,......

它工作正常但如果检测到冲突则其结果错误。

/**
     * Conflict resolution for when Snapshots are opened.  Must be run in an AsyncTask or in a
     * background thread,
     */
    Snapshots.OpenSnapshotResult processSnapshotOpenResult(Snapshots.OpenSnapshotResult result, int retryCount) {

        retryCount++;

        int status = result.getStatus().getStatusCode();
        Log.i(TAG, "Load Result for saveGame<" + savedGame.getName() + "> status: " + status);

        if (status == GamesStatusCodes.STATUS_OK) {
            return result;
        } else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONTENTS_UNAVAILABLE) {
            return result;
        } else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {

            saveResolveConflictGameData = true;

            Log.i(TAG, "Konflikt aufgetreten");
            Snapshots.OpenSnapshotResult resolveResult = null;
            Snapshot snapshot = result.getSnapshot();
            Snapshot conflictSnapshot = result.getConflictingSnapshot();

            Snapshot mResolvedSnapshot = null;
            mResolvedSnapshot = snapshot;


            SnapshotMetadata s1Meta = snapshot.getMetadata();
            SnapshotMetadata cMeta = conflictSnapshot.getMetadata();

            // resolveConflict and get new merged Parser Object
            //
            Parser conflictParserTemp = savedGame.resolveConflict(snapshot, conflictSnapshot);

            if ( conflictParserTemp == null) {
                Log.e(TAG, "savedGame.resolveConflict(snapshot,conflictSnapshot) Error");
                return  result;
            }

            //
            // wurde schon ein conflict behandelt ?
            //
            if ( conflictParser != null ) {
                // merge previous Conflict with this conflict
                conflictParser.merge(conflictParserTemp);
            } else {
                // set first conflict Parser
                conflictParser = conflictParserTemp;
            }

            Log.i(TAG, String.format("Games.Snapshots.resolveConflict() Step %d", retryCount));

            resolveResult =
            Games.Snapshots.resolveConflict(
                    activity.mGoogleApiClient, result.getConflictId(), mResolvedSnapshot).await();

            if (retryCount < MAX_SNAPSHOT_RESOLVE_RETRIES) {
                // Recursively attempt again
                return processSnapshotOpenResult(resolveResult, retryCount);
            } else {

                // Failed, log error and show Toast to the user
                String message = "Could not resolve snapshot conflicts";
                Log.e(TAG, message);
                Toast.makeText(activity.getBaseContext(), message, Toast.LENGTH_LONG).show();
                return resolveResult;
            }

        }

        // Fail, return null.
        return null;
    }

错误是,如果我加载savegame“coins”,我将成为其他存档游戏中的所有冲突。

我在这里看到了。

SnapshotMetadata s1Meta = snapshot.getMetadata();
            SnapshotMetadata cMeta = conflictSnapshot.getMetadata();

korrekt硬币快照的快照显示:

  

SnapshotMetadataEntity {游戏= GameEntity {的applicationID = 520840013521,   DisplayName =粉碎我,PrimaryCategory =模拟,   SecondaryCategory = null,Description = hallo,DeveloperName = steffen   höhmann,IconImageUri = null,IconImageUrl = null,HiResImageUri = null,   HiResImageUrl = null,FeaturedImageUri = null,FeaturedImageUrl = null,   PlayEnabledGame = true,InstanceInstalled = true,   InstancePackageName = cherry.de.wubbleburst,AchievementTotalCount = 0,   LeaderboardCount = 0,RealTimeMultiplayerEnabled = false,   TurnBasedMultiplayerEnabled = false,AreSnapshotsEnabled = true,   ThemeColor = 00456B,HasGamepadSupport = false},   所有者= PlayerEntity {PlayerId = 113260033482974102226,   DisplayName = shoehmi,HasDebugAccess = false,IconImageUri = null,   IconImageUrl = null,HiResImageUri = null,HiResImageUrl = null,   RetrievedTimestamp = 1454003980807,Title =Anfänger,   LevelInfo=com.google.android.gms.games.PlayerLevelInfo@1e1b36},   SnapshotId =驱动器://520840013521分之113260033482974102226/硬币,   CoverImageUri = null,CoverImageUrl = null,CoverImageAspectRatio = 0.0,   Description = null,LastModifiedTimestamp = 1454004003382,PlayedTime = -1,   UniqueName = coins,ChangePending = true,ProgressValue = -1}   驱动://520840013521分之113260033482974102226/硬币

和snapshotData:

  

时间戳;硬币#1453929273252; 100#1453929280956; -70#230179; 70

但是他向我展示了来自“级别”存档游戏的游戏快照,作为冲突的快照:

  

levelId;分#1; 3241#2; 9634

和冲突快照元数据说它是一个“硬币”存档游戏:

  

SnapshotMetadataEntity {游戏= GameEntity {的applicationID = 520840013521,   DisplayName =粉碎我,PrimaryCategory =模拟,   SecondaryCategory = null,Description = hallo,DeveloperName = steffen   höhmann,IconImageUri = null,IconImageUrl = null,HiResImageUri = null,   HiResImageUrl = null,FeaturedImageUri = null,FeaturedImageUrl = null,   PlayEnabledGame = true,InstanceInstalled = true,   InstancePackageName = cherry.de.wubbleburst,AchievementTotalCount = 0,   LeaderboardCount = 0,RealTimeMultiplayerEnabled = false,   TurnBasedMultiplayerEnabled = false,AreSnapshotsEnabled = true,   ThemeColor = 00456B,HasGamepadSupport = false},   所有者= PlayerEntity {PlayerId = 113260033482974102226,   DisplayName = shoehmi,HasDebugAccess = false,IconImageUri = null,   IconImageUrl = null,HiResImageUri = null,HiResImageUrl = null,   RetrievedTimestamp = 1454003980807,Title =Anfänger,   LevelInfo=com.google.android.gms.games.PlayerLevelInfo@1e1b36},   SnapshotId =驱动器://520840013521分之113260033482974102226/硬币,   CoverImageUri = null,CoverImageUrl = null,CoverImageAspectRatio = 0.0,   Description = null,LastModifiedTimestamp = 1454004003382,PlayedTime = -1,   UniqueName = coins,ChangePending = true,ProgressValue = -1}   驱动://520840013521分之113260033482974102226/硬币

为什么只有在发生冲突且没有冲突时才能正常运行 保存/加载正确??

请帮帮我???

抱歉我的英语;)

0 个答案:

没有答案