Example #1
0
        public static string ViewGames(GameManager gameManager, int page = 0, ArcadeUser user = null)
        {
            var result = new StringBuilder();

            bool allowTooltips = user?.Config?.Tooltips ?? true;

            if (allowTooltips)
            {
                result.AppendLine($"{Format.Tooltip("Type `game <game_id>` to learn more about a game.")}\n");
            }


            int pageCount = Paginate.GetPageCount(gameManager.Games.Count, 5);

            page = Paginate.ClampIndex(page, pageCount);

            string extra = pageCount > 1 ? $" ({Format.PageCount(page + 1, pageCount)})" : "";


            result.AppendLine($"> **Games**{extra}");

            foreach (GameBase game in Paginate.GroupAt(gameManager.Games.Values, page, 8))
            {
                string id = game.Details.Name.Equals(game.Id, StringComparison.OrdinalIgnoreCase) ? "" : $"`{game.Id}` ";
                result.AppendLine($"> {id}{Format.Title(game.Details.Name, game.Details.Icon)} ({(game.Details.RequiredPlayers == game.Details.PlayerLimit ? $"**{game.Details.RequiredPlayers}**" : $"**{game.Details.RequiredPlayers}** to **{game.Details.PlayerLimit}**")} players)");
            }
Example #2
0
        public static string WriteFor(ArcadeUser user, string query, int page = 0, int pageSize = 15)
        {
            VarGroup group = Var.GetGroupDefiner(query);

            if (group == null)
            {
                return(Format.Warning("Unable to find the specified stat group."));
            }

            var result = new StringBuilder();

            if (group.Writer != null)
            {
                result.AppendLine($"> **Stats: {group.Name}**");
                result.AppendLine(group.Writer.Invoke(user));
                return(result.ToString());
            }

            var stats     = GetGroupStats(user, group.Id).ToList();
            int pageCount = Paginate.GetPageCount(stats.Count, pageSize);

            page = Paginate.ClampIndex(page, pageCount);

            string counter = null;

            if (pageCount > 1)
            {
                counter = $" ({Format.PageCount(page + 1, pageCount)})";
            }

            result.AppendLine($"> **Stats: {group.Name}**{counter}");

            int i = 0;

            foreach ((string id, long value) in Paginate.GroupAt(stats, page, pageSize))
            {
                if (i >= pageSize)
                {
                    break;
                }

                result.AppendLine($"`{id}`: {value}");
                i++;
            }

            if (i == 0)
            {
                result.AppendLine("An invalid group was specified or an unknown error has occurred.");
            }

            return(result.ToString());
        }
Example #3
0
        public static string Write(ArcadeUser user, bool isSelf = true, int page = 0, int pageSize = 25)
        {
            var result = new StringBuilder();

            List <KeyValuePair <string, long> > stats = GetVisibleStats(user).ToList();
            int pageCount = Paginate.GetPageCount(stats.Count, pageSize);

            page = Paginate.ClampIndex(page, pageCount);

            string counter = null;

            if (pageCount > 1)
            {
                counter = $" ({Format.PageCount(page + 1, pageCount)})";
            }


            result.AppendLine(Locale.GetHeader(Headers.Stat, counter, group: isSelf ? null : user.Username));

            result.AppendLine();

            int offset = page * pageSize;
            int i      = 0;

            foreach ((string id, long value) in stats.Skip(offset))
            {
                if (i >= pageSize)
                {
                    break;
                }

                result.AppendLine($"`{id}`: {value}");
                i++;
            }

            if (i == 0)
            {
                result.Append("> There doesn't seem to be any visible stats here.");
            }

            return(result.ToString());
        }