mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-12-22 18:13:23 +00:00
Equipement avec filtres
This commit is contained in:
parent
cb7bdda270
commit
0215252ff2
8 changed files with 1237 additions and 120 deletions
|
|
@ -206,6 +206,11 @@
|
|||
<EmbeddedResource Include="..\..\Data\wizard_academician_hd.md" Link="Data\wizard_academician_hd.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\..\Data\equipment_hd.md" Link="Data\equipment_hd.md" />
|
||||
<EmbeddedResource Include="..\..\Data\equipment_properties_hd.md" Link="Data\equipment_properties_hd.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Views\MainNavigationPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
|
|
|
|||
171
AideDeJeu/AideDeJeu/Models/Equipment.cs
Normal file
171
AideDeJeu/AideDeJeu/Models/Equipment.cs
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using AideDeJeu.Tools;
|
||||
using Markdig.Syntax;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
public class Equipment : Item
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Price { get; set; }
|
||||
public string ArmorClass { get; set; }
|
||||
public string Discretion { get; set; }
|
||||
public string Weight { get; set; }
|
||||
public string Force { get; set; }
|
||||
public string Rarity { get; set; }
|
||||
public string Damages { get; set; }
|
||||
public string Properties { get; set; }
|
||||
public string Unity { get; set; }
|
||||
public string Capacity { get; set; }
|
||||
public string WeightCapacity { get; set; }
|
||||
public string Speed { get; set; }
|
||||
|
||||
public override string Markdown
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
//$"# {Name}\n\n" +
|
||||
//$"{AltName}\n\n" +
|
||||
Text;
|
||||
}
|
||||
}
|
||||
|
||||
public void ParseBlock(Block block)
|
||||
{
|
||||
if (block is HeadingBlock)
|
||||
{
|
||||
var headingBlock = block as HeadingBlock;
|
||||
if (this.Name == null)
|
||||
{
|
||||
this.Name = headingBlock.Inline.ToMarkdownString();
|
||||
}
|
||||
this.Text += block.ToMarkdownString();
|
||||
}
|
||||
else if (block is ListBlock)
|
||||
{
|
||||
var listBlock = block as ListBlock;
|
||||
if (listBlock.BulletType == '-')
|
||||
{
|
||||
foreach (var inblock in listBlock)
|
||||
{
|
||||
if (inblock is Markdig.Syntax.ListItemBlock)
|
||||
{
|
||||
var listItemBlock = inblock as Markdig.Syntax.ListItemBlock;
|
||||
foreach (var ininblock in listItemBlock)
|
||||
{
|
||||
if (ininblock is Markdig.Syntax.ParagraphBlock)
|
||||
{
|
||||
var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock;
|
||||
var str = paragraphBlock.ToMarkdownString();
|
||||
|
||||
var properties = new List<Tuple<string, Action<Equipment, string>>>()
|
||||
{
|
||||
new Tuple<string, Action<Equipment, string>>("AltName: ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + s; m.AltName = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Type** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Type = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Prix** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Price = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Classe d'armure** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.ArmorClass = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Discrétion** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Discretion = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Poids** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Weight = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Force** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Force = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Rareté** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Rarity = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Dégâts** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Damages = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Propriétés** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Properties = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Unité** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Unity = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Capacité** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Capacity = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Capacité de charge** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.WeightCapacity = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("**Vitesse** ", (m, s) =>
|
||||
{
|
||||
this.Text += "- " + str; m.Speed = s;
|
||||
}),
|
||||
new Tuple<string, Action<Equipment, string>>("", (m, s) =>
|
||||
{
|
||||
this.Text += str;
|
||||
}),
|
||||
};
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (str.StartsWith(property.Item1))
|
||||
{
|
||||
property.Item2.Invoke(this, str.Substring(property.Item1.Length));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Text += "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Text += block.ToMarkdownString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Text += block.ToMarkdownString();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Parse(ref ContainerBlock.Enumerator enumerator)
|
||||
{
|
||||
enumerator.MoveNext();
|
||||
while (enumerator.Current != null)
|
||||
{
|
||||
var block = enumerator.Current;
|
||||
if (block.IsNewItem())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ParseBlock(block);
|
||||
enumerator.MoveNext();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
AideDeJeu/AideDeJeu/Models/Equipments.cs
Normal file
15
AideDeJeu/AideDeJeu/Models/Equipments.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using AideDeJeu.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
public class Equipments : Items
|
||||
{
|
||||
public override FilterViewModel GetNewFilterViewModel()
|
||||
{
|
||||
return new VFEquipmentFilterViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ namespace AideDeJeuLib
|
|||
"# VF (H&D)\n\n" +
|
||||
"## [Races](races_hd.md)\n\n" +
|
||||
"## [Classes](classes_hd.md)\n\n" +
|
||||
"## [Équipement](equipment_hd.md)\n\n" +
|
||||
"## [Caractéristiques](abilities_hd.md)\n\n" +
|
||||
"## [Etats spéciaux](conditions_hd.md)\n\n" +
|
||||
"## [Sorts](spells_hd.md)\n\n" +
|
||||
|
|
|
|||
|
|
@ -27,4 +27,37 @@ namespace AideDeJeu.Tools
|
|||
return xpx - xpy;
|
||||
}
|
||||
}
|
||||
|
||||
public class PriceComparer : Comparer<string>
|
||||
{
|
||||
int ToCopperPieces(string price)
|
||||
{
|
||||
price = price.Trim(new char[] { ' ', '\n' });
|
||||
var regex = new Regex("(?<count>\\d?\\d?\\d?\\s?\\d?\\d?\\d?\\s?\\d?\\d?\\d?)\\s?(?<type>p[caeop])");
|
||||
var match = regex.Match(price);
|
||||
int count = 0;
|
||||
int.TryParse(match.Groups["count"].Value.Replace(" ", ""), out count);
|
||||
switch (match.Groups["type"].Value)
|
||||
{
|
||||
case "pc":
|
||||
return count;
|
||||
case "pa":
|
||||
return count * 10;
|
||||
case "pe":
|
||||
return count * 50;
|
||||
case "po":
|
||||
return count * 100;
|
||||
case "pp":
|
||||
return count * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public override int Compare(string x, string y)
|
||||
{
|
||||
if (string.IsNullOrEmpty(x) && string.IsNullOrEmpty(y)) return 0;
|
||||
if (string.IsNullOrEmpty(x)) return 1;
|
||||
if (string.IsNullOrEmpty(y)) return -1;
|
||||
return ToCopperPieces(x) - ToCopperPieces(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,10 @@ namespace AideDeJeu.ViewModels
|
|||
MaxPower,
|
||||
Size,
|
||||
Legendary,
|
||||
MinPrice,
|
||||
MaxPrice,
|
||||
MinWeight,
|
||||
MaxWeight,
|
||||
}
|
||||
|
||||
public class Filter : BaseViewModel
|
||||
|
|
@ -729,4 +733,104 @@ namespace AideDeJeu.ViewModels
|
|||
};
|
||||
}
|
||||
#endregion Monsters
|
||||
}
|
||||
|
||||
#region Equipments
|
||||
public abstract class EquipmentFilterViewModel : FilterViewModel
|
||||
{
|
||||
private IEnumerable<Filter> _Filters = null;
|
||||
public override IEnumerable<Filter> Filters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Filters == null)
|
||||
{
|
||||
_Filters = new List<Filter>()
|
||||
{
|
||||
new Filter() { Key = FilterKeys.Type, Name = "Type", KeyValues = Types, _Index = 0 },
|
||||
new Filter() { Key = FilterKeys.MinPrice, Name = "Prix Minimum", KeyValues = Prices, _Index = 0 },
|
||||
new Filter() { Key = FilterKeys.MaxPrice, Name = "Prix Maximum", KeyValues = Prices, _Index = 7 },
|
||||
};
|
||||
RegisterFilters();
|
||||
}
|
||||
return _Filters;
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task<IEnumerable<Item>> FilterItems(IEnumerable<Item> items, CancellationToken token = default)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var priceComparer = new PriceComparer();
|
||||
var type = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Type).SelectedKey ?? "";
|
||||
var minPrice = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinPrice).SelectedKey ?? "0 pc";
|
||||
var maxPrice = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxPrice).SelectedKey ?? "1 000 000 po";
|
||||
token.ThrowIfCancellationRequested();
|
||||
return items.Where(item =>
|
||||
{
|
||||
var equipment = item as Equipment;
|
||||
return equipment.Type.ToLower().Contains(type.ToLower()) &&
|
||||
priceComparer.Compare(equipment.Price, minPrice) >= 0 &&
|
||||
priceComparer.Compare(equipment.Price, maxPrice) <= 0 &&
|
||||
(
|
||||
(Helpers.RemoveDiacritics(equipment.Name).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower())) ||
|
||||
(Helpers.RemoveDiacritics(equipment.AltNameText ?? string.Empty).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower()))
|
||||
);
|
||||
}).OrderBy(eq => eq.Name)
|
||||
.AsEnumerable();
|
||||
}, token);
|
||||
|
||||
}
|
||||
|
||||
public abstract List<KeyValuePair<string, string>> Types { get; }
|
||||
|
||||
public abstract List<KeyValuePair<string, string>> Prices { get; }
|
||||
}
|
||||
|
||||
public class VFEquipmentFilterViewModel : EquipmentFilterViewModel
|
||||
{
|
||||
|
||||
public override List<KeyValuePair<string, string>> Types { get; } = new List<KeyValuePair<string, string>>()
|
||||
{
|
||||
new KeyValuePair<string, string>("", "Toutes" ),
|
||||
new KeyValuePair<string, string>("Armure", "Armure" ),
|
||||
new KeyValuePair<string, string>("Armure légère", "Armure légère" ),
|
||||
new KeyValuePair<string, string>("Armure intermédiaire", "Armure intermédiaire" ),
|
||||
new KeyValuePair<string, string>("Armure lourde", "Armure lourde" ),
|
||||
new KeyValuePair<string, string>("Bouclier", "Bouclier" ),
|
||||
new KeyValuePair<string, string>("Arme", "Arme" ),
|
||||
new KeyValuePair<string, string>("Arme de corps-à-corps", "Arme de corps-à-corps" ),
|
||||
new KeyValuePair<string, string>("Arme à distance", "Arme à distance" ),
|
||||
new KeyValuePair<string, string>("Équipement d'aventurier", "Équipement d'aventurier" ),
|
||||
new KeyValuePair<string, string>("Focaliseur arcanique", "Focaliseur arcanique" ),
|
||||
new KeyValuePair<string, string>("Focaliseur druidique", "Focaliseur druidique" ),
|
||||
new KeyValuePair<string, string>("Munitions", "Munitions" ),
|
||||
new KeyValuePair<string, string>("Symbole sacré", "Symbole sacré" ),
|
||||
new KeyValuePair<string, string>("Vêtements", "Vêtements" ),
|
||||
new KeyValuePair<string, string>("Outil", "Outil" ),
|
||||
new KeyValuePair<string, string>("Instrument de musique", "Instrument de musique" ),
|
||||
new KeyValuePair<string, string>("Jeu", "Jeu" ),
|
||||
new KeyValuePair<string, string>("Outil d'artisan", "Outil d'artisan" ),
|
||||
new KeyValuePair<string, string>("Monture", "Monture" ),
|
||||
new KeyValuePair<string, string>("Équipement, sellerie et véhicules à traction", "Équipement, sellerie et véhicules à traction" ),
|
||||
new KeyValuePair<string, string>("Bateau", "Bateau" ),
|
||||
new KeyValuePair<string, string>("Marchandise", "Marchandise" ),
|
||||
new KeyValuePair<string, string>("Nourriture, boisson et logement", "Nourriture, boisson et logement" ),
|
||||
};
|
||||
|
||||
public override List<KeyValuePair<string, string>> Prices { get; } = new List<KeyValuePair<string, string>>()
|
||||
{
|
||||
new KeyValuePair<string, string>("0 pc", "0 pc" ),
|
||||
new KeyValuePair<string, string>("1 pc", "1 pc" ),
|
||||
new KeyValuePair<string, string>("1 pa", "1 pa" ),
|
||||
new KeyValuePair<string, string>("1 po", "1 po" ),
|
||||
new KeyValuePair<string, string>("10 po", "10 po" ),
|
||||
new KeyValuePair<string, string>("100 po", "100 po" ),
|
||||
new KeyValuePair<string, string>("1 000 po", "1 000 po" ),
|
||||
new KeyValuePair<string, string>("10 000 po", "10 000 po" ),
|
||||
new KeyValuePair<string, string>("100 000 po", "100 000 po" ),
|
||||
new KeyValuePair<string, string>("1 000 000 po", "1 000 000 po" ),
|
||||
};
|
||||
}
|
||||
|
||||
#endregion Equipments
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue