コード例 #1
0
        /// <summary>
        /// Logins local user.
        /// </summary>
        /// <returns>
        /// The logged in user.
        /// </returns>
        public Task <Player> Login()
        {
            var tcs = new TaskCompletionSource <Player>();

            GKLocalPlayer.LocalPlayer.Authenticate(async(error) =>
            {
                var localPlayer = GKLocalPlayer.LocalPlayer;
                Player result   = null;

                if (error != null)
                {
#if DEBUG
                    new UIAlertView("Score submittion failed", "Submittion failed because: " + error, null, "OK", null).Show();
#endif
                }
                else if (localPlayer != null &&
                         localPlayer.Authenticated)
                {
                    result = await IOSMapper.MapPlayer(localPlayer);
                }

                tcs.TrySetResult(result);
            });

            return(tcs.Task);
        }
コード例 #2
0
        private Task <IEnumerable <LeaderboardScore> > InternalGetScores(string leaderboardCode, int count, bool socialOnly, bool centered)
        {
            var tcs = new TaskCompletionSource <IEnumerable <LeaderboardScore> >();

            UIKit.UIApplication.SharedApplication.InvokeOnMainThread(async() =>
            {
                var result = Enumerable.Empty <LeaderboardScore>();

                var leaderboards        = await GKLeaderboard.LoadLeaderboardsAsync() ?? new GKLeaderboard[] { };
                var selectedLeaderboard = leaderboards.FirstOrDefault(l => l.Identifier == leaderboardCode);

                if (selectedLeaderboard != null)
                {
                    selectedLeaderboard.PlayerScope = socialOnly ? GKLeaderboardPlayerScope.FriendsOnly : GKLeaderboardPlayerScope.Global;
                    selectedLeaderboard.Range       = new Foundation.NSRange(1, count);
                    var scores = await selectedLeaderboard.LoadScoresAsync();

                    if (centered && selectedLeaderboard.LocalPlayerScore != null)
                    {
                        var playerRank = selectedLeaderboard.LocalPlayerScore.Rank;
                        var fromIndex  = playerRank - (count / 2);
                        fromIndex      = fromIndex < 1 ? 1 : fromIndex;

                        selectedLeaderboard.Range = new Foundation.NSRange(fromIndex, count);
                        scores = await selectedLeaderboard.LoadScoresAsync();
                    }

                    result = await IOSMapper.MapLeaderBoards(scores);
                }

                tcs.SetResult(result);
            });

            return(tcs.Task);
        }
コード例 #3
0
        internal static async Task <IEnumerable <WaveEngine.Social.LeaderboardScore> > MapLeaderBoards(IEnumerable <GKScore> scores)
        {
            List <WaveEngine.Social.LeaderboardScore> waveScores = null;

            if (scores != null)
            {
                waveScores = new List <WaveEngine.Social.LeaderboardScore>();

                foreach (var item in scores)
                {
                    var scoreHolder = await IOSMapper.MapPlayer(item.Player);

                    var waveLeaderBoardScore = new WaveEngine.Social.LeaderboardScore()
                    {
                        DisplayRank  = null,
                        DisplayScore = item.FormattedValue,
                        Rank         = item.Rank,
                        RawScore     = item.Value,
                        ScoreHolder  = scoreHolder,
                        ScoreTag     = null,
                    };

                    waveScores.Add(waveLeaderBoardScore);
                }
            }

            return(waveScores);
        }
コード例 #4
0
        internal static async Task <IEnumerable <WaveEngine.Social.Achievement> > MapAchievements(IEnumerable <GKAchievement> achievements)
        {
            List <WaveEngine.Social.Achievement> waveAchievements = null;

            if (achievements != null)
            {
                waveAchievements = new List <WaveEngine.Social.Achievement>();

                foreach (var achievement in achievements)
                {
                    var waveAchievement = new WaveEngine.Social.Achievement()
                    {
                        AchievementCode      = achievement.Identifier,
                        CurrentSteps         = achievement.PercentComplete,
                        Description          = achievement.Description,
                        Player               = await IOSMapper.MapPlayer(achievement.Player),
                        RevealedImageUri     = null,
                        UnlockedImageUri     = null,
                        State                = 0,
                        TotalSteps           = 0,
                        Type                 = 0,
                        LastUpdatedTimestamp = 0,
                    };

                    waveAchievements.Add(waveAchievement);
                }
            }

            return(waveAchievements);
        }
コード例 #5
0
        /// <summary>
        /// Gets the achievements.
        /// </summary>
        /// <returns>
        /// The achievements.
        /// </returns>
        public Task <IEnumerable <Achievement> > GetAchievements()
        {
            var tcs = new TaskCompletionSource <IEnumerable <Achievement> >();

            UIKit.UIApplication.SharedApplication.InvokeOnMainThread(async() =>
            {
                var achievements     = await GKAchievement.LoadAchievementsAsync() ?? new GKAchievement[] { };
                var achievementsList = achievements.ToList();

                var result = await IOSMapper.MapAchievements(achievementsList);
                tcs.TrySetResult(result);
            });

            return(tcs.Task);
        }