diff --git a/AideDeJeu.sln b/AideDeJeu.sln index a81e28ac..12eba4d0 100644 --- a/AideDeJeu.sln +++ b/AideDeJeu.sln @@ -12,6 +12,9 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeu", "AideDeJeu\AideDeJeu\AideDeJeu.csproj", "{C0597D88-5C09-4314-80A3-64712B02D0E9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeuWeb", "AideDeJeu\AideDeJeuWeb\AideDeJeuWeb.csproj", "{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}" + ProjectSection(ProjectDependencies) = postProject + {C0597D88-5C09-4314-80A3-64712B02D0E9} = {C0597D88-5C09-4314-80A3-64712B02D0E9} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeuCmd", "AideDeJeu\AideDeJeuCmd\AideDeJeuCmd.csproj", "{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}" ProjectSection(ProjectDependencies) = postProject diff --git a/AideDeJeu/AideDeJeu/App.xaml.cs b/AideDeJeu/AideDeJeu/App.xaml.cs index 34568aa8..469e0c1a 100644 --- a/AideDeJeu/AideDeJeu/App.xaml.cs +++ b/AideDeJeu/AideDeJeu/App.xaml.cs @@ -1,5 +1,5 @@ using System; - +using AideDeJeu.ViewModels; using AideDeJeu.Views; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -14,7 +14,11 @@ namespace AideDeJeu { InitializeComponent(); - MainPage = new MainPage(); + DependencyService.Register(); + var vm = DependencyService.Get(); + var mainPage = new MainPage(); + vm.Navigator = new Navigator(mainPage.Detail.Navigation); + MainPage = mainPage; } protected override void OnStart () diff --git a/AideDeJeu/AideDeJeu/Tools/Converters.cs b/AideDeJeu/AideDeJeu/Tools/Converters.cs index e2fd00a7..6edf28c9 100644 --- a/AideDeJeu/AideDeJeu/Tools/Converters.cs +++ b/AideDeJeu/AideDeJeu/Tools/Converters.cs @@ -1,4 +1,5 @@ -using HtmlAgilityPack; +using AideDeJeu.ViewModels; +using HtmlAgilityPack; using System; using System.Collections.Generic; using System.Globalization; @@ -96,12 +97,12 @@ namespace AideDeJeu.Tools public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - var itemType = value as ViewModels.MainViewModel.ItemType?; - if (itemType == ViewModels.MainViewModel.ItemType.Spell) + var itemType = value as ItemType?; + if (itemType == ItemType.Spell) { return SpellsTemplate; } - if (itemType == ViewModels.MainViewModel.ItemType.Monster) + if (itemType == ItemType.Monster) { return MonstersTemplate; } @@ -121,12 +122,12 @@ namespace AideDeJeu.Tools public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - var itemType = value as ViewModels.MainViewModel.ItemType?; - if (itemType == ViewModels.MainViewModel.ItemType.Spell) + var itemType = value as ItemType?; + if (itemType == ItemType.Spell) { return Spells; } - if (itemType == ViewModels.MainViewModel.ItemType.Monster) + if (itemType == ItemType.Monster) { return Monsters; } @@ -140,4 +141,81 @@ namespace AideDeJeu.Tools } public class ItemTypeToStringConverter : ItemTypeConverter { } + + + public class ItemSourceTypeConverter : IValueConverter + { + public T SpellVF { get; set; } + public T SpellVO { get; set; } + public T SpellHD { get; set; } + public T MonsterVF { get; set; } + public T MonsterVO { get; set; } + public T MonsterHD { get; set; } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + //var itemType = value as ItemSourceType?; + //if (itemType == ItemSourceType.SpellVF) + //{ + // return SpellVF; + //} + //if (itemType == ItemSourceType.SpellVO) + //{ + // return SpellVO; + //} + //if (itemType == ItemSourceType.SpellHD) + //{ + // return SpellHD; + //} + //if (itemType == ItemSourceType.MonsterVF) + //{ + // return MonsterVF; + //} + //if (itemType == ItemSourceType.MonsterVO) + //{ + // return MonsterVO; + //} + //if (itemType == ItemSourceType.MonsterHD) + //{ + // return MonsterHD; + //} + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } + + public class ItemSourceTypeToItemsConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var vm = DependencyService.Get(); + var itemSourceType = vm.ItemSourceType; + return vm.GetItemsViewModel(itemSourceType); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } + + public class ItemSourceTypeToFilterConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var vm = DependencyService.Get(); + var itemSourceType = vm.ItemSourceType; + return vm.GetFilterViewModel(itemSourceType); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } + } diff --git a/AideDeJeu/AideDeJeu/Tools/Helpers.cs b/AideDeJeu/AideDeJeu/Tools/Helpers.cs new file mode 100644 index 00000000..aca83287 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Tools/Helpers.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; + +namespace AideDeJeu.Tools +{ + public static class Helpers + { + public static T GetResourceObject(string resourceName) where T : class + { + var serializer = new DataContractJsonSerializer(typeof(T)); + var assembly = typeof(Helpers).GetTypeInfo().Assembly; + using (var stream = assembly.GetManifestResourceStream(resourceName)) + { + return serializer.ReadObject(stream) as T; + } + } + } +} diff --git a/AideDeJeu/AideDeJeu/ViewModels/BaseViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BaseViewModel.cs index 26d76dcb..4d9cef29 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/BaseViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/BaseViewModel.cs @@ -12,8 +12,13 @@ namespace AideDeJeu.ViewModels { public class BaseViewModel : INotifyPropertyChanged { - //public SpellsScrappers SpellsScrappers => DependencyService.Get() ?? new SpellsScrappers(); - //public MonstersScrappers MonstersScrappers => DependencyService.Get() ?? new MonstersScrappers(); + public MainViewModel Main + { + get + { + return DependencyService.Get(); + } + } bool isBusy = false; public bool IsBusy diff --git a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs new file mode 100644 index 00000000..00d95861 --- /dev/null +++ b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs @@ -0,0 +1,310 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Input; + +namespace AideDeJeu.ViewModels +{ + public abstract class FilterViewModel : BaseViewModel + { + public ICommand LoadItemsCommand { get; protected set; } + } + + #region Spells + public abstract class SpellFilterViewModel : FilterViewModel + { + public abstract List> Classes { get; } + + public abstract List> Niveaux { get; } + + public abstract List> Ecoles { get; } + + public abstract List> Rituels { get; } + + public abstract List> Sources { get; } + + + private int _Classe = 0; + public int Classe + { + get + { + return _Classe; + } + set + { + if (_Classe != value) + { + SetProperty(ref _Classe, value); + LoadItemsCommand.Execute(null); + } + } + } + private int _NiveauMin = 0; + public int NiveauMin + { + get + { + return _NiveauMin; + } + set + { + if (_NiveauMin != value) + { + SetProperty(ref _NiveauMin, value); + if (_NiveauMax < _NiveauMin) + { + SetProperty(ref _NiveauMax, value, nameof(NiveauMax)); + } + LoadItemsCommand.Execute(null); + } + } + } + private int _NiveauMax = 9; + public int NiveauMax + { + get + { + return _NiveauMax; + } + set + { + if (_NiveauMax != value) + { + SetProperty(ref _NiveauMax, value); + if (_NiveauMax < _NiveauMin) + { + SetProperty(ref _NiveauMin, value, nameof(NiveauMin)); + } + LoadItemsCommand.Execute(null); + } + } + } + private int _Ecole = 0; + public int Ecole + { + get + { + return _Ecole; + } + set + { + if (_Ecole != value) + { + SetProperty(ref _Ecole, value); + LoadItemsCommand.Execute(null); + } + } + } + private int _Rituel = 0; + public int Rituel + { + get + { + return _Rituel; + } + set + { + if (_Rituel != value) + { + SetProperty(ref _Rituel, value); + LoadItemsCommand.Execute(null); + } + } + } + private int _Source = 1; + public int Source + { + get + { + return _Source; + } + set + { + if (_Source != value) + { + SetProperty(ref _Source, value); + LoadItemsCommand.Execute(null); + } + } + } + + } + + public class VFSpellFilterViewModel : SpellFilterViewModel + { + + public override List> Classes { get; } = new List>() + { + new KeyValuePair("", "Toutes" ), + new KeyValuePair("Barde", "Barde" ), + new KeyValuePair("Clerc", "Clerc" ), + new KeyValuePair("Druide", "Druide" ), + new KeyValuePair("Ensorceleur", "Ensorceleur" ), + new KeyValuePair("Magicien", "Magicien" ), + new KeyValuePair("Paladin", "Paladin" ), + new KeyValuePair("Rôdeur", "Rôdeur" ), + new KeyValuePair("Sorcier", "Sorcier" ), + }; + + public override List> Niveaux { get; } = new List>() + { + new KeyValuePair("0", "Sorts mineurs"), + new KeyValuePair("1", "Niveau 1"), + new KeyValuePair("2", "Niveau 2"), + new KeyValuePair("3", "Niveau 3"), + new KeyValuePair("4", "Niveau 4"), + new KeyValuePair("5", "Niveau 5"), + new KeyValuePair("6", "Niveau 6"), + new KeyValuePair("7", "Niveau 7"), + new KeyValuePair("8", "Niveau 8"), + new KeyValuePair("9", "Niveau 9"), + }; + + public override List> Ecoles { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("abjuration", "Abjuration"), + new KeyValuePair("divination", "Divination"), + new KeyValuePair("enchantement", "Enchantement"), + new KeyValuePair("évocation", "Évocation"), + new KeyValuePair("illusion", "Illusion"), + new KeyValuePair("invocation", "Invocation"), + new KeyValuePair("cromancie", "Nécromancie"), + new KeyValuePair("transmutation", "Transmutation"), + }; + + public override List> Rituels { get; } = new List>() + { + new KeyValuePair("", "Tous"), + new KeyValuePair("(rituel)", "Rituel"), + }; + + public override List> Sources { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("(SRD)", "SRD"), + }; + + } + + public class VOSpellFilterViewModel : SpellFilterViewModel + { + public override List> Classes { get; } = new List>() + { + new KeyValuePair("", "All" ), + new KeyValuePair("Bard", "Bard" ), + new KeyValuePair("Cleric", "Cleric" ), + new KeyValuePair("Druid", "Druid" ), + new KeyValuePair("Ensorceleur", "Ensorceleur" ), + new KeyValuePair("Wizard", "Wizard" ), + new KeyValuePair("Paladin", "Paladin" ), + new KeyValuePair("Rôdeur", "Rôdeur" ), + new KeyValuePair("Sorcier", "Sorcier" ), + }; + + public override List> Niveaux { get; } = new List>() + { + new KeyValuePair("0", "Sorts mineurs"), + new KeyValuePair("1", "Level 1"), + new KeyValuePair("2", "Level 2"), + new KeyValuePair("3", "Level 3"), + new KeyValuePair("4", "Level 4"), + new KeyValuePair("5", "Level 5"), + new KeyValuePair("6", "Level 6"), + new KeyValuePair("7", "Level 7"), + new KeyValuePair("8", "Level 8"), + new KeyValuePair("9", "Level 9"), + }; + + public override List> Ecoles { get; } = new List>() + { + new KeyValuePair("", "All"), + new KeyValuePair("abjuration", "Abjuration"), + new KeyValuePair("divination", "Divination"), + new KeyValuePair("enchantement", "Enchantement"), + new KeyValuePair("évocation", "Evocation"), + new KeyValuePair("illusion", "Illusion"), + new KeyValuePair("invocation", "Invocation"), + new KeyValuePair("necromancie", "Necromancie"), + new KeyValuePair("transmutation", "Transmutation"), + }; + + public override List> Rituels { get; } = new List>() + { + new KeyValuePair("", "All"), + new KeyValuePair("(rituel)", "Rituel"), + }; + + public override List> Sources { get; } = new List>() + { + new KeyValuePair("", "All"), + new KeyValuePair("(SRD)", "SRD"), + }; + } + + public class HDSpellFilterViewModel : SpellFilterViewModel + { + public override List> Classes { get; } = new List>() + { + new KeyValuePair("", "Toutes" ), + new KeyValuePair("Barde", "Barde" ), + new KeyValuePair("Clerc", "Clerc" ), + new KeyValuePair("Druide", "Druide" ), + new KeyValuePair("Ensorceleur", "Ensorceleur" ), + new KeyValuePair("Magicien", "Magicien" ), + new KeyValuePair("Ombrelame", "Ombrelame" ), + new KeyValuePair("Paladin", "Paladin" ), + new KeyValuePair("Rôdeur", "Rôdeur" ), + new KeyValuePair("Sorcier", "Sorcier" ), + }; + + public override List> Niveaux { get; } = new List>() + { + new KeyValuePair("0", "Sorts mineurs"), + new KeyValuePair("1", "Niveau 1"), + new KeyValuePair("2", "Niveau 2"), + new KeyValuePair("3", "Niveau 3"), + new KeyValuePair("4", "Niveau 4"), + new KeyValuePair("5", "Niveau 5"), + new KeyValuePair("6", "Niveau 6"), + new KeyValuePair("7", "Niveau 7"), + new KeyValuePair("8", "Niveau 8"), + new KeyValuePair("9", "Niveau 9"), + }; + + public override List> Ecoles { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("abjuration", "Abjuration"), + new KeyValuePair("divination", "Divination"), + new KeyValuePair("enchantement", "Enchantement"), + new KeyValuePair("évocation", "Évocation"), + new KeyValuePair("illusion", "Illusion"), + new KeyValuePair("invocation", "Invocation"), + new KeyValuePair("cromancie", "Nécromancie"), + new KeyValuePair("transmutation", "Transmutation"), + }; + + public override List> Rituels { get; } = new List>() + { + new KeyValuePair("", "Tous"), + new KeyValuePair("(rituel)", "Rituel"), + }; + + public override List> Sources { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("(SRD)", "SRD"), + new KeyValuePair("(HD)", "H&D"), + }; + } + #endregion Spells + + #region Monsters + public class MonsterFilterViewModel : FilterViewModel + { + + } + #endregion Monsters +} diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index 884bc303..65740d26 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -8,44 +8,41 @@ namespace AideDeJeu.ViewModels { public abstract class ItemsViewModel : BaseViewModel { - public ItemsViewModel(INavigator navigator, ObservableCollection items) + public ItemsViewModel() { - Navigator = navigator; - Items = items; - LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync()); + LoadItemsCommand = new Command(() => ExecuteLoadItemsCommand(null)); } protected ObservableCollection AllItems { get; set; } = new ObservableCollection(); - public ObservableCollection Items { get; protected set; } public ICommand LoadItemsCommand { get; protected set; } - public abstract Task ExecuteLoadItemsCommandAsync(); + public abstract void ExecuteLoadItemsCommand(FilterViewModel filterViewModel); public abstract Task ExecuteGotoItemCommandAsync(Item item); protected INavigator Navigator { get; set; } - private string _SearchText = ""; - public string SearchText - { - get - { - return _SearchText; - } - set - { - SetProperty(ref _SearchText, value); - FilterItems(); - } - } + //private string _SearchText = ""; + //public string SearchText + //{ + // get + // { + // return _SearchText; + // } + // set + // { + // SetProperty(ref _SearchText, value); + // FilterItems(); + // } + //} - public void FilterItems() - { - Items.Clear(); - foreach (var item in AllItems) - { - if (item.NamePHB.ToLower().Contains(SearchText.ToLower())) - { - Items.Add(item); - } - } - } + //public void FilterItems() + //{ + // Items.Clear(); + // foreach (var item in AllItems) + // { + // if (item.NamePHB.ToLower().Contains(SearchText.ToLower())) + // { + // Items.Add(item); + // } + // } + //} } diff --git a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs index 3fddf05b..53c68dbd 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs @@ -1,51 +1,118 @@ using AideDeJeuLib; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using Xamarin.Forms; namespace AideDeJeu.ViewModels { + public enum ItemType + { + Spell, + Monster, + } + + public enum ItemSource + { + VF, + VO, + HD + } + + [Flags] + public enum ItemSourceType + { + Spell = 0x01, + Monster = 0x10, + VF = 0x0100, + VO = 0x1100, + HD = 0x1000, + SpellVF = Spell | VF, + SpellVO = Spell | VO, + SpellHD = Spell | HD, + MonsterVF = Monster | VF, + MonsterVO = Monster | VO, + MonsterHD = Monster | HD, + } + public class MainViewModel : BaseViewModel { - public enum ItemType - { - Spell, - Monster, - } - public SpellsViewModel Spells { get; private set; } - public MonstersViewModel Monsters { get; private set; } - - private ItemType _ItemsType = ItemType.Spell; - public ItemType ItemsType + private ItemSourceType _ItemSourceType = ItemSourceType.SpellVF; + public ItemSourceType ItemSourceType { get { - return _ItemsType; + return _ItemSourceType; } set { - CurrentViewModel.SearchText = ""; - SetProperty(ref _ItemsType, value); - CurrentViewModel.SearchText = ""; - OnPropertyChanged(nameof(CurrentViewModel)); - LoadItemsCommand.Execute(null); + //CurrentViewModel.SearchText = ""; + SetProperty(ref _ItemSourceType, value); + //CurrentViewModel.SearchText = ""; + OnPropertyChanged(nameof(Items)); + //LoadItemsCommand.Execute(null); } } - public ItemsViewModel CurrentViewModel + //private ItemSource _ItemsSource = ItemSource.VF; + //public ItemSource ItemsSource + //{ + // get + // { + // return _ItemsSource; + // } + // set + // { + // //CurrentViewModel.SearchText = ""; + // SetProperty(ref _ItemsSource, value); + // //CurrentViewModel.SearchText = ""; + // //OnPropertyChanged(nameof(CurrentViewModel)); + // LoadItemsCommand.Execute(null); + // } + //} + + public Dictionary> AllItemsViewModel = new Dictionary>() { - get - { - if (ItemsType == ItemType.Spell) - { - return Spells; - } - if (ItemsType == ItemType.Monster) - { - return Monsters; - } - return null; - } + { ItemSourceType.SpellVF, new Lazy(() => new SpellsViewModel()) }, + }; + + public ItemsViewModel GetItemsViewModel(ItemSourceType itemSourceType) + { + return AllItemsViewModel[itemSourceType].Value; } + + public Dictionary> AllFiltersViewModel = new Dictionary>() + { + { ItemSourceType.SpellVF, new Lazy(() => new VFSpellFilterViewModel()) }, + }; + + public FilterViewModel GetFilterViewModel(ItemSourceType itemSourceType) + { + return AllFiltersViewModel[itemSourceType].Value; + } + + //public ItemsViewModel SpellsVF + //{ + // get + // { + // return AllItemsViewModel[ItemSourceType.SpellVF].Value; + // } + //} + //public ItemsViewModel CurrentViewModel + //{ + // get + // { + // if (ItemsType == ItemType.Spell) + // { + // return Spells; + // } + // if (ItemsType == ItemType.Monster) + // { + // return Monsters; + // } + // return null; + // } + //} public ObservableCollection Items { get; private set; } = new ObservableCollection(); private Item _SelectedItem; @@ -58,7 +125,10 @@ namespace AideDeJeu.ViewModels set { SetProperty(ref _SelectedItem, value); - GotoItemCommand.Execute(_SelectedItem); + if (_SelectedItem != null) + { + GotoItemCommand.Execute(_SelectedItem); + } } } @@ -70,16 +140,17 @@ namespace AideDeJeu.ViewModels public Command AboutCommand { get; private set; } public Command SearchCommand { get; private set; } - public MainViewModel(INavigator navigator) + public Navigator Navigator { get; set; } + public MainViewModel() { - Spells = new SpellsViewModel(navigator, Items); - Monsters = new MonstersViewModel(navigator, Items); - LoadItemsCommand = new Command(async () => await CurrentViewModel.ExecuteLoadItemsCommandAsync()); - GotoItemCommand = new Command(async (item) => await CurrentViewModel.ExecuteGotoItemCommandAsync(item)); - SwitchToSpells = new Command(() => ItemsType = ItemType.Spell); - SwitchToMonsters = new Command(() => ItemsType = ItemType.Monster); - AboutCommand = new Command(async() => await navigator.GotoAboutPageAsync()); - SearchCommand = new Command((text) => CurrentViewModel.SearchText = text); + //Spells = new SpellsViewModel(navigator, Items); + //Monsters = new MonstersViewModel(navigator, Items); + LoadItemsCommand = new Command(async () => GetItemsViewModel(ItemSourceType).ExecuteLoadItemsCommand(GetFilterViewModel(ItemSourceType))); + GotoItemCommand = new Command(async (item) => await GetItemsViewModel(ItemSourceType).ExecuteGotoItemCommandAsync(item)); + SwitchToSpells = new Command(() => ItemSourceType = (ItemSourceType & ~ ItemSourceType.Monster) | ItemSourceType.Spell); + SwitchToMonsters = new Command(() => ItemSourceType = (ItemSourceType & ~ItemSourceType.Spell) | ItemSourceType.Monster); + //AboutCommand = new Command(async() => await navigator.GotoAboutPageAsync()); + //SearchCommand = new Command((text) => GetItemsViewModel(ItemSourceType).SearchText = text); } } } \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs index f5596539..4f0e0904 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs @@ -224,14 +224,6 @@ namespace AideDeJeu.ViewModels } - public MonstersViewModel(INavigator navigator, ObservableCollection items) - : base(navigator, items) - { - } - - - - private IEnumerable _AllMonsters = null; private IEnumerable AllMonsters @@ -267,7 +259,7 @@ namespace AideDeJeu.ViewModels } - public override async Task ExecuteLoadItemsCommandAsync() + public override void ExecuteLoadItemsCommand(FilterViewModel filterViewModel) { if (IsBusy) return; @@ -289,7 +281,7 @@ namespace AideDeJeu.ViewModels { AllItems.Add(item); } - FilterItems(); + //FilterItems(); } catch (Exception ex) { diff --git a/AideDeJeu/AideDeJeu/ViewModels/SpellsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/SpellsViewModel.cs index d912a30d..9b71afc1 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/SpellsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/SpellsViewModel.cs @@ -14,171 +14,6 @@ namespace AideDeJeu.ViewModels { public class SpellsViewModel : ItemsViewModel { - public List> Classes { get; set; } = new List>() - { - new KeyValuePair("", "Toutes" ), - new KeyValuePair("Barde", "Barde" ), - new KeyValuePair("Clerc", "Clerc" ), - new KeyValuePair("Druide", "Druide" ), - new KeyValuePair("Ensorceleur", "Ensorceleur" ), - new KeyValuePair("Magicien", "Magicien" ), - new KeyValuePair("Paladin", "Paladin" ), - new KeyValuePair("Rôdeur", "Rôdeur" ), - new KeyValuePair("Sorcier", "Sorcier" ), - }; - - public List> Niveaux { get; set; } = new List>() - { - new KeyValuePair("0", "Sorts mineurs"), - new KeyValuePair("1", "Niveau 1"), - new KeyValuePair("2", "Niveau 2"), - new KeyValuePair("3", "Niveau 3"), - new KeyValuePair("4", "Niveau 4"), - new KeyValuePair("5", "Niveau 5"), - new KeyValuePair("6", "Niveau 6"), - new KeyValuePair("7", "Niveau 7"), - new KeyValuePair("8", "Niveau 8"), - new KeyValuePair("9", "Niveau 9"), - }; - - public List> Ecoles { get; set; } = new List>() - { - new KeyValuePair("", "Toutes"), - new KeyValuePair("abjuration", "Abjuration"), - new KeyValuePair("divination", "Divination"), - new KeyValuePair("enchantement", "Enchantement"), - new KeyValuePair("évocation", "Évocation"), - new KeyValuePair("illusion", "Illusion"), - new KeyValuePair("invocation", "Invocation"), - new KeyValuePair("cromancie", "Nécromancie"), - new KeyValuePair("transmutation", "Transmutation"), - }; - - public List> Rituels { get; set; } = new List>() - { - new KeyValuePair("", "Tous"), - new KeyValuePair("(rituel)", "Rituel"), - }; - - public List> Sources { get; set; } = new List>() - { - new KeyValuePair("", "Toutes"), - new KeyValuePair("(SRD)", "SRD"), - new KeyValuePair("Player's Handbook", "PHB"), - new KeyValuePair("sup", "SCAG, XGtE"), - }; - - private int _Classe = 0; - public int Classe - { - get - { - return _Classe; - } - set - { - if (_Classe != value) - { - SetProperty(ref _Classe, value); - LoadItemsCommand.Execute(null); - } - } - } - private int _NiveauMin = 0; - public int NiveauMin - { - get - { - return _NiveauMin; - } - set - { - if (_NiveauMin != value) - { - SetProperty(ref _NiveauMin, value); - if (_NiveauMax < _NiveauMin) - { - SetProperty(ref _NiveauMax, value, nameof(NiveauMax)); - } - LoadItemsCommand.Execute(null); - } - } - } - private int _NiveauMax = 9; - public int NiveauMax - { - get - { - return _NiveauMax; - } - set - { - if (_NiveauMax != value) - { - SetProperty(ref _NiveauMax, value); - if (_NiveauMax < _NiveauMin) - { - SetProperty(ref _NiveauMin, value, nameof(NiveauMin)); - } - LoadItemsCommand.Execute(null); - } - } - } - private int _Ecole = 0; - public int Ecole - { - get - { - return _Ecole; - } - set - { - if (_Ecole != value) - { - SetProperty(ref _Ecole, value); - LoadItemsCommand.Execute(null); - } - } - } - private int _Rituel = 0; - public int Rituel - { - get - { - return _Rituel; - } - set - { - if (_Rituel != value) - { - SetProperty(ref _Rituel, value); - LoadItemsCommand.Execute(null); - } - } - } - private int _Source = 1; - public int Source - { - get - { - return _Source; - } - set - { - if (_Source != value) - { - SetProperty(ref _Source, value); - LoadItemsCommand.Execute(null); - } - } - } - - - public SpellsViewModel(INavigator navigator, ObservableCollection items) - : base(navigator, items) - { - } - private IEnumerable _AllSpells = null; private IEnumerable AllSpells { @@ -186,15 +21,16 @@ namespace AideDeJeu.ViewModels { if(_AllSpells == null) { - var serializer = new DataContractJsonSerializer(typeof(IEnumerable)); - var assembly = typeof(AboutViewModel).GetTypeInfo().Assembly; - //var names = assembly.GetManifestResourceNames(); - //using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.spells_hd.json")) - using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.spells_vf.json")) - //using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.spells_vo.json")) - { - _AllSpells = serializer.ReadObject(stream) as IEnumerable; - } + _AllSpells = Tools.Helpers.GetResourceObject>("AideDeJeu.Data.spells_vf.json"); + //var serializer = new DataContractJsonSerializer(typeof(IEnumerable)); + //var assembly = typeof(AboutViewModel).GetTypeInfo().Assembly; + ////var names = assembly.GetManifestResourceNames(); + ////using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.spells_hd.json")) + //using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.spells_vf.json")) + ////using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.spells_vo.json")) + //{ + // _AllSpells = serializer.ReadObject(stream) as IEnumerable; + //} } return _AllSpells; } @@ -216,7 +52,7 @@ namespace AideDeJeu.ViewModels } - public override async Task ExecuteLoadItemsCommandAsync() + public override void ExecuteLoadItemsCommand(FilterViewModel filterViewModel) { if (IsBusy) return; @@ -225,35 +61,15 @@ namespace AideDeJeu.ViewModels try { - AllItems.Clear(); + Main.Items.Clear(); IEnumerable items = null; - //using (var spellsScrappers = new SpellsScrappers()) - //{ - // items = await spellsScrappers.GetSpells(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key); - //} - - //ItemDatabaseHelper helper = new ItemDatabaseHelper(); - //items = await helper.GetSpellsAsync(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key); - items = GetSpells(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key); - //items = Spells; - - //try - //{ - //ItemDatabaseHelper helper = new ItemDatabaseHelper(); - //await helper.AddOrUpdateSpellsAsync(items); - //var items2 = await helper.GetSpellsAsync(); - //} - //catch(Exception ex) - //{ - // Debug.WriteLine(ex); - //} - //var aitems = items.ToArray(); - //Array.Sort(aitems, new ItemComparer()); + SpellFilterViewModel filters = filterViewModel as SpellFilterViewModel; + items = GetSpells(classe: filters.Classes[filters.Classe].Key, niveauMin: filters.Niveaux[filters.NiveauMin].Key, niveauMax: filters.Niveaux[filters.NiveauMax].Key, ecole: filters.Ecoles[filters.Ecole].Key, rituel: filters.Rituels[filters.Rituel].Key, source: filters.Sources[filters.Source].Key); foreach (var item in items) { - AllItems.Add(item); + Main.Items.Add(item); } - FilterItems(); + //FilterItems(); } catch (Exception ex) { @@ -267,7 +83,7 @@ namespace AideDeJeu.ViewModels public override async Task ExecuteGotoItemCommandAsync(Item item) { - await Navigator.GotoSpellDetailPageAsync(item as Spell); + await Main.Navigator.GotoSpellDetailPageAsync(item as Spell); } } diff --git a/AideDeJeu/AideDeJeu/Views/MainPage.xaml b/AideDeJeu/AideDeJeu/Views/MainPage.xaml index beea7378..01522a73 100644 --- a/AideDeJeu/AideDeJeu/Views/MainPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/MainPage.xaml @@ -37,9 +37,6 @@ - - @@ -74,6 +68,10 @@ x:Key="ItemsTypeTemplateConverter" SpellsTemplate="{StaticResource SpellsMasterDataTemplate}" MonstersTemplate="{StaticResource MonstersMasterDataTemplate}" /> + + @@ -96,26 +94,26 @@ - - - + + - diff --git a/AideDeJeu/AideDeJeu/Views/MainPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/MainPage.xaml.cs index b85d6d92..0bef7734 100644 --- a/AideDeJeu/AideDeJeu/Views/MainPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/MainPage.xaml.cs @@ -11,22 +11,32 @@ namespace AideDeJeu.Views [XamlCompilation(XamlCompilationOptions.Compile)] public partial class MainPage : MasterDetailPage { - MainViewModel viewModel; - INavigator Navigator; + MainViewModel Main + { + get + { + return DependencyService.Get(); + } + } + //INavig//ator Navigator; public MainPage () { InitializeComponent (); - Navigator = new Navigator((Detail as NavigationPage).Navigation); - BindingContext = viewModel = new MainViewModel(Navigator); + + //DependencyService.Register(new Navigator((Detail as NavigationPage).Navigation)); + + //Navigator = new Navigator((Detail as NavigationPage).Navigation); + //BindingContext = viewModel = new MainViewModel(Navigator); + BindingContext = Main; } protected override void OnAppearing() { base.OnAppearing(); - if (viewModel.Items.Count == 0) - viewModel.LoadItemsCommand.Execute(null); + if (Main.Items.Count == 0) + Main.LoadItemsCommand.Execute(null); } private void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e) diff --git a/AideDeJeu/AideDeJeuWeb/AideDeJeuWeb.csproj b/AideDeJeu/AideDeJeuWeb/AideDeJeuWeb.csproj index 223f2122..ab4e9fd3 100644 --- a/AideDeJeu/AideDeJeuWeb/AideDeJeuWeb.csproj +++ b/AideDeJeu/AideDeJeuWeb/AideDeJeuWeb.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs b/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs index 20938d5b..b9567f65 100644 --- a/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs +++ b/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Threading.Tasks; using AideDeJeuLib.Cards; using AideDeJeuLib.Spells;