From 63ee4b6a178693bc7a42b2247c42545d6fc89a2f Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Tue, 9 Apr 2019 01:07:47 +0200 Subject: [PATCH] Description ok ! --- .../AideDeJeu/ViewModels/StoreViewModel.cs | 173 +++++++++++++----- .../Views/PlayerCharacterEditorPage.xaml | 1 + AideDeJeu/AideDeJeuCmd/Program.cs | 9 +- Data/HD/hd_background_brigand.md | 5 +- Data/library.db | Bin 10960896 -> 10960896 bytes 5 files changed, 128 insertions(+), 60 deletions(-) diff --git a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs index 367eeabe..f319c427 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs @@ -55,6 +55,7 @@ namespace AideDeJeu.ViewModels public Item ParseItem(string source, ref ContainerBlock.Enumerator enumerator, Dictionary allItems) { var currentItem = GetNewItem(enumerator.Current); + PropertyInfo currentProp = null; if (currentItem != null) { @@ -65,66 +66,114 @@ namespace AideDeJeu.ViewModels if (block is HtmlBlock) { - if (IsClosingItem(block)) + var htmlBlock = block as HtmlBlock; + if (htmlBlock.Type == HtmlBlockType.Comment) { - currentItem.Id = GetNewAnchorId(source, currentItem.Name, allItems); - if (currentItem.Id != null && allItems != null) - { - allItems[currentItem.Id] = currentItem; - } - return currentItem; - } - else if (IsNewItem(block)) - { - var subItem = ParseItem(source, ref enumerator, allItems); - subItem.ParentLink = GetNewAnchorId(source, currentItem.Name, allItems); - subItem.ParentName = currentItem.Name; - subItem.Markdown = $"> {subItem.ParentNameLink}\n\n---\n\n{subItem.Markdown}"; + var tag = htmlBlock.Lines.Lines.FirstOrDefault().Slice.ToString(); + var parsedComment = new ParsedComment(tag, withSigns: true); - var propertyName = subItem.GetType().Name; - - if (currentItem.GetType().GetProperty(propertyName) != null) + if (parsedComment.Type == ParsedCommentType.Item) { - PropertyInfo prop = currentItem.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance); - if (null != prop && prop.CanWrite) + if (parsedComment.IsClosing) { - prop.SetValue(currentItem, subItem, null); - } - } - else //if (currentItem is Items) - { - if (allItems != null && currentItem.GetNewFilterViewModel() == null) - { - var name = subItem.Name; - var level = Math.Max(1, Math.Min(6, subItem.NameLevel)); - var link = (subItem is LinkItem ? (subItem as LinkItem).Link : subItem.Id); - currentItem.Markdown += $"\n\n{new String('#', level)} [{name}]({link})"; - if(!string.IsNullOrEmpty(subItem.AltNameText)) + currentItem.Id = GetNewAnchorId(source, currentItem.Name, allItems); + if (currentItem.Id != null && allItems != null) { - var altname = subItem.AltNameText; - var altlevel = Math.Max(1, Math.Min(6, subItem.NameLevel + 3)); - currentItem.Markdown += $"\n\n{new String('#', altlevel)} _[{altname}]({link})_"; + allItems[currentItem.Id] = currentItem; } - currentItem.Markdown += "\n\n"; + return currentItem; } else { - var items = currentItem; // as Items; - items.AddChild(subItem); + var subItem = ParseItem(source, ref enumerator, allItems); + subItem.ParentLink = GetNewAnchorId(source, currentItem.Name, allItems); + subItem.ParentName = currentItem.Name; + subItem.Markdown = $"> {subItem.ParentNameLink}\n\n---\n\n{subItem.Markdown}"; + + var propertyName = subItem.GetType().Name; + + if (currentItem.GetType().GetProperty(propertyName) != null) + { + PropertyInfo prop = currentItem.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance); + if (null != prop && prop.CanWrite) + { + prop.SetValue(currentItem, subItem, null); + } + } + else + { + if (allItems != null && currentItem.GetNewFilterViewModel() == null) + { + var name = subItem.Name; + var level = Math.Max(1, Math.Min(6, subItem.NameLevel)); + var link = (subItem is LinkItem ? (subItem as LinkItem).Link : subItem.Id); + currentItem.Markdown += $"\n\n{new String('#', level)} [{name}]({link})"; + if (!string.IsNullOrEmpty(subItem.AltNameText)) + { + var altname = subItem.AltNameText; + var altlevel = Math.Max(1, Math.Min(6, subItem.NameLevel + 3)); + currentItem.Markdown += $"\n\n{new String('#', altlevel)} _[{altname}]({link})_"; + } + currentItem.Markdown += "\n\n"; + } + else + { + var items = currentItem; // as Items; + items.AddChild(subItem); + } + } + enumerator.MoveNext(); } } + else if (parsedComment.Type == ParsedCommentType.Property) + { + if (!parsedComment.IsClosing) + { + PropertyInfo prop = currentItem.GetType().GetProperty(parsedComment.Name, BindingFlags.Public | BindingFlags.Instance); + if (null != prop && prop.CanWrite) + { + prop.SetValue(currentItem, "", null); + currentProp = prop; + } + enumerator.MoveNext(); + } + else + { + currentProp = null; + enumerator.MoveNext(); + } + } + else // comment html différent de item et property + { + var md = enumerator.Current.ToMarkdownString(); + currentItem.Markdown += md; + if (currentProp != null) + { + currentProp.SetValue(currentItem, currentProp.GetValue(currentItem) + md, null); + } + enumerator.MoveNext(); + } + } + else // autre chose qu'un comment html + { + var md = enumerator.Current.ToMarkdownString(); + currentItem.Markdown += md; + if (currentProp != null) + { + currentProp.SetValue(currentItem, currentProp.GetValue(currentItem) + md, null); + } enumerator.MoveNext(); } - else - { - currentItem.Markdown += enumerator.Current.ToMarkdownString(); - enumerator.MoveNext(); - } } - else + else // autre chose qu'un block html { ParseItemProperties(source, currentItem, block); - currentItem.Markdown += enumerator.Current.ToMarkdownString(); + var md = enumerator.Current.ToMarkdownString(); + currentItem.Markdown += md; + if (currentProp != null) + { + currentProp.SetValue(currentItem, currentProp.GetValue(currentItem) + md, null); + } enumerator.MoveNext(); } } @@ -259,16 +308,27 @@ namespace AideDeJeu.ViewModels return false; } + public enum ParsedCommentType + { + Item, + Property, + None, + } public class ParsedComment { - public string Name { get; set; } - public Dictionary Attributes { get; set; } + public string Name { get; private set; } + public ParsedCommentType Type { get; private set; } + public bool IsClosing { get; private set; } + public Dictionary Attributes { get; private set; } - public ParsedComment(string comment) + public ParsedComment(string tag, bool withSigns = false) { - var regex = new Regex("(?\\w+)(\\s+((?\\w+)=\"(?.*?)\"))*"); + var comment = withSigns ? tag.Substring(4, tag.Length - 7) : tag; + var regex = new Regex("(?/?)(?\\w+)(\\s+((?\\w+)=\"(?.*?)\"))*"); var match = regex.Match(comment); Name = match.Groups["item"].Value; + Type = Name.EndsWith("Item") || Name.EndsWith("Items") ? ParsedCommentType.Item : Name != "br" ? ParsedCommentType.Property : ParsedCommentType.None; + IsClosing = !string.IsNullOrEmpty(match.Groups["closing"].Value); var names = match.Groups["name"].Captures; var values = match.Groups["value"].Captures; Attributes = new Dictionary(); @@ -282,7 +342,7 @@ namespace AideDeJeu.ViewModels bool CheckNewItem(string itemString) { var parsedComment = new ParsedComment(itemString); - if (parsedComment.Name.EndsWith("Item") || parsedComment.Name.EndsWith("Items")) + if (parsedComment.Type == ParsedCommentType.Item) { var name = $"AideDeJeuLib.{parsedComment.Name}, AideDeJeu"; var type = Type.GetType(name); @@ -291,7 +351,7 @@ namespace AideDeJeu.ViewModels return true; } } - else if(parsedComment.Name != "br") + else if(parsedComment.Type == ParsedCommentType.Property) { Debug.WriteLine(parsedComment.Name); } @@ -350,6 +410,19 @@ namespace AideDeJeu.ViewModels return false; } + public bool IsClosingProperty(Block block) + { + var htmlBlock = block as HtmlBlock; + if (htmlBlock.Type == HtmlBlockType.Comment) + { + var tag = htmlBlock.Lines.Lines.FirstOrDefault().Slice.ToString(); + var comment = tag.Substring(4, tag.Length - 7); + var parsedComment = new ParsedComment(comment); + return parsedComment.IsClosing && parsedComment.Type == ParsedCommentType.Property; + } + return false; + } + public Item GetNewItem(Block block) { var htmlBlock = block as HtmlBlock; diff --git a/AideDeJeu/AideDeJeu/Views/PlayerCharacterEditorPage.xaml b/AideDeJeu/AideDeJeu/Views/PlayerCharacterEditorPage.xaml index b0561cdf..b97963e0 100644 --- a/AideDeJeu/AideDeJeu/Views/PlayerCharacterEditorPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/PlayerCharacterEditorPage.xaml @@ -56,6 +56,7 @@ + diff --git a/AideDeJeu/AideDeJeuCmd/Program.cs b/AideDeJeu/AideDeJeuCmd/Program.cs index b232dd88..da3de3e6 100644 --- a/AideDeJeu/AideDeJeuCmd/Program.cs +++ b/AideDeJeu/AideDeJeuCmd/Program.cs @@ -373,14 +373,7 @@ namespace AideDeJeuCmd flags[it.Id] = true; } await context.Items.AddRangeAsync(store._AllItems.Values); - try - { - await context.SaveChangesAsync(); - } - catch(Exception ex) - { - Debug.WriteLine(ex); - } + await context.SaveChangesAsync(); var itemsSRD = await context.Items.Where(item => (item.Source != null && item.Source.Contains("SRD"))).ToListAsync(); var monsters = await context.Monsters.ToListAsync(); diff --git a/Data/HD/hd_background_brigand.md b/Data/HD/hd_background_brigand.md index 3e2a9414..2049f237 100644 --- a/Data/HD/hd_background_brigand.md +++ b/Data/HD/hd_background_brigand.md @@ -1,5 +1,8 @@ --- !BackgroundItem +Description: >+ + Vous n'êtes ni un solitaire, ni un sauvage, mais vous avez grandi et vécu en marge de la société. Par choix ou par contrainte, vous avez préféré vous tenir loin des villes et des routes les plus fréquentées, préférant les chemins de terre et les pistes sinueuses aux rues étroites des cités. Une large part de votre existence a été consacrée à assurer votre survie et celle de vos proches, qu'il s'agisse de votre famille ou de compagnons de brigandage. Et lorsque la nature n'y suffisait pas, vous n'avez jamais rechigné à vous en prendre aux voyageurs ou aux villageois afin d'assurer votre subsistance. + Abilities: Discrétion, Survie. MasteredTools: Véhicules (terrestres), un type de jeu au choix. Equipment: Couverture, habits de voyageur, piège à mâchoires, boîte à amadou, matériel de pêche, outre d'eau, bourse contenant 10 po. @@ -18,10 +21,8 @@ Attributes: {} # Brigand - Vous n'êtes ni un solitaire, ni un sauvage, mais vous avez grandi et vécu en marge de la société. Par choix ou par contrainte, vous avez préféré vous tenir loin des villes et des routes les plus fréquentées, préférant les chemins de terre et les pistes sinueuses aux rues étroites des cités. Une large part de votre existence a été consacrée à assurer votre survie et celle de vos proches, qu'il s'agisse de votre famille ou de compagnons de brigandage. Et lorsque la nature n'y suffisait pas, vous n'avez jamais rechigné à vous en prendre aux voyageurs ou aux villageois afin d'assurer votre subsistance. - **Compétences :** Discrétion, Survie. **Outils maîtrisés :** Véhicules (terrestres), un type de jeu au choix. diff --git a/Data/library.db b/Data/library.db index 893fa424c2a24e4ceea4e5e38ba3154dccb01109..d4aac02b2fd0421f52897140b6246d5d9060acf1 100644 GIT binary patch delta 671 zcmZ9?*;kBl0LJmRVW=2XQ-jGevSn$po0-JCvNyJ|6Ct~yB9wS14>i^-^;3zg*IhX0 zy>;R5aU7=$XRdtb)^pD1x%xWJu-C~_jyxKt@$zbdCMs8X%GV@KmQPbORnt_ULKVrc zVwEVM>6)RL3aV7IG+T2tS0T+)ndWPO7HW|et6WR8RLitn6{=K~slIc+QPpUJYPC_D6#H&_e^*?ntGg4-%(&2>p(HaYw(YCPH#1qlD>2v=8Gg1)?x`DrTfyeca z*)5)I?(dFfY-~mywqPr^VLNtUCw8G8aqPw(?8QFpM*;_M5QlIWM{pF!a2zMlfRi|d zMx4eOoJAAP;XE$jA}--FuHY(?xQ6R!MhjYT12@rzTeyuoXh#R`q7(OU9}ZIJ!UG5o z@d(}MK^l+o1W)k{&+!7ic!^hdjW_5+KMdYt0D~C9I}GDJK41hN@d=;t1z+80=G)J@ Ee{aw-3;+NC delta 705 zcmY+(Sy#+)0EhAMXQU|FBqNMHOjF2`Y0$r{HInRE6J?o6Gg7vud{g$u_9G%ou3d2E z99J&90FIa7-pM)K%yHqFOV2rLhMwZ5EoSYi36ira7(lk+%l&%a-))Zwb zOWDd%uBIwa)0D62a%qMNG*h!QTW-zKT+P#bEzm+OQlS=WiI&QvB6(G;5-rnmtx%~} zYL!-NjmorEK9$R_by}|ts`y|#M^mh3N7_%TIi5M-Yp@DpR)4Uwrrhgtce_&^jzO;@ zz0i@YH00*uPiyf%LPSj%;c4H6rVjuS702*)*hj182a1_VTh~sF&37kYT zT5t-daRz4*L5W{^uz(YL3V;DTaQw-u6o?{3v@Djs#h1Yn4w-|~067RlL{R4P2M1=qV