mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Attributs race
This commit is contained in:
		
							parent
							
								
									1b3b101b6e
								
							
						
					
					
						commit
						893019a4d7
					
				
					 3 changed files with 153 additions and 46 deletions
				
			
		|  | @ -38,7 +38,7 @@ namespace AideDeJeuLib | |||
|             _Items = new List<Item>(); | ||||
|         } | ||||
| 
 | ||||
|         public async Task<IEnumerable<Item>> GetChildrenAsync() | ||||
|         public virtual async Task<IEnumerable<Item>> GetChildrenAsync() | ||||
|         { | ||||
|             return _Items; | ||||
|         } | ||||
|  | @ -86,7 +86,7 @@ namespace AideDeJeuLib | |||
|         //    _Items.RemoveAt(index); | ||||
|         //} | ||||
| 
 | ||||
|         public void AddChild(Item item) | ||||
|         public virtual void AddChild(Item item) | ||||
|         { | ||||
|             _Items.Add(item); | ||||
|         } | ||||
|  | @ -117,22 +117,22 @@ namespace AideDeJeuLib | |||
| 
 | ||||
|         [DataMember(Name = "Item_RootId", Order = 1)] | ||||
|         [Indexed] | ||||
|         public string RootId { get; set; } | ||||
|         public virtual string RootId { get; set; } | ||||
| 
 | ||||
|         [DataMember(Name = "Item_ParentLink", Order = 2)] | ||||
|         [Indexed] | ||||
|         public string ParentLink { get; set; } | ||||
|         public virtual string ParentLink { get; set; } | ||||
| 
 | ||||
|         [DataMember(Name = "Item_Name", Order = 3)] | ||||
|         public string Name { get; set; } | ||||
|         public virtual string Name { get; set; } | ||||
| 
 | ||||
|         [DataMember(Name = "Item_ParentName", Order = 4)] | ||||
|         public string ParentName { get; set; } | ||||
|         public virtual string ParentName { get; set; } | ||||
| 
 | ||||
|         [YamlIgnore] | ||||
|         [IgnoreDataMember] | ||||
|         [Ignore] | ||||
|         public string ParentNameLink | ||||
|         public virtual string ParentNameLink | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -155,13 +155,13 @@ namespace AideDeJeuLib | |||
|         } | ||||
| 
 | ||||
|         [DataMember(Name = "Item_NameLevel", Order = 5)] | ||||
|         public int NameLevel { get; set; } | ||||
|         public virtual int NameLevel { get; set; } | ||||
|         [DataMember(Name = "Item_AltName", Order = 6)] | ||||
|         public string AltName { get; set; } | ||||
|         public virtual string AltName { get; set; } | ||||
| 
 | ||||
|         [YamlIgnore] | ||||
|         [IgnoreDataMember] | ||||
|         public string AltNameText | ||||
|         public virtual string AltNameText | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -184,13 +184,13 @@ namespace AideDeJeuLib | |||
|             } | ||||
|         } | ||||
|         [DataMember(Name = "Item_Source", Order = 7)] | ||||
|         public string Source { get; set; } | ||||
|         public virtual string Source { get; set; } | ||||
| 
 | ||||
|         [YamlIgnore] | ||||
|         [DataMember(Name = "Item_Markdown", Order = 8)] | ||||
|         public virtual string Markdown { get; set; } | ||||
|         [DataMember(Name = "Item_FullText", Order = 9)] | ||||
|         public string FullText { get; set; } | ||||
|         public virtual string FullText { get; set; } | ||||
| 
 | ||||
|         [IgnoreDataMember] | ||||
|         [YamlIgnore] | ||||
|  | @ -234,7 +234,7 @@ namespace AideDeJeuLib | |||
| 
 | ||||
|         [IgnoreDataMember] | ||||
|         [YamlIgnore] | ||||
|         public string Yaml | ||||
|         public virtual string Yaml | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -263,7 +263,7 @@ namespace AideDeJeuLib | |||
| 
 | ||||
|         [IgnoreDataMember] | ||||
|         [YamlIgnore] | ||||
|         public string SubMarkdown | ||||
|         public virtual string SubMarkdown | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -306,7 +306,7 @@ namespace AideDeJeuLib | |||
|             return post as Item; | ||||
|         } | ||||
| 
 | ||||
|         public string CleanMarkdown | ||||
|         public virtual string CleanMarkdown | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -317,7 +317,7 @@ namespace AideDeJeuLib | |||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public string NewId | ||||
|         public virtual string NewId | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -357,9 +357,9 @@ namespace AideDeJeuLib | |||
|         } | ||||
|         [NotMapped] | ||||
|         [IgnoreDataMember] | ||||
|         public OrderedDictionary Attributes { get; set; } = new OrderedDictionary(); | ||||
|         public virtual OrderedDictionary Attributes { get; set; } = new OrderedDictionary(); | ||||
| 
 | ||||
