From 2c0d222a03d29edfc592924198d189e55e47c45f Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Mon, 28 May 2018 09:18:25 +0200 Subject: [PATCH] Recablage Monsters --- AideDeJeu/AideDeJeu/Tools/Comparers.cs | 2 +- .../AideDeJeu/ViewModels/FilterViewModel.cs | 459 +++++++++++++++++- .../AideDeJeu/ViewModels/ItemsViewModel.cs | 2 - .../AideDeJeu/ViewModels/MainViewModel.cs | 55 +-- .../AideDeJeu/ViewModels/MonstersViewModel.cs | 243 +--------- 5 files changed, 491 insertions(+), 270 deletions(-) diff --git a/AideDeJeu/AideDeJeu/Tools/Comparers.cs b/AideDeJeu/AideDeJeu/Tools/Comparers.cs index fd164f8d..6141d6c1 100644 --- a/AideDeJeu/AideDeJeu/Tools/Comparers.cs +++ b/AideDeJeu/AideDeJeu/Tools/Comparers.cs @@ -19,7 +19,7 @@ namespace AideDeJeu.Tools { public override int Compare(string x, string y) { - var regex = new Regex(@"\((?\d*?) PX\)"); + var regex = new Regex(@"\((?\d*?) (PX|XP)\)"); int xpx = int.Parse(regex.Match(x).Groups["xp"].Value); int xpy = int.Parse(regex.Match(y).Groups["xp"].Value); return xpx - xpy; diff --git a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs index 00d95861..f7e15214 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs @@ -1,5 +1,10 @@ -using System; +using AideDeJeu.Tools; +using AideDeJeuLib; +using AideDeJeuLib.Monsters; +using AideDeJeuLib.Spells; +using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Windows.Input; @@ -8,11 +13,36 @@ namespace AideDeJeu.ViewModels public abstract class FilterViewModel : BaseViewModel { public ICommand LoadItemsCommand { get; protected set; } + public abstract IEnumerable FilterItems(IEnumerable items); } #region Spells public abstract class SpellFilterViewModel : FilterViewModel { + public override IEnumerable FilterItems(IEnumerable items) + { + var classe = Classes[Classe].Key; + var niveauMin = Niveaux[NiveauMin].Key; + var niveauMax = Niveaux[NiveauMax].Key; + var ecole = Ecoles[Ecole].Key; + var rituel = Rituels[Rituel].Key; + var source = Sources[Source].Key; + + return items + .Where(item => + { + var spell = item as Spell; + return (int.Parse(spell.Level) >= int.Parse(niveauMin)) && + (int.Parse(spell.Level) <= int.Parse(niveauMax)) && + spell.Type.ToLower().Contains(ecole.ToLower()) && + spell.Source.Contains(source) && + spell.Source.Contains(classe) && + spell.Type.Contains(rituel); + }) + .OrderBy(spell => spell.NamePHB) + .ToList(); + } + public abstract List> Classes { get; } public abstract List> Niveaux { get; } @@ -302,9 +332,434 @@ namespace AideDeJeu.ViewModels #endregion Spells #region Monsters - public class MonsterFilterViewModel : FilterViewModel + public abstract class MonsterFilterViewModel : FilterViewModel { + public override IEnumerable FilterItems(IEnumerable items) + { + var powerComparer = new PowerComparer(); + var category = Categories[Category].Key; + var type = Types[Type].Key; + var minPower = Powers[MinPower].Key; + var maxPower = Powers[MaxPower].Key; + var size = Sizes[Size].Key; + var legendary = Legendaries[Legendary].Key; + var source = Sources[Source].Key; + return items.Where(item => + { + var monster = item as Monster; + return monster.Type.Contains(type) && + (string.IsNullOrEmpty(size) || monster.Size.Equals(size)) && + monster.Source.Contains(source) && + powerComparer.Compare(monster.Challenge, minPower) >= 0 && + powerComparer.Compare(monster.Challenge, maxPower) <= 0; + }) + .OrderBy(monster => monster.NamePHB) + .ToList(); + } + + public abstract List> Categories { get; } + + public abstract List> Types { get; } + + public abstract List> Powers { get; } + + public abstract List> Sizes { get; } + + public abstract List> Legendaries { get; } + + public abstract List> Sources { get; } + + private int _Category = 0; + public int Category + { + get + { + return _Category; + } + set + { + if (_Category != value) + { + SetProperty(ref _Category, value); + LoadItemsCommand.Execute(null); + } + } + } + private int _Type = 0; + public int Type + { + get + { + return _Type; + } + set + { + if (_Type != value) + { + SetProperty(ref _Type, value); + LoadItemsCommand.Execute(null); + } + } + } + private int _MinPower = 0; + public int MinPower + { + get + { + return _MinPower; + } + set + { + if (_MinPower != value) + { + SetProperty(ref _MinPower, value); + if (_MaxPower < _MinPower) + { + SetProperty(ref _MaxPower, value, nameof(MaxPower)); + } + LoadItemsCommand.Execute(null); + } + } + } + private int _MaxPower = 28; + public int MaxPower + { + get + { + return _MaxPower; + } + set + { + if (_MaxPower != value) + { + SetProperty(ref _MaxPower, value); + if (_MaxPower < _MinPower) + { + SetProperty(ref _MinPower, value, nameof(MinPower)); + } + LoadItemsCommand.Execute(null); + } + } + } + private int _Size = 0; + public int Size + { + get + { + return _Size; + } + set + { + if (_Size != value) + { + SetProperty(ref _Size, value); + LoadItemsCommand.Execute(null); + } + } + } + private int _Legendary = 0; + public int Legendary + { + get + { + return _Legendary; + } + set + { + if (_Legendary != value) + { + SetProperty(ref _Legendary, 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 VFMonsterFilterViewModel : MonsterFilterViewModel + { + public override List> Categories { get; } = new List>() + { + new KeyValuePair("", "Toutes" ), + new KeyValuePair("M", "Monstres" ), + new KeyValuePair("A", "Animaux" ), + new KeyValuePair("P", "PNJ" ), + }; + + public override List> Types { get; } = new List>() + { + new KeyValuePair("", "Tous" ), + new KeyValuePair("Humanoïde", "Humanoïde"), + new KeyValuePair("Aberration", "Aberration"), + new KeyValuePair("Bête", "Bête"), + new KeyValuePair("Céleste", "Céleste"), + new KeyValuePair("Créature artificielle", "Créature artificielle"), + new KeyValuePair("Créature monstrueuse", "Créature monstrueuse"), + new KeyValuePair("Dragon", "Dragon"), + new KeyValuePair("Élémentaire", "Élémentaire"), + new KeyValuePair("Fée", "Fée"), + new KeyValuePair("Fiélon", "Fiélon"), + new KeyValuePair("Géant", "Géant"), + new KeyValuePair("Mort-vivant", "Mort-vivant"), + new KeyValuePair("Plante", "Plante"), + new KeyValuePair("Vase", "Vase"), + }; + + public override List> Powers { get; } = new List>() + { + new KeyValuePair(" 0 (0 PX)", "0" ), + new KeyValuePair(" 1/8 (25 PX)", "1/8" ), + new KeyValuePair(" 1/4 (50 PX)", "1/4" ), + new KeyValuePair(" 1/2 (100 PX)", "1/2" ), + new KeyValuePair(" 1 (200 PX)", "1" ), + new KeyValuePair(" 2 (450 PX)", "2" ), + new KeyValuePair(" 3 (700 PX)", "3" ), + new KeyValuePair(" 4 (1100 PX)", "4" ), + new KeyValuePair(" 5 (1800 PX)", "5" ), + new KeyValuePair(" 6 (2300 PX)", "6" ), + new KeyValuePair(" 7 (2900 PX)", "7" ), + new KeyValuePair(" 8 (3900 PX)", "8" ), + new KeyValuePair(" 9 (5000 PX)", "9" ), + new KeyValuePair(" 10 (5900 PX)", "10" ), + new KeyValuePair(" 11 (7200 PX)", "11" ), + new KeyValuePair(" 12 (8400 PX)", "12" ), + new KeyValuePair(" 13 (10000 PX)", "13" ), + new KeyValuePair(" 14 (11500 PX)", "14" ), + new KeyValuePair(" 15 (13000 PX)", "15" ), + new KeyValuePair(" 16 (15000 PX)", "16" ), + new KeyValuePair(" 17 (18000 PX)", "17" ), + new KeyValuePair(" 18 (20000 PX)", "18" ), + new KeyValuePair(" 19 (22000 PX)", "19" ), + new KeyValuePair(" 20 (25000 PX)", "20" ), + new KeyValuePair(" 21 (33000 PX)", "21" ), + new KeyValuePair(" 22 (41000 PX)", "22" ), + new KeyValuePair(" 23 (50000 PX)", "23" ), + new KeyValuePair(" 24 (62000 PX)", "24" ), + new KeyValuePair(" 30 (155000 PX)", "30" ), + }; + + public override List> Sizes { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("TP", "Très petite"), + new KeyValuePair("P", "Petite"), + new KeyValuePair("M", "Moyenne"), + new KeyValuePair("G", "Grande"), + new KeyValuePair("TG", "Très grande"), + new KeyValuePair("Gig", "Gigantesque"), + }; + + public override List> Legendaries { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("si", "Si"), + new KeyValuePair("no", "Non"), + }; + + public override List> Sources { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("(SRD)", "SRD"), + new KeyValuePair("Monster Manual", "MM"), + new KeyValuePair("sup", "VGtM, MToF"), + new KeyValuePair("supno", "AL, AideDD"), + }; + } + + public class VOMonsterFilterViewModel : MonsterFilterViewModel + { + public override List> Categories { get; } = new List>() + { + new KeyValuePair("", "Toutes" ), + new KeyValuePair("M", "Monstres" ), + new KeyValuePair("A", "Animaux" ), + new KeyValuePair("P", "PNJ" ), + }; + + public override List> Types { get; } = new List>() + { + new KeyValuePair("", "Tous" ), + new KeyValuePair("Humanoïde", "Humanoïde"), + new KeyValuePair("Aberration", "Aberration"), + new KeyValuePair("Bête", "Bête"), + new KeyValuePair("Céleste", "Céleste"), + new KeyValuePair("Créature artificielle", "Créature artificielle"), + new KeyValuePair("Créature monstrueuse", "Créature monstrueuse"), + new KeyValuePair("Dragon", "Dragon"), + new KeyValuePair("Élémentaire", "Élémentaire"), + new KeyValuePair("Fée", "Fée"), + new KeyValuePair("Fiélon", "Fiélon"), + new KeyValuePair("Géant", "Géant"), + new KeyValuePair("Mort-vivant", "Mort-vivant"), + new KeyValuePair("Plante", "Plante"), + new KeyValuePair("Vase", "Vase"), + }; + + public override List> Powers { get; } = new List>() + { + new KeyValuePair(" 0 (0 PX)", "0" ), + new KeyValuePair(" 1/8 (25 PX)", "1/8" ), + new KeyValuePair(" 1/4 (50 PX)", "1/4" ), + new KeyValuePair(" 1/2 (100 PX)", "1/2" ), + new KeyValuePair(" 1 (200 PX)", "1" ), + new KeyValuePair(" 2 (450 PX)", "2" ), + new KeyValuePair(" 3 (700 PX)", "3" ), + new KeyValuePair(" 4 (1100 PX)", "4" ), + new KeyValuePair(" 5 (1800 PX)", "5" ), + new KeyValuePair(" 6 (2300 PX)", "6" ), + new KeyValuePair(" 7 (2900 PX)", "7" ), + new KeyValuePair(" 8 (3900 PX)", "8" ), + new KeyValuePair(" 9 (5000 PX)", "9" ), + new KeyValuePair(" 10 (5900 PX)", "10" ), + new KeyValuePair(" 11 (7200 PX)", "11" ), + new KeyValuePair(" 12 (8400 PX)", "12" ), + new KeyValuePair(" 13 (10000 PX)", "13" ), + new KeyValuePair(" 14 (11500 PX)", "14" ), + new KeyValuePair(" 15 (13000 PX)", "15" ), + new KeyValuePair(" 16 (15000 PX)", "16" ), + new KeyValuePair(" 17 (18000 PX)", "17" ), + new KeyValuePair(" 18 (20000 PX)", "18" ), + new KeyValuePair(" 19 (22000 PX)", "19" ), + new KeyValuePair(" 20 (25000 PX)", "20" ), + new KeyValuePair(" 21 (33000 PX)", "21" ), + new KeyValuePair(" 22 (41000 PX)", "22" ), + new KeyValuePair(" 23 (50000 PX)", "23" ), + new KeyValuePair(" 24 (62000 PX)", "24" ), + new KeyValuePair(" 30 (155000 PX)", "30" ), + }; + + public override List> Sizes { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("TP", "Très petite"), + new KeyValuePair("P", "Petite"), + new KeyValuePair("M", "Moyenne"), + new KeyValuePair("G", "Grande"), + new KeyValuePair("TG", "Très grande"), + new KeyValuePair("Gig", "Gigantesque"), + }; + + public override List> Legendaries { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("si", "Si"), + new KeyValuePair("no", "Non"), + }; + + public override List> Sources { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("(SRD)", "SRD"), + new KeyValuePair("Monster Manual", "MM"), + new KeyValuePair("sup", "VGtM, MToF"), + new KeyValuePair("supno", "AL, AideDD"), + }; + } + + public class HDMonsterFilterViewModel : MonsterFilterViewModel + { + public override List> Categories { get; } = new List>() + { + new KeyValuePair("", "Toutes" ), + new KeyValuePair("M", "Monstres" ), + new KeyValuePair("A", "Animaux" ), + new KeyValuePair("P", "PNJ" ), + }; + + public override List> Types { get; } = new List>() + { + new KeyValuePair("", "Tous" ), + new KeyValuePair("Humanoïde", "Humanoïde"), + new KeyValuePair("Aberration", "Aberration"), + new KeyValuePair("Bête", "Bête"), + new KeyValuePair("Céleste", "Céleste"), + new KeyValuePair("Créature artificielle", "Créature artificielle"), + new KeyValuePair("Créature monstrueuse", "Créature monstrueuse"), + new KeyValuePair("Dragon", "Dragon"), + new KeyValuePair("Élémentaire", "Élémentaire"), + new KeyValuePair("Fée", "Fée"), + new KeyValuePair("Fiélon", "Fiélon"), + new KeyValuePair("Géant", "Géant"), + new KeyValuePair("Mort-vivant", "Mort-vivant"), + new KeyValuePair("Plante", "Plante"), + new KeyValuePair("Vase", "Vase"), + }; + + public override List> Powers { get; } = new List>() + { + new KeyValuePair(" 0 (0 PX)", "0" ), + new KeyValuePair(" 1/8 (25 PX)", "1/8" ), + new KeyValuePair(" 1/4 (50 PX)", "1/4" ), + new KeyValuePair(" 1/2 (100 PX)", "1/2" ), + new KeyValuePair(" 1 (200 PX)", "1" ), + new KeyValuePair(" 2 (450 PX)", "2" ), + new KeyValuePair(" 3 (700 PX)", "3" ), + new KeyValuePair(" 4 (1100 PX)", "4" ), + new KeyValuePair(" 5 (1800 PX)", "5" ), + new KeyValuePair(" 6 (2300 PX)", "6" ), + new KeyValuePair(" 7 (2900 PX)", "7" ), + new KeyValuePair(" 8 (3900 PX)", "8" ), + new KeyValuePair(" 9 (5000 PX)", "9" ), + new KeyValuePair(" 10 (5900 PX)", "10" ), + new KeyValuePair(" 11 (7200 PX)", "11" ), + new KeyValuePair(" 12 (8400 PX)", "12" ), + new KeyValuePair(" 13 (10000 PX)", "13" ), + new KeyValuePair(" 14 (11500 PX)", "14" ), + new KeyValuePair(" 15 (13000 PX)", "15" ), + new KeyValuePair(" 16 (15000 PX)", "16" ), + new KeyValuePair(" 17 (18000 PX)", "17" ), + new KeyValuePair(" 18 (20000 PX)", "18" ), + new KeyValuePair(" 19 (22000 PX)", "19" ), + new KeyValuePair(" 20 (25000 PX)", "20" ), + new KeyValuePair(" 21 (33000 PX)", "21" ), + new KeyValuePair(" 22 (41000 PX)", "22" ), + new KeyValuePair(" 23 (50000 PX)", "23" ), + new KeyValuePair(" 24 (62000 PX)", "24" ), + new KeyValuePair(" 30 (155000 PX)", "30" ), + }; + + public override List> Sizes { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("TP", "Très petite"), + new KeyValuePair("P", "Petite"), + new KeyValuePair("M", "Moyenne"), + new KeyValuePair("G", "Grande"), + new KeyValuePair("TG", "Très grande"), + new KeyValuePair("Gig", "Gigantesque"), + }; + + public override List> Legendaries { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("si", "Si"), + new KeyValuePair("no", "Non"), + }; + + public override List> Sources { get; } = new List>() + { + new KeyValuePair("", "Toutes"), + new KeyValuePair("(SRD)", "SRD"), + new KeyValuePair("Monster Manual", "MM"), + new KeyValuePair("sup", "VGtM, MToF"), + new KeyValuePair("supno", "AL, AideDD"), + }; } #endregion Monsters } diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index 65740d26..3f05a5ea 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -12,11 +12,9 @@ namespace AideDeJeu.ViewModels { LoadItemsCommand = new Command(() => ExecuteLoadItemsCommand(null)); } - protected ObservableCollection AllItems { get; set; } = new ObservableCollection(); public ICommand LoadItemsCommand { get; protected set; } public abstract void ExecuteLoadItemsCommand(FilterViewModel filterViewModel); public abstract Task ExecuteGotoItemCommandAsync(Item item); - protected INavigator Navigator { get; set; } //private string _SearchText = ""; //public string SearchText diff --git a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs index 601f38a1..560f68b8 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs @@ -37,7 +37,7 @@ namespace AideDeJeu.ViewModels public class MainViewModel : BaseViewModel { - private ItemSourceType _ItemSourceType = ItemSourceType.SpellHD; + private ItemSourceType _ItemSourceType = ItemSourceType.MonsterVO; public ItemSourceType ItemSourceType { get @@ -54,31 +54,14 @@ namespace AideDeJeu.ViewModels } } - //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>() { { ItemSourceType.SpellVF, new Lazy(() => new SpellsViewModel(ItemSourceType.SpellVF)) }, { ItemSourceType.SpellVO, new Lazy(() => new SpellsViewModel(ItemSourceType.SpellVO)) }, { ItemSourceType.SpellHD, new Lazy(() => new SpellsViewModel(ItemSourceType.SpellHD)) }, - { ItemSourceType.MonsterVF, new Lazy(() => new MonstersViewModel()) }, - { ItemSourceType.MonsterVO, new Lazy(() => new MonstersViewModel()) }, - { ItemSourceType.MonsterHD, new Lazy(() => new MonstersViewModel()) }, + { ItemSourceType.MonsterVF, new Lazy(() => new MonstersViewModel(ItemSourceType.MonsterVF)) }, + { ItemSourceType.MonsterVO, new Lazy(() => new MonstersViewModel(ItemSourceType.MonsterVO)) }, + { ItemSourceType.MonsterHD, new Lazy(() => new MonstersViewModel(ItemSourceType.MonsterHD)) }, }; public ItemsViewModel GetItemsViewModel(ItemSourceType itemSourceType) @@ -91,6 +74,9 @@ namespace AideDeJeu.ViewModels { ItemSourceType.SpellVF, new Lazy(() => new VFSpellFilterViewModel()) }, { ItemSourceType.SpellVO, new Lazy(() => new VOSpellFilterViewModel()) }, { ItemSourceType.SpellHD, new Lazy(() => new HDSpellFilterViewModel()) }, + { ItemSourceType.MonsterVF, new Lazy(() => new VFMonsterFilterViewModel()) }, + { ItemSourceType.MonsterVO, new Lazy(() => new VOMonsterFilterViewModel()) }, + { ItemSourceType.MonsterHD, new Lazy(() => new HDMonsterFilterViewModel()) }, }; public FilterViewModel GetFilterViewModel(ItemSourceType itemSourceType) @@ -98,28 +84,6 @@ namespace AideDeJeu.ViewModels 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; @@ -155,7 +119,10 @@ namespace AideDeJeu.ViewModels { //Spells = new SpellsViewModel(navigator, Items); //Monsters = new MonstersViewModel(navigator, Items); - LoadItemsCommand = new Command(() => GetItemsViewModel(ItemSourceType).ExecuteLoadItemsCommand(GetFilterViewModel(ItemSourceType))); + LoadItemsCommand = new Command(() => + { + 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); diff --git a/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs index 4f0e0904..e6831042 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MonstersViewModel.cs @@ -15,214 +15,11 @@ namespace AideDeJeu.ViewModels { public class MonstersViewModel : ItemsViewModel { - public List> Categories { get; set; } = new List>() + ItemSourceType ItemSourceType; + public MonstersViewModel(ItemSourceType itemSourceType) { - new KeyValuePair("", "Toutes" ), - new KeyValuePair("M", "Monstres" ), - new KeyValuePair("A", "Animaux" ), - new KeyValuePair("P", "PNJ" ), - }; - - public List> Types { get; set; } = new List>() - { - new KeyValuePair("", "Tous" ), - new KeyValuePair("Humanoïde", "Humanoïde"), - new KeyValuePair("Aberration", "Aberration"), - new KeyValuePair("Bête", "Bête"), - new KeyValuePair("Céleste", "Céleste"), - new KeyValuePair("Créature artificielle", "Créature artificielle"), - new KeyValuePair("Créature monstrueuse", "Créature monstrueuse"), - new KeyValuePair("Dragon", "Dragon"), - new KeyValuePair("Élémentaire", "Élémentaire"), - new KeyValuePair("Fée", "Fée"), - new KeyValuePair("Fiélon", "Fiélon"), - new KeyValuePair("Géant", "Géant"), - new KeyValuePair("Mort-vivant", "Mort-vivant"), - new KeyValuePair("Plante", "Plante"), - new KeyValuePair("Vase", "Vase"), - }; - - public List> Powers { get; set; } = new List>() - { - new KeyValuePair(" 0 (0 PX)", "0" ), - new KeyValuePair(" 1/8 (25 PX)", "1/8" ), - new KeyValuePair(" 1/4 (50 PX)", "1/4" ), - new KeyValuePair(" 1/2 (100 PX)", "1/2" ), - new KeyValuePair(" 1 (200 PX)", "1" ), - new KeyValuePair(" 2 (450 PX)", "2" ), - new KeyValuePair(" 3 (700 PX)", "3" ), - new KeyValuePair(" 4 (1100 PX)", "4" ), - new KeyValuePair(" 5 (1800 PX)", "5" ), - new KeyValuePair(" 6 (2300 PX)", "6" ), - new KeyValuePair(" 7 (2900 PX)", "7" ), - new KeyValuePair(" 8 (3900 PX)", "8" ), - new KeyValuePair(" 9 (5000 PX)", "9" ), - new KeyValuePair(" 10 (5900 PX)", "10" ), - new KeyValuePair(" 11 (7200 PX)", "11" ), - new KeyValuePair(" 12 (8400 PX)", "12" ), - new KeyValuePair(" 13 (10000 PX)", "13" ), - new KeyValuePair(" 14 (11500 PX)", "14" ), - new KeyValuePair(" 15 (13000 PX)", "15" ), - new KeyValuePair(" 16 (15000 PX)", "16" ), - new KeyValuePair(" 17 (18000 PX)", "17" ), - new KeyValuePair(" 18 (20000 PX)", "18" ), - new KeyValuePair(" 19 (22000 PX)", "19" ), - new KeyValuePair(" 20 (25000 PX)", "20" ), - new KeyValuePair(" 21 (33000 PX)", "21" ), - new KeyValuePair(" 22 (41000 PX)", "22" ), - new KeyValuePair(" 23 (50000 PX)", "23" ), - new KeyValuePair(" 24 (62000 PX)", "24" ), - new KeyValuePair(" 30 (155000 PX)", "30" ), - }; - - public List> Sizes { get; set; } = new List>() - { - new KeyValuePair("", "Toutes"), - new KeyValuePair("TP", "Très petite"), - new KeyValuePair("P", "Petite"), - new KeyValuePair("M", "Moyenne"), - new KeyValuePair("G", "Grande"), - new KeyValuePair("TG", "Très grande"), - new KeyValuePair("Gig", "Gigantesque"), - }; - - public List> Legendaries { get; set; } = new List>() - { - new KeyValuePair("", "Toutes"), - new KeyValuePair("si", "Si"), - new KeyValuePair("no", "Non"), - }; - - public List> Sources { get; set; } = new List>() - { - new KeyValuePair("", "Toutes"), - new KeyValuePair("(SRD)", "SRD"), - new KeyValuePair("Monster Manual", "MM"), - new KeyValuePair("sup", "VGtM, MToF"), - new KeyValuePair("supno", "AL, AideDD"), - }; - - private int _Category = 0; - public int Category - { - get - { - return _Category; - } - set - { - if (_Category != value) - { - SetProperty(ref _Category, value); - LoadItemsCommand.Execute(null); - } - } + this.ItemSourceType = itemSourceType; } - private int _Type = 0; - public int Type - { - get - { - return _Type; - } - set - { - if (_Type != value) - { - SetProperty(ref _Type, value); - LoadItemsCommand.Execute(null); - } - } - } - private int _MinPower = 0; - public int MinPower - { - get - { - return _MinPower; - } - set - { - if (_MinPower != value) - { - SetProperty(ref _MinPower, value); - if (_MaxPower < _MinPower) - { - SetProperty(ref _MaxPower, value, nameof(MaxPower)); - } - LoadItemsCommand.Execute(null); - } - } - } - private int _MaxPower = 28; - public int MaxPower - { - get - { - return _MaxPower; - } - set - { - if (_MaxPower != value) - { - SetProperty(ref _MaxPower, value); - if (_MaxPower < _MinPower) - { - SetProperty(ref _MinPower, value, nameof(MinPower)); - } - LoadItemsCommand.Execute(null); - } - } - } - private int _Size = 0; - public int Size - { - get - { - return _Size; - } - set - { - if (_Size != value) - { - SetProperty(ref _Size, value); - LoadItemsCommand.Execute(null); - } - } - } - private int _Legendary = 0; - public int Legendary - { - get - { - return _Legendary; - } - set - { - if (_Legendary != value) - { - SetProperty(ref _Legendary, 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); - } - } - } - private IEnumerable _AllMonsters = null; @@ -232,18 +29,26 @@ namespace AideDeJeu.ViewModels { if (_AllMonsters == null) { - var serializer = new DataContractJsonSerializer(typeof(IEnumerable)); - var assembly = typeof(AboutViewModel).GetTypeInfo().Assembly; - //var names = assembly.GetManifestResourceNames(); - using (var stream = assembly.GetManifestResourceStream("AideDeJeu.Data.monsters_vf.json")) + string resourceName = null; + switch (ItemSourceType) { - _AllMonsters = serializer.ReadObject(stream) as IEnumerable; + case ItemSourceType.MonsterVF: + resourceName = "AideDeJeu.Data.monsters_vf.json"; + break; + case ItemSourceType.MonsterVO: + resourceName = "AideDeJeu.Data.monsters_vo.json"; + break; + case ItemSourceType.MonsterHD: + resourceName = "AideDeJeu.Data.monsters_hd.json"; + break; } + _AllMonsters = Tools.Helpers.GetResourceObject>(resourceName); } return _AllMonsters; } } + public IEnumerable GetMonsters(string category, string type, string minPower, string maxPower, string size, string legendary, string source) { var powerComparer = new PowerComparer(); @@ -268,18 +73,14 @@ namespace AideDeJeu.ViewModels try { - AllItems.Clear(); - //var items = await new MonstersScrappers().GetMonsters(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary:Legendaries[Legendary].Key, source: Sources[Source].Key); + Main.Items.Clear(); + //var filter = filterViewModel as MonsterFilterViewModel; + //var items = GetMonsters(category: filter.Categories[filter.Category].Key, type: filter.Types[filter.Type].Key, minPower: filter.Powers[filter.MinPower].Key, maxPower: filter.Powers[filter.MaxPower].Key, size: filter.Sizes[filter.Size].Key, legendary: filter.Legendaries[filter.Legendary].Key, source: filter.Sources[filter.Source].Key); + var items = filterViewModel.FilterItems(AllMonsters); - //ItemDatabaseHelper helper = new ItemDatabaseHelper(); - //var items = await helper.GetMonstersAsync(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary: Legendaries[Legendary].Key, source: Sources[Source].Key); - var items = GetMonsters(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary: Legendaries[Legendary].Key, source: Sources[Source].Key); - - //var aitems = items.ToArray(); - //Array.Sort(aitems, new ItemComparer()); foreach (var item in items) { - AllItems.Add(item); + Main.Items.Add(item); } //FilterItems(); } @@ -295,7 +96,7 @@ namespace AideDeJeu.ViewModels public override async Task ExecuteGotoItemCommandAsync(Item item) { - await Navigator.GotoMonsterDetailPageAsync(item as Monster); + await Main.Navigator.GotoMonsterDetailPageAsync(item as Monster); } }