Пример #1
0
        private async Task GetDataAsync()
        {
            if (this.Roles.Count != 0)            //HERE IS THE ANSWER. IF LOADED, DO NOT LOAD AGAIN
                return;

            Uri dataUri = new Uri("ms-appx:///DataModel/Data.json");      //Get location of data 
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);       //Get the file from where the data is located

            string jsonText = await FileIO.ReadTextAsync(file);     //Returns the json text in which it was saved as 
            JsonObject jsonObject = JsonObject.Parse(jsonText);     //Parse the json text into object 
            JsonArray jsonArray = jsonObject["Roles"].GetArray();

            foreach (JsonValue roleValue in jsonArray)
            {
                JsonObject roleObject = roleValue.GetObject();
                Role role = new Role(roleObject["UniqueId"].GetString());

                foreach (JsonValue championValue in roleObject["Champions"].GetArray())
                {
                    JsonObject championObject = championValue.GetObject();
                    var counterList = new ObservableCollection<String>();

                    foreach (JsonValue counterValue in championObject["Counters"].GetArray())
                    {
                        var counterString = counterValue.GetString();
                        counterList.Add(counterString);
                    }
                    role.Champions.Add(new Champion(championObject["UniqueId"].GetString(),
                                                       championObject["ImagePath"].GetString(),
                                                       counterList));


                }
                this.Roles.Add(role);
            }

            GetAllChampions(); //Fills up the all role immediately with json data serialization
        }
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>.
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            int id = await AdData.GetAdId();
            HelperMethods.CreateSingleAdUnit(id,"TallAd", AdGrid);
            HelperMethods.CreateAdUnits(id, "TallAd", AdGrid2, 5);

            // Setup the underlying UI 
            var champName = (string)e.NavigationParameter;
            Champion champion = DataSource.GetChampion(champName);
            champions = DataSource.GetAllChampions();
            this.DefaultViewModel["Champion"] = champion;
            this.DefaultViewModel["Role"] = DataSource.GetRoleId(champion.UniqueId);
            this.DefaultViewModel["Filter"] = champions.Champions;

            
            // If navigating via a counterpick, on loading that page, remove the previous history so the back page will go to main or role, not champion
            var prevPage = Frame.BackStack.ElementAt(Frame.BackStackDepth - 1);
            if (prevPage.SourcePageType.Equals(typeof(ChampionPage))){
                Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1);
            }

            // Champion feedback code 
            // await commentViewModel.SeedDataAsync(champions);
            // Grab the champion feedback from the server 
            await commentViewModel.GetChampionFeedbackAsync(champName);

            // Check if an there was no champion retrieved as well as an error message (must be internet connection problem)
            if (commentViewModel.ChampionFeedback == null && commentViewModel.ErrorMessage != null){
                MessageDialog messageBox = new MessageDialog("Make sure your internet connection is working and try again!");
                await messageBox.ShowAsync();
                Application.Current.Exit();
            }

           
            // Collapse the progress ring once counters have been loaded. If the ring hasn't loaded yet, set a boolean to collapse it once it loads.
            championFeedbackLoaded = true;

            if (counterLoadingRing != null)
                counterLoadingRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            if (easyMatchupLoadingRing != null)
                easyMatchupLoadingRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            if (synergyLoadingRing != null)
                synergyLoadingRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            if (counterCommentsLoadingRing != null)
                counterCommentsLoadingRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            if (playingCommentsLoadingRing != null)
                playingCommentsLoadingRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            // Check if comments exist for counter comments. If not, show a message indicating so. 
            if (commentViewModel.ChampionFeedback.Comments.Where(x => x.Page == PageEnum.CommentPage.Counter).Count() == 0) {
                if (counterMessage == null) 
                    emptyComments = true;
                else 
                    counterMessage.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            // Check if comments exist for playing comments. If not, show a message indicating so. 
            if (commentViewModel.ChampionFeedback.Comments.Where(x => x.Page == PageEnum.CommentPage.Playing).Count() == 0)
            {
                if (playingMessage == null)
                    emptyPlayingComments = true;
                else 
                    playingMessage.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            // Check if synergy champions existing. If not, show a message indicating so. 
            if (commentViewModel.ChampionFeedback.Counters.Where(x => x.Page == PageEnum.ChampionPage.Synergy).Count() == 0)
            {
                if (synergyMessage == null)
                    emptySynergyChampions = true;
                else
                    synergyMessage.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            // Make updates to champion comments observable
            this.DefaultViewModel["ChampionFeedback"] = commentViewModel.ChampionFeedback;
        }
Пример #3
0
 public static Role FilterChampions(string filter)
 {
     var matches = new Role(filter);
     foreach (var role in _DataSource.Roles)
     {
         foreach (var champion in role.Champions)
         {
             if (champion.UniqueId.ToLower().StartsWith(filter.ToLower()) && role.UniqueId != "All")
                 matches.Champions.Add(champion);
         }
     }
     matches.Champions = new ObservableCollection<Champion>(matches.Champions.OrderBy(p => p.UniqueId));
     return matches;
 }