|         public OrderedDictionary AttributesKeyValue | ||||
|         public virtual OrderedDictionary AttributesKeyValue | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -380,7 +380,7 @@ namespace AideDeJeuLib | |||
|         } | ||||
| 
 | ||||
|         [DataMember] | ||||
|         public string AttributesDictionary | ||||
|         public virtual string AttributesDictionary | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -400,7 +400,7 @@ namespace AideDeJeuLib | |||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void ResetAttribute(string name) | ||||
|         public virtual void ResetAttribute(string name) | ||||
|         { | ||||
|             if (name != null) | ||||
|             { | ||||
|  | @ -415,7 +415,7 @@ namespace AideDeJeuLib | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         public void SetAttribute(string name, string value) | ||||
|         public virtual void SetAttribute(string name, string value) | ||||
|         { | ||||
|             if (name != null && value != null) | ||||
|             { | ||||
|  | @ -434,7 +434,7 @@ namespace AideDeJeuLib | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         public string GetAttribute(string name) | ||||
|         public virtual string GetAttribute(string name) | ||||
|         { | ||||
|             if (this.Attributes.Contains(name)) | ||||
|             { | ||||
|  | @ -445,6 +445,6 @@ namespace AideDeJeuLib | |||
| 
 | ||||
| 
 | ||||
|         [DataMember] | ||||
|         public string Description { get; set; } | ||||
|         public virtual string Description { get; set; } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -6,39 +6,39 @@ namespace AideDeJeuLib | |||
|     public class RaceItem : Item | ||||
|     { | ||||
|         [DataMember] | ||||
|         public string FullName { get; set; } | ||||
|         public virtual string FullName { get; set; } | ||||
|         [DataMember] | ||||
|         public bool HasSubRaces { get; set; } | ||||
|         public virtual bool HasSubRaces { get; set; } | ||||
| 
 | ||||
|         [DataMember] | ||||
|         public string StrengthBonus { get; set; } | ||||
|         public virtual string StrengthBonus { get; set; } | ||||
|         [DataMember] | ||||
|         public string DexterityBonus { get; set; } | ||||
|         public virtual string DexterityBonus { get; set; } | ||||
|         [DataMember] | ||||
|         public string ConstitutionBonus { get; set; } | ||||
|         public virtual string ConstitutionBonus { get; set; } | ||||
|         [DataMember] | ||||
|         public string IntelligenceBonus { get; set; } | ||||
|         public virtual string IntelligenceBonus { get; set; } | ||||
|         [DataMember] | ||||
|         public string WisdomBonus { get; set; } | ||||
|         public virtual string WisdomBonus { get; set; } | ||||
|         [DataMember] | ||||
|         public string CharismaBonus { get; set; } | ||||
|         public virtual string CharismaBonus { get; set; } | ||||
|         [DataMember] | ||||
|         public string AnyAbilityBonus { get; set; } | ||||
|         public virtual string AnyAbilityBonus { get; set; } | ||||
| 
 | ||||
|         [DataMember] | ||||
|         public string AbilityScoreIncrease { get; set; } | ||||
|         public virtual string AbilityScoreIncrease { get; set; } | ||||
|         [DataMember] | ||||
|         public string Age { get; set; } | ||||
|         public virtual string Age { get; set; } | ||||
|         [DataMember] | ||||
|         public string Alignment { get; set; } | ||||
|         public virtual string Alignment { get; set; } | ||||
|         [DataMember] | ||||
|         public string Size { get; set; } | ||||
|         public virtual string Size { get; set; } | ||||
|         [DataMember] | ||||
|         public string Speed { get; set; } | ||||
|         public virtual string Speed { get; set; } | ||||
|         [DataMember] | ||||
|         public string Darkvision { get; set; } | ||||
|         public virtual string Darkvision { get; set; } | ||||
|         [DataMember] | ||||
|         public string Languages { get; set; } | ||||
|         public virtual string Languages { get; set; } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -2,7 +2,9 @@ | |||
| using AideDeJeuLib; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using System.Collections.Specialized; | ||||
| using System.Linq; | ||||
| using System.Text.RegularExpressions; | ||||
| using System.Threading.Tasks; | ||||
|  | @ -16,7 +18,7 @@ namespace AideDeJeu.ViewModels | |||
|         public PlayerCharacterEditorViewModel() | ||||
|         { | ||||
|             ResetAlignments(); | ||||
|             Races = new NotifyTaskCompletion<List<RaceItem>>(Task.Run(() => LoadRacesAsync())); | ||||
|             Races = new NotifyTaskCompletion<List<RaceItemExpanded>>(Task.Run(() => LoadRacesAsync())); | ||||
|             Classes = new NotifyTaskCompletion<List<ClassItem>>(Task.Run(() => LoadClassesAsync())); | ||||
| 
 | ||||
|             Backgrounds = new NotifyTaskCompletion<List<BackgroundItem>>(Task.Run(() => LoadBackgroundsAsync())); | ||||
|  | @ -147,7 +149,7 @@ namespace AideDeJeu.ViewModels | |||
|         #endregion Alignment | ||||
| 
 | ||||
|         #region Race | ||||
|         public NotifyTaskCompletion<List<RaceItem>> Races { get; private set; } | ||||
|         public NotifyTaskCompletion<List<RaceItemExpanded>> Races { get; private set; } | ||||
|         private int _RaceSelectedIndex = -1; | ||||
|         public int RaceSelectedIndex | ||||
|         { | ||||
|  | @ -164,8 +166,8 @@ namespace AideDeJeu.ViewModels | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         private RaceItem _SelectedRace = null; | ||||
|         public RaceItem SelectedRace | ||||
|         private RaceItemExpanded _SelectedRace = null; | ||||
|         public RaceItemExpanded SelectedRace | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|  | @ -174,15 +176,120 @@ namespace AideDeJeu.ViewModels | |||
|             set | ||||
|             { | ||||
|                 SetProperty(ref _SelectedRace, value); | ||||
|                 SelectedPlayerCharacter.Race = _SelectedRace; | ||||
|                 //SelectedPlayerCharacter.Race = _SelectedRace; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public async Task<List<RaceItem>> LoadRacesAsync() | ||||
|         public class RaceItemExpanded : RaceItem | ||||
|         { | ||||
|             public RaceItem Race { get; set; } | ||||
|             public SubRaceItem SubRace { get; set; } | ||||
| 
 | ||||
|             private RaceItem RaceOrSubRace | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     return SubRace ?? Race; | ||||
|                 } | ||||
|             } | ||||
|             public override string Name | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     return RaceOrSubRace.Name; | ||||
|                 } | ||||
|             } | ||||
|             public override string Description | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     return RaceOrSubRace.Description; | ||||
|                 } | ||||
|             } | ||||
|             public override string NewId | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     return RaceOrSubRace.NewId; | ||||
|                 } | ||||
|             } | ||||
|             public override string Id | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     return RaceOrSubRace.Id; | ||||
|                 } | ||||
|             } | ||||
|             public override string RootId | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     return RaceOrSubRace.RootId; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             public override string AbilityScoreIncrease | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     if(SubRace?.AbilityScoreIncrease != null) | ||||
|                     { | ||||
|                         return Race.AbilityScoreIncrease + "\n\n" + SubRace.AbilityScoreIncrease; | ||||
|                     } | ||||
|                     return Race.AbilityScoreIncrease; | ||||
|                 } | ||||
|             } | ||||
|             public override OrderedDictionary Attributes | ||||
|             { | ||||
|                 get | ||||
|                 { | ||||
|                     if(SubRace == null) | ||||
|                     { | ||||
|                         return Race.Attributes; | ||||
|                     } | ||||
|                     var dico = new OrderedDictionary(); | ||||
|                     foreach(DictionaryEntry attr in Race.Attributes) | ||||
|                     { | ||||
|                         dico[attr.Key] = attr.Value; | ||||
|                     } | ||||
|                     foreach (DictionaryEntry attr in SubRace.Attributes) | ||||
|                     { | ||||
|                         dico[attr.Key] = attr.Value; | ||||
|                     } | ||||
|                     return dico; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             public override string Age { get { return Race.Age; } } | ||||
|             public override string Alignment { get { return Race.Alignment; } } | ||||
|             public override string Size { get { return Race.Size; } } | ||||
|             public override string Speed { get { return Race.Speed; } } | ||||
|             public override string Darkvision { get { return Race.Darkvision; } } | ||||
|             public override string Languages { get { return Race.Languages; } } | ||||
|         } | ||||
|         public async Task<List<RaceItemExpanded>> LoadRacesAsync() | ||||
|         { | ||||
|             using (var context = await StoreViewModel.GetLibraryContextAsync()) | ||||
|             { | ||||
|                 return await context.Races.Where(r => !r.HasSubRaces).OrderBy(r => Tools.Helpers.RemoveDiacritics(r.Name)).ToListAsync().ConfigureAwait(false); | ||||
|                 var expandedRaces = new List<RaceItemExpanded>(); | ||||
|                 var races = context.Races.Where(r => r.GetType() == typeof(RaceItem)); | ||||
|                 foreach(var race in races) | ||||
|                 { | ||||
|                     if(race.HasSubRaces) | ||||
|                     { | ||||
|                         var subraces = context.SubRaces.Where(sr => sr.ParentLink == race.Id); | ||||
|                         foreach(var subrace in subraces) | ||||
|                         { | ||||
|                             expandedRaces.Add(new RaceItemExpanded() { Race = race, SubRace = subrace }); | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         expandedRaces.Add(new RaceItemExpanded() { Race = race, SubRace = null }); | ||||
|                     } | ||||
|                 } | ||||
|                 return expandedRaces; | ||||
|                 //return await context.Races.Where(r => !r.HasSubRaces).OrderBy(r => Tools.Helpers.RemoveDiacritics(r.Name)).ToListAsync().ConfigureAwait(false); | ||||
|             } | ||||
|         } | ||||
|         #endregion Race | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez