diff --git a/AideDeJeu/AideDeJeu/Models/Monsters/MonstersHD.cs b/AideDeJeu/AideDeJeu/Models/Monsters/MonstersHD.cs index 69e46f96..406da8dd 100644 --- a/AideDeJeu/AideDeJeu/Models/Monsters/MonstersHD.cs +++ b/AideDeJeu/AideDeJeu/Models/Monsters/MonstersHD.cs @@ -9,7 +9,7 @@ namespace AideDeJeuLib { public override FilterViewModel GetNewFilterViewModel() { - return new HDSpellFilterViewModel(); + return new HDMonsterFilterViewModel(); } } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index f5765b8d..dfd1caec 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -14,12 +14,12 @@ namespace AideDeJeu.ViewModels { CancellationTokenSource cancellationTokenSource; - public ItemsViewModel(ItemSourceType itemSourceType) + public ItemsViewModel() { - this.ItemSourceType = itemSourceType; + //this.ItemSourceType = itemSourceType; LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync().ConfigureAwait(false)); - Filter = Main.GetFilterViewModel(ItemSourceType); - Filter.LoadItemsCommand = LoadItemsCommand; + //Filter = Main.GetFilterViewModel(ItemSourceType); + //Filter.LoadItemsCommand = LoadItemsCommand; SearchCommand = new Command((text) => { Filter.SearchText = text; @@ -32,19 +32,19 @@ namespace AideDeJeu.ViewModels await Main.Navigator.GotoItemDetailPageAsync(item); } - private ItemSourceType _ItemSourceType = ItemSourceType.SpellHD; - public ItemSourceType ItemSourceType - { - get - { - return _ItemSourceType; - } - set - { - SetProperty(ref _ItemSourceType, value); - OnPropertyChanged(nameof(Items)); - } - } + //private ItemSourceType _ItemSourceType = ItemSourceType.SpellHD; + //public ItemSourceType ItemSourceType + //{ + // get + // { + // return _ItemSourceType; + // } + // set + // { + // SetProperty(ref _ItemSourceType, value); + // OnPropertyChanged(nameof(Items)); + // } + //} private FilterViewModel _Filter; public FilterViewModel Filter @@ -89,6 +89,14 @@ namespace AideDeJeu.ViewModels } } + public IEnumerable AllItems; + public async Task InitAsync() + { + //AllItems = await Main.GetAllItemsAsync(ItemSourceType); + Title = (AllItems as Item)?.Name; + Filter = (AllItems as Items).GetNewFilterViewModel(); //Main.GetFilterViewModel(ItemSourceType); + Filter.LoadItemsCommand = LoadItemsCommand; + } async Task LoadItemsAsync(CancellationToken cancellationToken = default) { @@ -96,11 +104,10 @@ namespace AideDeJeu.ViewModels Main.IsLoading = true; try { - var filterViewModel = Filter; - var allItems = await Main.GetAllItemsAsync(ItemSourceType); - var items = await filterViewModel.FilterItems(allItems, cancellationToken: cancellationToken); + //var filterViewModel = Filter; + //var allItems = await Main.GetAllItemsAsync(ItemSourceType); + var items = await Filter.FilterItems(AllItems, cancellationToken: cancellationToken); Items = items.ToList(); - Title = (allItems as Item)?.Name; } catch (OperationCanceledException ex) { diff --git a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs index 1e2a57fc..7acb2428 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs @@ -29,50 +29,16 @@ namespace AideDeJeu.ViewModels set => SetProperty(ref _isLoading, value); } - private Dictionary> _AllItems = new Dictionary>(); - public async Task> GetAllItemsAsync(ItemSourceType itemSourceType) + private Dictionary> _AllItems = new Dictionary>(); + public async Task> GetAllItemsAsync(string source) { - if (!_AllItems.ContainsKey(itemSourceType)) + if (!_AllItems.ContainsKey(source)) { - string resourceName = null; - switch (itemSourceType) - { - case ItemSourceType.MonsterVO: - { - resourceName = "monsters_vo"; - } - break; - case ItemSourceType.MonsterHD: - { - resourceName = "monsters_hd"; - } - break; - case ItemSourceType.SpellVO: - { - resourceName = "spells_vo"; - } - break; - case ItemSourceType.SpellHD: - { - resourceName = "spells_hd"; - } - break; - case ItemSourceType.ConditionVO: - { - resourceName = "conditions_vo"; - } - break; - case ItemSourceType.ConditionHD: - { - resourceName = "conditions_hd"; - } - break; - } - //var md = await Tools.Helpers.GetStringFromUrl($"https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/{resourceName}.md"); - var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{resourceName}.md"); - _AllItems[itemSourceType] = Tools.MarkdownExtensions.ToItem(md) as IEnumerable; + //var md = await Tools.Helpers.GetStringFromUrl($"https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/{source}.md"); + var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{source}.md"); + _AllItems[source] = Tools.MarkdownExtensions.ToItem(md) as IEnumerable; } - return _AllItems[itemSourceType]; + return _AllItems[source]; } @@ -87,19 +53,23 @@ namespace AideDeJeu.ViewModels // new KeyValuePair(ItemSourceType.ConditionVO, "Conditions (VO)"), //}; - public Dictionary> AllItemsViewModel = new Dictionary>() - { - { ItemSourceType.SpellVO, () => new ItemsViewModel(ItemSourceType.SpellVO) }, - { ItemSourceType.SpellHD, () => new ItemsViewModel(ItemSourceType.SpellHD) }, - { ItemSourceType.MonsterVO, () => new ItemsViewModel(ItemSourceType.MonsterVO) }, - { ItemSourceType.MonsterHD, () => new ItemsViewModel(ItemSourceType.MonsterHD) }, - { ItemSourceType.ConditionHD, () => new ItemsViewModel(ItemSourceType.ConditionHD) }, - { ItemSourceType.ConditionVO, () => new ItemsViewModel(ItemSourceType.ConditionVO) }, - }; + //public Dictionary> AllItemsViewModel = new Dictionary>() + //{ + // { ItemSourceType.SpellVO, () => new ItemsViewModel(ItemSourceType.SpellVO) }, + // { ItemSourceType.SpellHD, () => new ItemsViewModel(ItemSourceType.SpellHD) }, + // { ItemSourceType.MonsterVO, () => new ItemsViewModel(ItemSourceType.MonsterVO) }, + // { ItemSourceType.MonsterHD, () => new ItemsViewModel(ItemSourceType.MonsterHD) }, + // { ItemSourceType.ConditionHD, () => new ItemsViewModel(ItemSourceType.ConditionHD) }, + // { ItemSourceType.ConditionVO, () => new ItemsViewModel(ItemSourceType.ConditionVO) }, + //}; - public ItemsViewModel GetItemsViewModel(ItemSourceType itemSourceType) + public async Task GetItemsViewModelAsync(string source) { - return AllItemsViewModel[itemSourceType].Invoke(); + var allItems = await GetAllItemsAsync(source); + var itemsViewModel = new ItemsViewModel(); //AllItemsViewModel[source].Invoke(); + itemsViewModel.AllItems = allItems; + await itemsViewModel.InitAsync(); + return itemsViewModel; } public Dictionary> AllFiltersViewModel = new Dictionary>() @@ -190,7 +160,7 @@ namespace AideDeJeu.ViewModels var file = match.Groups["file"].Value; var anchor = match.Groups["anchor"].Value; var itemSourceType = MDFileToItemSourceType(file); - var spells = await GetAllItemsAsync(itemSourceType); + var spells = await GetAllItemsAsync(file); var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); if (spell != null) { @@ -202,8 +172,8 @@ namespace AideDeJeu.ViewModels var regex = new Regex("/(?.*)\\.md"); var match = regex.Match(s); var file = match.Groups["file"].Value; - var itemSourceType = MDFileToItemSourceType(file); - var items = GetItemsViewModel(itemSourceType); + //var itemSourceType = MDFileToItemSourceType(file); + var items = await GetItemsViewModelAsync(file); items.LoadItemsCommand.Execute(null); await Navigator.GotoItemsPageAsync(items); }