예제 #1
0
        public ItemData GetItemById(int itemID)
        {
            var itemData = Items.Find(i => i.itemID == itemID);

            if (itemData != null)
            {
                DataDragonUtils.ExtendItemLocal(itemData, version);
            }
            return(itemData);
        }
예제 #2
0
        public SummonerSpell GetSummonerById(int summonerID)
        {
            var summonerData = SummonerSpells.Find(s => s.key == summonerID);

            if (summonerData != null)
            {
                DataDragonUtils.ExtendSummonerLocal(summonerData, version);
            }
            return(summonerData);
        }
예제 #3
0
        public Champion GetChampionById(int champID)
        {
            var champData = Champions.Find(c => c.key == champID);

            if (champData != null)
            {
                DataDragonUtils.ExtendChampionLocal(champData, version);
            }
            return(champData);
        }
예제 #4
0
        private async void InitLatest()
        {
            dynamic riotVersion = JsonConvert.DeserializeObject <dynamic>(await DataDragonUtils.GetAsync($"https://ddragon.leagueoflegends.com/realms/{Realm}.json"));

            version.CDN      = riotVersion.cdn;
            version.Champion = riotVersion.n.champion;
            version.Item     = riotVersion.n.item;
            version.Summoner = riotVersion.n.summoner;

            var oldPatch = BroadcastHubController.ClientConfig.frontend.patch;

            BroadcastHubController.ClientConfig.frontend.patch = version.Champion;
            if (oldPatch != BroadcastHubController.ClientConfig.frontend.patch)
            {
                BroadcastHubController.WriteConfig("config.json", BroadcastHubController.ClientConfig);
            }

            Init();
        }
예제 #5
0
        public async Task <bool> CheckLocalCache()
        {
            var patch   = version.Champion;
            var dlTasks = new List <Task>();

            string path        = currentDir;
            string cache       = path + "/cache";
            string patchFolder = cache + "/" + ((string)patch);
            string champ       = patchFolder + "/champion";
            string item        = patchFolder + "/item";
            string spell       = patchFolder + "/spell";

            if (!Directory.Exists(cache))
            {
                Directory.CreateDirectory(cache);
            }

            if (!Directory.Exists(patchFolder))
            {
                //Delete old patch folders
                Logging.Info("Current Patch cache not detected, removing old Patch data");

                List <string> dirs = new List <string>(Directory.EnumerateDirectories(cache));

                dirs.ForEach(dir => {
                    new DirectoryInfo(dir).Empty();
                    Directory.Delete(dir);
                    Logging.Info($"Removed Patch Cache {dir}");
                });

                Directory.CreateDirectory(patchFolder);
            }
            else
            {
                Logging.Info($"Cache {patchFolder} exists already");
                return(true);
            }

            if (!Directory.Exists(champ))
            {
                Directory.CreateDirectory(champ);
            }

            if (!Directory.Exists(item))
            {
                Directory.CreateDirectory(item);
            }

            if (!Directory.Exists(spell))
            {
                Directory.CreateDirectory(spell);
            }

            Logging.Info("Starting download process. This could take a while");

            Items.ForEach(findItem =>
            {
                DataDragonUtils.ExtendItem(findItem, version);
                dlTasks.Add(new Task(() => DataDragonUtils.DownloadFile(findItem.sprite, $"{item}/{findItem.itemID}.png")));
            });

            Champions.ForEach(findChampion => {
                DataDragonUtils.ExtendChampion(findChampion, version);
                dlTasks.Add(new Task(() => DataDragonUtils.DownloadFile(findChampion.loadingImg, $"{champ}/{findChampion.id}_loading.png")));
                dlTasks.Add(new Task(() => DataDragonUtils.DownloadFile(findChampion.splashImg, $"{champ}/{findChampion.id}_splash.png")));
                dlTasks.Add(new Task(() => DataDragonUtils.DownloadFile(findChampion.splashCenteredImg, $"{champ}/{findChampion.id}_centered_splash.png")));
                dlTasks.Add(new Task(() => DataDragonUtils.DownloadFile(findChampion.squareImg, $"{champ}/{findChampion.id}_square.png")));
            });

            SummonerSpells.ForEach(findSummoner => {
                DataDragonUtils.ExtendSummoner(findSummoner, version);
                dlTasks.Add(new Task(() => DataDragonUtils.DownloadFile(findSummoner.icon, $"{spell}/{findSummoner.id}.png")));
            });

            LoadingProgress.LoadingPopUp.IsVisible = true;
            LoadingProgress.LoadingPopUp.UpdateProgress(0, dlTasks.Count);

            Logging.Info($"Downloading {dlTasks.Count} assets from datadragon!");
            dlTasks.ForEach(t => t.Start());
            var totalTasks = dlTasks.Count;


            int total = 0;

            while (dlTasks.Any())
            {
                Task finishTask = await Task.WhenAny(dlTasks);

                dlTasks.Remove(finishTask);
                total++;
                LoadingProgress.LoadingPopUp.UpdateProgress(total, totalTasks);
            }

            Logging.Info("Download finished");
            LoadingProgress.LoadingPopUp.IsVisible = false;

            return(true);
        }
예제 #6
0
        private async void Init()
        {
            System.Diagnostics.Debug.WriteLine($"Champion: {version.Champion}, Item: {version.Item}, CDN: {version.CDN}");

            Champions = new List <Champion>(JsonConvert.DeserializeObject <dynamic>(await DataDragonUtils.GetAsync($"{version.CDN}/{version.Champion}/data/en_US/champion.json")).data.ToObject <Dictionary <string, Champion> >().Values);
            Logging.Info($"Loaded {Champions.Count} champions");

            SummonerSpells = new List <SummonerSpell>(JsonConvert.DeserializeObject <dynamic>(await DataDragonUtils.GetAsync($"{version.CDN}/{version.Item}/data/en_US/summoner.json")).data.ToObject <Dictionary <string, SummonerSpell> >().Values);
            Logging.Info($"Loaded {SummonerSpells.Count} summoner spells");

            List <KeyValuePair <int, ItemData> > rawItemData = new List <KeyValuePair <int, ItemData> >(JsonConvert.DeserializeObject <dynamic>(await DataDragonUtils.GetAsync($"{version.CDN}/{version.Item}/data/en_US/item.json")).data.ToObject <Dictionary <int, ItemData> >());

            Logging.Info($"Loaded {rawItemData.Count} items");

            rawItemData.ForEach(kvPair => {
                ItemData itemData = kvPair.Value;
                itemData.itemID   = kvPair.Key;
                if (itemData.gold.total >= Properties.Settings.Default.ItemGoldCutoff || itemData.specialRecipe != 0)
                {
                    Items.Add(itemData);
                    FullIDs.Add(itemData.itemID);
                }
            });

            Logging.Info($"Registered {Items.Count} full items");

            //Download all needed champion, item, and summoner spell data
            await CheckLocalCache();

            FinishedLoading.Invoke(this, EventArgs.Empty);
        }