Ejemplo n.º 1
0
        private async Task PopulateGridsAsync()
        {
            SkillsDataGrid.Items.Clear();
            MinigamesDataGrid.Items.Clear();

            string      playerName = PlayerNameTextBox.Text.Replace(' ', '_');
            HiscoreType type       = HiscoreType.ByName(HiscoreTypeComboBox.Text);
            Hiscore     hiscore    = await parser.FetchHiscoreAsync(playerName, type);

            if (hiscore == null)
            {
                PlayerNameTextBox.Text = "There was an issue fetching stats for " + playerName;
                return;
            }

            foreach (SkillData skill in hiscore.Skills)
            {
                SkillsDataGrid.Items.Add(skill);
            }

            foreach (MinigameData minigame in hiscore.Minigames)
            {
                MinigamesDataGrid.Items.Add(minigame);
            }
        }
Ejemplo n.º 2
0
        public async Task <Hiscore> FetchHiscoreAsync(string playerName, HiscoreType type)
        {
            Hiscore hiscore  = new Hiscore();
            string  url      = string.Format(HISCORE_URL, type.UrlNode, playerName);
            string  response = await FetchAsync(url);

            if (response == null)
            {
                return(null);
            }

            string[] lines = response.TrimEnd('\n').Split('\n');

            int skillsCount = hiscore.Skills.Length;

            for (int i = 0; i < lines.Length; i++)
            {
                string[] details = lines[i].Split(',');

                if (i < skillsCount)
                {
                    SkillData skill = hiscore.Skills[i];
                    skill.Rank  = int.Parse(details[0]);
                    skill.Level = int.Parse(details[1]);
                    skill.XP    = int.Parse(details[2]);
                }
                else
                {
                    MinigameData minigame = hiscore.Minigames[i - skillsCount];
                    minigame.Rank  = int.Parse(details[0]);
                    minigame.Score = int.Parse(details[1]);
                }
            }

            return(hiscore);
        }