mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Filtres dans md
This commit is contained in:
		
							parent
							
								
									cdc8ca4a2f
								
							
						
					
					
						commit
						30bd94ddae
					
				
					 3 changed files with 54 additions and 77 deletions
				
			
		|  | @ -9,7 +9,7 @@ namespace AideDeJeuLib | ||||||
|     { |     { | ||||||
|         public override FilterViewModel GetNewFilterViewModel() |         public override FilterViewModel GetNewFilterViewModel() | ||||||
|         { |         { | ||||||
|             return new HDSpellFilterViewModel(); |             return new HDMonsterFilterViewModel(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -14,12 +14,12 @@ namespace AideDeJeu.ViewModels | ||||||
|     { |     { | ||||||
|         CancellationTokenSource cancellationTokenSource; |         CancellationTokenSource cancellationTokenSource; | ||||||
| 
 | 
 | ||||||
|         public ItemsViewModel(ItemSourceType itemSourceType) |         public ItemsViewModel() | ||||||
|         { |         { | ||||||
|             this.ItemSourceType = itemSourceType; |             //this.ItemSourceType = itemSourceType; | ||||||
|             LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync().ConfigureAwait(false)); |             LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync().ConfigureAwait(false)); | ||||||
|             Filter = Main.GetFilterViewModel(ItemSourceType); |             //Filter = Main.GetFilterViewModel(ItemSourceType); | ||||||
|             Filter.LoadItemsCommand = LoadItemsCommand; |             //Filter.LoadItemsCommand = LoadItemsCommand; | ||||||
|             SearchCommand = new Command<string>((text) => |             SearchCommand = new Command<string>((text) => | ||||||
|             { |             { | ||||||
|                 Filter.SearchText = text; |                 Filter.SearchText = text; | ||||||
|  | @ -32,19 +32,19 @@ namespace AideDeJeu.ViewModels | ||||||
|             await Main.Navigator.GotoItemDetailPageAsync(item); |             await Main.Navigator.GotoItemDetailPageAsync(item); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private ItemSourceType _ItemSourceType = ItemSourceType.SpellHD; |         //private ItemSourceType _ItemSourceType = ItemSourceType.SpellHD; | ||||||
|         public ItemSourceType ItemSourceType |         //public ItemSourceType ItemSourceType | ||||||
|         { |         //{ | ||||||
|             get |         //    get | ||||||
|             { |         //    { | ||||||
|                 return _ItemSourceType; |         //        return _ItemSourceType; | ||||||
|             } |         //    } | ||||||
|             set |         //    set | ||||||
|             { |         //    { | ||||||
|                 SetProperty(ref _ItemSourceType, value); |         //        SetProperty(ref _ItemSourceType, value); | ||||||
|                 OnPropertyChanged(nameof(Items)); |         //        OnPropertyChanged(nameof(Items)); | ||||||
|             } |         //    } | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         private FilterViewModel _Filter; |         private FilterViewModel _Filter; | ||||||
|         public FilterViewModel Filter |         public FilterViewModel Filter | ||||||
|  | @ -89,6 +89,14 @@ namespace AideDeJeu.ViewModels | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public IEnumerable<Item> 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) |         async Task LoadItemsAsync(CancellationToken cancellationToken = default) | ||||||
|         { |         { | ||||||
|  | @ -96,11 +104,10 @@ namespace AideDeJeu.ViewModels | ||||||
|             Main.IsLoading = true; |             Main.IsLoading = true; | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 var filterViewModel = Filter; |                 //var filterViewModel = Filter; | ||||||
|                 var allItems = await Main.GetAllItemsAsync(ItemSourceType); |                 //var allItems = await Main.GetAllItemsAsync(ItemSourceType); | ||||||
|                 var items = await filterViewModel.FilterItems(allItems, cancellationToken: cancellationToken); |                 var items = await Filter.FilterItems(AllItems, cancellationToken: cancellationToken); | ||||||
|                 Items = items.ToList(); |                 Items = items.ToList(); | ||||||
|                 Title = (allItems as Item)?.Name; |  | ||||||
|             } |             } | ||||||
|             catch (OperationCanceledException ex) |             catch (OperationCanceledException ex) | ||||||
|             { |             { | ||||||
|  |  | ||||||
|  | @ -29,50 +29,16 @@ namespace AideDeJeu.ViewModels | ||||||
|             set => SetProperty(ref _isLoading, value); |             set => SetProperty(ref _isLoading, value); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private Dictionary<ItemSourceType, IEnumerable<Item>> _AllItems = new Dictionary<ItemSourceType, IEnumerable<Item>>(); |         private Dictionary<string, IEnumerable<Item>> _AllItems = new Dictionary<string, IEnumerable<Item>>(); | ||||||
|         public async Task<IEnumerable<Item>> GetAllItemsAsync(ItemSourceType itemSourceType) |         public async Task<IEnumerable<Item>> GetAllItemsAsync(string source) | ||||||
|         { |         { | ||||||
|             if (!_AllItems.ContainsKey(itemSourceType)) |             if (!_AllItems.ContainsKey(source)) | ||||||
|             { |             { | ||||||
|                 string resourceName = null; |                 //var md = await Tools.Helpers.GetStringFromUrl($"https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/{source}.md"); | ||||||
|                 switch (itemSourceType) |                 var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{source}.md"); | ||||||
|                 { |                 _AllItems[source] = Tools.MarkdownExtensions.ToItem(md) as IEnumerable<Item>; | ||||||
|                     case ItemSourceType.MonsterVO: |  | ||||||
|                         { |  | ||||||
|                             resourceName = "monsters_vo"; |  | ||||||
|             } |             } | ||||||
|                         break; |             return _AllItems[source]; | ||||||
|                     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<Item>; |  | ||||||
|             } |  | ||||||
|             return _AllItems[itemSourceType]; |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -87,19 +53,23 @@ namespace AideDeJeu.ViewModels | ||||||
|         //    new KeyValuePair<ItemSourceType, string>(ItemSourceType.ConditionVO, "Conditions (VO)"), |         //    new KeyValuePair<ItemSourceType, string>(ItemSourceType.ConditionVO, "Conditions (VO)"), | ||||||
|         //}; |         //}; | ||||||
| 
 | 
 | ||||||
|         public Dictionary<ItemSourceType, Func<ItemsViewModel>> AllItemsViewModel = new Dictionary<ItemSourceType, Func<ItemsViewModel>>() |         //public Dictionary<ItemSourceType, Func<ItemsViewModel>> AllItemsViewModel = new Dictionary<ItemSourceType, Func<ItemsViewModel>>() | ||||||
|         { |         //{ | ||||||
|             { ItemSourceType.SpellVO, () => new ItemsViewModel(ItemSourceType.SpellVO) }, |         //    { ItemSourceType.SpellVO, () => new ItemsViewModel(ItemSourceType.SpellVO) }, | ||||||
|             { ItemSourceType.SpellHD, () => new ItemsViewModel(ItemSourceType.SpellHD) }, |         //    { ItemSourceType.SpellHD, () => new ItemsViewModel(ItemSourceType.SpellHD) }, | ||||||
|             { ItemSourceType.MonsterVO, () => new ItemsViewModel(ItemSourceType.MonsterVO) }, |         //    { ItemSourceType.MonsterVO, () => new ItemsViewModel(ItemSourceType.MonsterVO) }, | ||||||
|             { ItemSourceType.MonsterHD, () => new ItemsViewModel(ItemSourceType.MonsterHD) }, |         //    { ItemSourceType.MonsterHD, () => new ItemsViewModel(ItemSourceType.MonsterHD) }, | ||||||
|             { ItemSourceType.ConditionHD, () => new ItemsViewModel(ItemSourceType.ConditionHD) }, |         //    { ItemSourceType.ConditionHD, () => new ItemsViewModel(ItemSourceType.ConditionHD) }, | ||||||
|             { ItemSourceType.ConditionVO, () => new ItemsViewModel(ItemSourceType.ConditionVO) }, |         //    { ItemSourceType.ConditionVO, () => new ItemsViewModel(ItemSourceType.ConditionVO) }, | ||||||
|         }; |         //}; | ||||||
| 
 | 
 | ||||||
|         public ItemsViewModel GetItemsViewModel(ItemSourceType itemSourceType) |         public async Task<ItemsViewModel> 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<ItemSourceType, Func<FilterViewModel>> AllFiltersViewModel = new Dictionary<ItemSourceType, Func<FilterViewModel>>() |         public Dictionary<ItemSourceType, Func<FilterViewModel>> AllFiltersViewModel = new Dictionary<ItemSourceType, Func<FilterViewModel>>() | ||||||
|  | @ -190,7 +160,7 @@ namespace AideDeJeu.ViewModels | ||||||
|                     var file = match.Groups["file"].Value; |                     var file = match.Groups["file"].Value; | ||||||
|                     var anchor = match.Groups["anchor"].Value; |                     var anchor = match.Groups["anchor"].Value; | ||||||
|                     var itemSourceType = MDFileToItemSourceType(file); |                     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(); |                     var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); | ||||||
|                     if (spell != null) |                     if (spell != null) | ||||||
|                     { |                     { | ||||||
|  | @ -202,8 +172,8 @@ namespace AideDeJeu.ViewModels | ||||||
|                     var regex = new Regex("/(?<file>.*)\\.md"); |                     var regex = new Regex("/(?<file>.*)\\.md"); | ||||||
|                     var match = regex.Match(s); |                     var match = regex.Match(s); | ||||||
|                     var file = match.Groups["file"].Value; |                     var file = match.Groups["file"].Value; | ||||||
|                     var itemSourceType = MDFileToItemSourceType(file); |                     //var itemSourceType = MDFileToItemSourceType(file); | ||||||
|                     var items = GetItemsViewModel(itemSourceType); |                     var items = await GetItemsViewModelAsync(file); | ||||||
|                     items.LoadItemsCommand.Execute(null); |                     items.LoadItemsCommand.Execute(null); | ||||||
|                     await Navigator.GotoItemsPageAsync(items); |                     await Navigator.GotoItemsPageAsync(items); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez