From 9bdd734df373e36b02f65044277b044c0465be90 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Thu, 18 Apr 2019 03:18:08 +0200 Subject: [PATCH] Class vm --- AideDeJeu/AideDeJeu/AideDeJeu.csproj | 3 + .../Models/Classes/ClassEvolutionItem.cs | 29 ++++++- .../PlayerCharacter/ClassViewModel.cs | 60 ++++++++++++-- .../PlayerCharacterEditorViewModel.cs | 41 ---------- .../PlayerCharacterViewModel.cs | 1 + .../AideDeJeu/ViewModels/StoreViewModel.cs | 19 +++-- AideDeJeu/AideDeJeu/Views/ItemView.xaml | 19 +++++ AideDeJeu/AideDeJeu/Views/ItemView.xaml.cs | 82 +++++++++++++++++++ .../PlayerCharacterEditorPage.xaml | 16 ++++ 9 files changed, 216 insertions(+), 54 deletions(-) create mode 100644 AideDeJeu/AideDeJeu/Views/ItemView.xaml create mode 100644 AideDeJeu/AideDeJeu/Views/ItemView.xaml.cs diff --git a/AideDeJeu/AideDeJeu/AideDeJeu.csproj b/AideDeJeu/AideDeJeu/AideDeJeu.csproj index 349644ce..8b927640 100644 --- a/AideDeJeu/AideDeJeu/AideDeJeu.csproj +++ b/AideDeJeu/AideDeJeu/AideDeJeu.csproj @@ -50,6 +50,9 @@ Code + + ItemView.xaml + ItemDetailPage.xaml diff --git a/AideDeJeu/AideDeJeu/Models/Classes/ClassEvolutionItem.cs b/AideDeJeu/AideDeJeu/Models/Classes/ClassEvolutionItem.cs index a5e95e6a..665c28a3 100644 --- a/AideDeJeu/AideDeJeu/Models/Classes/ClassEvolutionItem.cs +++ b/AideDeJeu/AideDeJeu/Models/Classes/ClassEvolutionItem.cs @@ -1,6 +1,33 @@ -namespace AideDeJeuLib +using System.Collections.Generic; +using System.Linq; + +namespace AideDeJeuLib { public class ClassEvolutionItem : Item { + public string Table { get; set; } + public List BindableTable + { + get + { + return ExtractSimpleTable(Table); + } + } + public List ExtractSimpleTable(string table) + { + var lines = table.Split('\n'); + var result = new List(); + foreach (var line in lines.Skip(2)) + { + if (line.StartsWith("|")) + { + var cols = line.Split('|'); + var text = cols[2].Replace("", " ").Replace(" ", " "); + result.Add(text); + } + } + return result; + } + } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/ClassViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/ClassViewModel.cs index 49c00a71..2bfd8f3d 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/ClassViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/ClassViewModel.cs @@ -1,20 +1,66 @@ using AideDeJeuLib; using System.Collections.Generic; +using System.Threading.Tasks; +using System.Linq; +using Microsoft.EntityFrameworkCore; namespace AideDeJeu.ViewModels.PlayerCharacter { public class ClassViewModel : BaseViewModel { - public ClassItem Class { get; set; } - public SubClassItem SubClass { get; set; } - public ClassHitPointsItem HitPoints { get; set; } - public ClassProficienciesItem Proficiencies { get; set; } - public ClassEquipmentItem Equipment { get; set; } - public ClassEvolutionItem Evolution { get; set; } - public List Features { get; set; } + private ClassItem _Class = null; + public ClassItem Class { get { return _Class; } set { SetProperty(ref _Class, value); } } + + private SubClassItem _SubClass = null; + public SubClassItem SubClass { get { return _SubClass; } set { SetProperty(ref _SubClass, value); } } + + private ClassHitPointsItem _HitPoints = null; + public ClassHitPointsItem HitPoints { get { return _HitPoints; } set { SetProperty(ref _HitPoints, value); } } + + public ClassProficienciesItem _Proficiencies = null; + public ClassProficienciesItem Proficiencies { get { return _Proficiencies; } set { SetProperty(ref _Proficiencies, value); } } + + public ClassEquipmentItem _Equipment = null; + public ClassEquipmentItem Equipment { get { return _Equipment; } set { SetProperty(ref _Equipment, value); } } + + public ClassEvolutionItem _Evolution = null; + public ClassEvolutionItem Evolution { get { return _Evolution; } set { SetProperty(ref _Evolution, value); } } + + public List _Features = null; + public List Features { get { return _Features; } set { SetProperty(ref _Features, value); } } public string Name { get { return Class?.Name; } } public string Description { get { return Class?.Description; } } public string Markdown { get { return Class?.Markdown; } } + + public List LeveledFeatures + { + get + { + var table = Evolution.ExtractSimpleTable(Evolution.Table); + var feats = table[1]; + var leveledFeats = new List(); + foreach(var feature in Features) + { + if(feats.Contains(feature.Name)) + { + leveledFeats.Add(feature); + } + } + return leveledFeats; + } + } + + public async Task LoadDetailsAsync() + { + using (var context = await StoreViewModel.GetLibraryContextAsync()) + { + HitPoints = await context.ClassHitPoints.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync(); + Proficiencies = await context.ClassProficiencies.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync(); + Equipment = await context.ClassEquipments.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync(); + Evolution = await context.ClassEvolutions.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync(); + Features = await context.ClassFeatures.Where(c => c.ParentLink == Class.Id).ToListAsync(); + } + } } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterEditorViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterEditorViewModel.cs index dedd976b..f99ece63 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterEditorViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterEditorViewModel.cs @@ -151,20 +151,6 @@ namespace AideDeJeu.ViewModels.PlayerCharacter #region Race public NotifyTaskCompletion> Races { get; private set; } - //private RaceViewModel _SelectedRace = null; - //public RaceViewModel SelectedRace - //{ - // get - // { - // return _SelectedRace; - // } - // set - // { - // SetProperty(ref _SelectedRace, value); - // //SelectedPlayerCharacter.Race = _SelectedRace; - // } - //} - public async Task> LoadRacesAsync() { using (var context = await StoreViewModel.GetLibraryContextAsync()) @@ -195,33 +181,6 @@ namespace AideDeJeu.ViewModels.PlayerCharacter #region Class public NotifyTaskCompletion> Classes { get; private set; } - //private int _ClassSelectedIndex = -1; - //public int ClassSelectedIndex - //{ - // get - // { - // return _ClassSelectedIndex; - // } - // set - // { - // SetProperty(ref _ClassSelectedIndex, value); - // SelectedClass = Classes.Result[_ClassSelectedIndex]; - // } - //} - //private ClassViewModel _SelectedClass = null; - //public ClassViewModel SelectedClass - //{ - // get - // { - // return _SelectedClass; - // } - // set - // { - // SetProperty(ref _SelectedClass, value); - // //SelectedPlayerCharacter.Class = _SelectedClass; - // } - //} - public async Task> LoadClassesAsync() { using (var context = await StoreViewModel.GetLibraryContextAsync()) diff --git a/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterViewModel.cs index d0c9a444..f6d0566f 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/PlayerCharacter/PlayerCharacterViewModel.cs @@ -41,6 +41,7 @@ namespace AideDeJeu.ViewModels.PlayerCharacter set { SetProperty(ref _Class, value); + _Class.LoadDetailsAsync().ConfigureAwait(true); } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs index 33117216..c5b6ec4e 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs @@ -610,14 +610,21 @@ namespace AideDeJeu.ViewModels public DbSet MagicItems { get; set; } public DbSet Spells { get; set; } public DbSet Monsters { get; set; } - //public DbSet Spells { get; set; } - //public DbSet MonstersHD { get; set; } - //public DbSet SpellsVO { get; set; } - //public DbSet MonstersVO { get; set; } + + public DbSet Races { get; set; } - public DbSet Classes { get; set; } public DbSet SubRaces { get; set; } + + + public DbSet Classes { get; set; } public DbSet SubClasses { get; set; } + public DbSet ClassHitPoints { get; set; } + public DbSet ClassProficiencies { get; set; } + public DbSet ClassEquipments { get; set; } + public DbSet ClassEvolutions { get; set; } + public DbSet ClassFeatures { get; set; } + + public DbSet Backgrounds { get; set; } public DbSet SubBackgrounds { get; set; } public DbSet PersonalityTraits { get; set; } @@ -626,6 +633,8 @@ namespace AideDeJeu.ViewModels public DbSet PersonalityDefects { get; set; } public DbSet Skills { get; set; } public DbSet BackgroundSpecialties { get; set; } + + public DbSet Alignments { get; set; } public AideDeJeuContext(string dbPath) diff --git a/AideDeJeu/AideDeJeu/Views/ItemView.xaml b/AideDeJeu/AideDeJeu/Views/ItemView.xaml new file mode 100644 index 00000000..c093fc6a --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/ItemView.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/Views/ItemView.xaml.cs b/AideDeJeu/AideDeJeu/Views/ItemView.xaml.cs new file mode 100644 index 00000000..93189535 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Views/ItemView.xaml.cs @@ -0,0 +1,82 @@ +using AideDeJeu.ViewModels; +using AideDeJeuLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace AideDeJeu.Views +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class ItemView : StackLayout + { + public MainViewModel Main + { + get + { + return DependencyService.Get(); + } + } + public ItemView() + { + InitializeComponent(); + BindingContext = this; + } + + public string Name + { + get { return (string)GetValue(NameProperty); } + set { SetValue(NameProperty, value); } + } + public static readonly BindableProperty NameProperty = BindableProperty.Create( + nameof(Name), + typeof(string), + typeof(ItemView), + defaultValue: default(string)); + + public string Description + { + get { return (string)GetValue(DescriptionProperty); } + set { SetValue(DescriptionProperty, value); } + } + public static readonly BindableProperty DescriptionProperty = BindableProperty.Create( + nameof(Description), + typeof(string), + typeof(ItemView), + defaultValue: default(string)); + + public object SelectedItem + { + get { return (object)GetValue(SelectedItemProperty); } + set { SetValue(SelectedItemProperty, value); } + } + public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create( + nameof(SelectedItem), + typeof(object), + typeof(ItemView), + defaultValue: default(object), + defaultBindingMode: BindingMode.TwoWay); + + public System.Collections.IEnumerable ItemsSource + { + get { return (System.Collections.IEnumerable)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + //public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create( + // nameof(ItemsSource), + // typeof(System.Collections.IList), + // typeof(StringPickerView), + // defaultValue: new List()); + public static readonly BindableProperty ItemsSourceProperty = + BindableProperty.Create( + nameof(ItemsSource), + typeof(System.Collections.IEnumerable), + typeof(ItemView), + default(System.Collections.IEnumerable)); + + } +} \ No newline at end of file diff --git a/AideDeJeu/AideDeJeu/Views/PlayerCharacter/PlayerCharacterEditorPage.xaml b/AideDeJeu/AideDeJeu/Views/PlayerCharacter/PlayerCharacterEditorPage.xaml index e63d3658..097bcba6 100644 --- a/AideDeJeu/AideDeJeu/Views/PlayerCharacter/PlayerCharacterEditorPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/PlayerCharacter/PlayerCharacterEditorPage.xaml @@ -71,6 +71,22 @@ + + + + + + + + + + + + + + + +