コード例 #1
0
ファイル: GameHelper.cs プロジェクト: tilteffect/KTManagerApp
        public async void Save(byte[] data)
        {
            var result = await GamesClass.Snapshots.Open(client, SavedGameFileName, true).AsAsync <ISnapshotsOpenSnapshotResult>();

            var code = result.Status.StatusCode;

            if (code == STATUS_SNAPSHOT_CONFLICT)
            {
                var conflictId         = result.ConflictId;
                var serverSnapshot     = result.Snapshot;
                var conflictedSnapshot = result.ConflictingSnapshot;

                result = await GamesClass.Snapshots.ResolveConflict(client, conflictId, conflictedSnapshot).AsAsync <ISnapshotsOpenSnapshotResult>();
            }
            //On sauve
            ISnapshotMetadataChange change = new SnapshotMetadataChangeBuilder()
                                             .SetDescription("KillTeamManager")
                                             .SetPlayedTimeMillis(DateTime.Now.Ticks)
                                             .Build();

            using (var settings = this.activity.GetSharedPreferences("googleplayservicessettings", FileCreationMode.Private))
            {
                using (var e = settings.Edit())
                {
                    e.PutLong("lastSave", change.PlayedTimeMillis.LongValue());
                    e.Commit();
                }
            }

            result.Snapshot.SnapshotContents.WriteBytes(dataToSave);
            await GamesClass.Snapshots.CommitAndClose(client, result.Snapshot, change);
        }
コード例 #2
0
        public async static Task <long> Update(long Gold, long Stage, float Damage, GoogleApiClient googleApiClient)
        {
            ISnapshot snapshot = await GetSnapshot(googleApiClient);

            snapshot.SnapshotContents.WriteBytes(CloudCopyState.GetData(Gold, Stage, Damage));

            SnapshotMetadataChangeBuilder metadataChangeBuilder = new SnapshotMetadataChangeBuilder( );

            metadataChangeBuilder.SetCoverImage(Assets.Icon);
            metadataChangeBuilder.SetDescription($"Time Titan Stage {Stage}, {Gold} Gold, {Damage} Damage");
            metadataChangeBuilder.SetProgressValue(Stage);
            ISnapshotMetadataChange metadataChange = metadataChangeBuilder.Build( );

            ISnapshotsCommitSnapshotResult commitSnapshotResult = await GamesClass.Snapshots.CommitAndCloseAsync(googleApiClient, snapshot, metadataChange);

            return(commitSnapshotResult.SnapshotMetadata.LastModifiedTimestamp);
        }
コード例 #3
0
 internal NativeSnapshotMetadataChange Build()
 {
     return(NativeSnapshotMetadataChange.FromPointer(SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_Create(this.SelfPtr())));
 }
コード例 #4
0
 internal NativeSnapshotMetadataChange.Builder SetCoverImageFromPngData(byte[] pngData)
 {
     Misc.CheckNotNull <byte[]>(pngData);
     SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_SetCoverImageFromPngData(this.SelfPtr(), pngData, new UIntPtr((ulong)pngData.LongLength));
     return(this);
 }
コード例 #5
0
 internal NativeSnapshotMetadataChange.Builder SetPlayedTime(ulong playedTime)
 {
     SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_SetPlayedTime(this.SelfPtr(), playedTime);
     return(this);
 }
コード例 #6
0
 internal NativeSnapshotMetadataChange.Builder SetDescription(string description)
 {
     SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_SetDescription(this.SelfPtr(), description);
     return(this);
 }
コード例 #7
0
 protected override void CallDispose(HandleRef selfPointer)
 {
     SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_Dispose(selfPointer);
 }
コード例 #8
0
 internal Builder()
     : base(SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_Construct())
 {
 }
コード例 #9
0
ファイル: GameHelper.cs プロジェクト: tilteffect/KTManagerApp
        public async Task <byte[]> Synchro(byte[] data)
        {
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            {
                if (Android.App.Application.Context.CheckSelfPermission(Manifest.Permission.Internet) != (int)Permission.Granted ||
                    Android.App.Application.Context.CheckSelfPermission(Manifest.Permission.GetAccounts) != (int)Permission.Granted)
                {
                    Android.Support.V4.App.ActivityCompat.RequestPermissions(this.activity, new string[]
                    {
                        Manifest.Permission.Internet,
                        Manifest.Permission.GetAccounts,
                    }, 0);
                    return(null);
                }
            }
            long lastSave = 0;

            using (var settings = this.activity.GetSharedPreferences("googleplayservicessettings", FileCreationMode.Private))
            {
                lastSave = settings.GetLong("lastSave", 0);
            }

            try
            {
                if (data != null)
                {
                    dataToSave = data;
                }

                if (!IsConnected())
                {
                    SignIn();
                }
                else
                {
                    var result = await GamesClass.Snapshots.Open(client, SavedGameFileName, true).AsAsync <ISnapshotsOpenSnapshotResult>();

                    var code = result.Status.StatusCode;
                    if (code == STATUS_SNAPSHOT_CONFLICT)
                    {
                        var conflictId         = result.ConflictId;
                        var serverSnapshot     = result.Snapshot;
                        var conflictedSnapshot = result.ConflictingSnapshot;

                        result = await GamesClass.Snapshots.ResolveConflict(client, conflictId, conflictedSnapshot).AsAsync <ISnapshotsOpenSnapshotResult>();
                    }
                    long savedTime = result.Snapshot.Metadata.PlayedTime;

                    if (savedTime > lastSave)
                    {
                        //On charge
                        using (var settings = this.activity.GetSharedPreferences("googleplayservicessettings", FileCreationMode.Private))
                        {
                            using (var e = settings.Edit())
                            {
                                e.PutLong("lastSave", savedTime);
                                e.Commit();
                            }
                        }

                        dataToLoad = result.Snapshot.SnapshotContents.ReadFully();
                        return(dataToLoad);
                    }
                    else
                    {
                        dataToLoad = null;

                        //On sauve
                        ISnapshotMetadataChange change = new SnapshotMetadataChangeBuilder()
                                                         .SetDescription("KillTeamManager")
                                                         .SetPlayedTimeMillis(DateTime.Now.Ticks)
                                                         .Build();

                        using (var settings = this.activity.GetSharedPreferences("googleplayservicessettings", FileCreationMode.Private))
                        {
                            using (var e = settings.Edit())
                            {
                                e.PutLong("lastSave", change.PlayedTimeMillis.LongValue());
                                e.Commit();
                            }
                        }

                        result.Snapshot.SnapshotContents.WriteBytes(dataToSave);
                        await GamesClass.Snapshots.CommitAndClose(client, result.Snapshot, change);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
            return(null);
        }
コード例 #10
0
 internal NativeSnapshotMetadataChange Build() =>
 NativeSnapshotMetadataChange.FromPointer(SnapshotMetadataChangeBuilder.SnapshotMetadataChange_Builder_Create(base.SelfPtr()));