예제 #1
0
        static void FixupStageList(SteamStats.LeaderboardsResponse leaderboards, string path)
        {
            var file = JsonConvert.DeserializeObject <StageListFile>(File.ReadAllText(path));

            foreach (var stage in file.Stages)
            {
                foreach (var level in stage.Levels)
                {
                    level.PortalsId = GetLeaderboardId(leaderboards, "challenge_portals_" + level.Map);
                    level.TimeId    = GetLeaderboardId(leaderboards, "challenge_besttime_" + level.Map);
                }
            }

            File.WriteAllText(path, JsonConvert.SerializeObject(file, Formatting.Indented));
        }
예제 #2
0
        static void DownloadEveryLeaderboard(SteamStats stats, SteamStats.LeaderboardsResponse leaderboards)
        {
            Console.WriteLine();
            Console.WriteLine($"Generating histogram for every leaderboard.");
            Console.WriteLine("Press any key to cancel...");

            var cancellationSource = new CancellationTokenSource();

            var task = DownloadLeaderboardsAsync(stats, leaderboards, cancellationSource.Token);

            task.ContinueWith((t, state) =>
            {
                Console.WriteLine();
                Console.WriteLine("Press any key to continue...");
            }, null, cancellationSource.Token);

            Console.ReadKey(false);

            if (!task.IsCompleted)
            {
                cancellationSource.Cancel();
            }
        }
예제 #3
0
        static void InteractiveMenu(SteamStats stats, SteamStats.LeaderboardsResponse leaderboards)
        {
            var path = new List <string>();

            SteamStats.LeaderboardInfo leaderboard;

browsing:
            {
                Console.WriteLine();
                Console.WriteLine($"Browsing /{string.Join("/", path)}:");

                var entries = leaderboards
                              .Where(x => x.IsInPath(path) && x.NameParts.Length > path.Count)
                              .GroupBy(x => x.NameParts[path.Count])
                              .OrderBy(x => x.Count() == 1 ? 1 : 0)
                              .ToArray();

                if (path.Count > 0)
                {
                    Console.WriteLine($"  {0}:\t../");
                }

                var i = 1;
                foreach (var entry in entries)
                {
                    Console.WriteLine($"  {i++}:\t{(entry.Count() == 1 ? entry.First().DisplayName : entry.Key + "/")}");
                }

                i = ReadIndex(path.Count > 0 ? 0 : 1, entries.Length);

                if (i == 0)
                {
                    path.RemoveAt(path.Count - 1);
                }
                else if (entries[i - 1].Count() == 1)
                {
                    leaderboard = entries[i - 1].First();
                    goto selected;
                }
                else
                {
                    path.Add(entries[i - 1].Key);
                }

                goto browsing;
            }

selected:
            {
                Console.WriteLine();
                Console.WriteLine($"Selected {leaderboard.DisplayName} ({leaderboard.Entries:N} entries).");
                Console.WriteLine($"  {0}:\tBack to browse");
                Console.WriteLine($"  {1}:\tGenerate histogram data");

                switch (ReadIndex(0, 1))
                {
                case 0:
                    goto browsing;

                case 1:
                    Console.WriteLine();
                    Console.WriteLine($"Generating histogram for {leaderboard.DisplayName}.");
                    Console.WriteLine("Press any key to cancel...");
                    Console.WriteLine();

                    var cancellationSource = new CancellationTokenSource();
                    var task = GenerateHistogramAsync(stats, leaderboard, cancellationSource.Token);

                    task.ContinueWith((t, state) =>
                    {
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue...");
                    }, null, cancellationSource.Token);

                    Console.ReadKey(false);

                    if (!task.IsCompleted)
                    {
                        cancellationSource.Cancel();
                    }

                    goto selected;
                }
            }
        }
예제 #4
0
        static int GetLeaderboardId(SteamStats.LeaderboardsResponse leaderboards, string name)
        {
            var match = leaderboards.FirstOrDefault(x => x.Name == name);

            return(match?.LeaderboardId ?? 0);
        }