mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 06:26:02 +00:00
Nouvelles polices
This commit is contained in:
parent
b5ab129daa
commit
0d1fe544c5
15 changed files with 559 additions and 434 deletions
|
|
@ -26,6 +26,11 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidLinkMode>None</AndroidLinkMode>
|
||||
<AotAssemblies>false</AotAssemblies>
|
||||
<EnableLLVM>false</EnableLLVM>
|
||||
<BundleAssemblies>false</BundleAssemblies>
|
||||
<AndroidSupportedAbis />
|
||||
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
|
@ -58,6 +63,7 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidAsset Include="Assets\LinLibertine_R.ttf" />
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
<None Include="Assets\AboutAssets.txt" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
BIN
AideDeJeu/AideDeJeu.Android/Assets/LinLibertine_R.ttf
Normal file
BIN
AideDeJeu/AideDeJeu.Android/Assets/LinLibertine_R.ttf
Normal file
Binary file not shown.
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.AideDeJeu">
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.AideDeJeu" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="15" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application android:label="AideDeJeu.Android"></application>
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
|
@ -102,6 +102,7 @@
|
|||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<None Include="AideDeJeu.UWP_TemporaryKey.pfx" />
|
||||
<Content Include="Assets\Fonts\LinLibertine_R.ttf" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Properties\Default.rd.xml" />
|
||||
|
|
@ -150,7 +151,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.1"/>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AideDeJeu\AideDeJeu.csproj">
|
||||
|
|
@ -158,6 +159,7 @@
|
|||
<Name>AideDeJeu</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
BIN
AideDeJeu/AideDeJeu.UWP/Assets/Fonts/LinLibertine_R.ttf
Normal file
BIN
AideDeJeu/AideDeJeu.UWP/Assets/Fonts/LinLibertine_R.ttf
Normal file
Binary file not shown.
|
|
@ -93,6 +93,9 @@
|
|||
<None Include="Entitlements.plist" />
|
||||
<None Include="Info.plist" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<BundleResource Include="Resources\Fonts\LinLibertine_R.ttf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</BundleResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BundleResource Include="Resources\Default-568h%402x.png" />
|
||||
|
|
|
|||
BIN
AideDeJeu/AideDeJeu.iOS/Resources/Fonts/LinLibertine_R.ttf
Normal file
BIN
AideDeJeu/AideDeJeu.iOS/Resources/Fonts/LinLibertine_R.ttf
Normal file
Binary file not shown.
|
|
@ -4,6 +4,10 @@
|
|||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Remove="Resources\AdJTheme.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,87 @@
|
|||
<Color x:Key="MediumGrayTextColor">#4d4d4d</Color>
|
||||
<Color x:Key="LightTextColor">#999999</Color>
|
||||
|
||||
|
||||
|
||||
<!-- https://github.com/evanbergeron/DND-5e-LaTeX-Template/blob/master/lib/dndcolors.sty -->
|
||||
|
||||
<Color x:Key="bgtan">#F7F2E5</Color> <!--% background and quotebox-->
|
||||
<Color x:Key="pagegold">#B89A67</Color> <!--% pagenumbers and footer-->
|
||||
|
||||
<!--% Type-->
|
||||
<Color x:Key="titlered">#58180D</Color> <!--% titles-->
|
||||
<Color x:Key="titlegold">#C9AD6A</Color> <!--% titlerules-->
|
||||
<Color x:Key="rulered">#9C2B1B</Color> <!--% triangular rule in statsblock-->
|
||||
|
||||
<!--% Trim (affects tables and paperboxes)-->
|
||||
<Color x:Key="PhbLightGreen">#E0E5C1</Color> <!--% PHB Part 1-->
|
||||
<Color x:Key="PhbLightCyan">#B5CEB8</Color> <!--% PHB Part 2-->
|
||||
<Color x:Key="PhbMauve">#DCCCC5</Color> <!--% PHB Part 3-->
|
||||
<Color x:Key="PhbTan">#E5D5AC</Color> <!--% PHB appendix-->
|
||||
<Color x:Key="DmgLavender">#E3CED3</Color> <!--% DMG Part 1-->
|
||||
<Color x:Key="DmgCoral">#F3D7C1</Color> <!--% DMG Part 2-->
|
||||
<Color x:Key="DmgSlateGray">#DBE4E4</Color> <!--% DMG Part 3-->
|
||||
<Color x:Key="DmgLilac">#D7D4D6</Color> <!--% DMG appendix-->
|
||||
|
||||
<!--% Trim aliases-->
|
||||
<Color x:Key="DmgSlateGrey">#DBE4E4</Color>
|
||||
|
||||
<!--% The color used in \setthemecolor when a new color is not set-->
|
||||
<Color x:Key="themecolor">#E0E5C1</Color> <!--% Set the default theme to Part 1 of the PHB.-->
|
||||
|
||||
<!--% Element colors that change when \setthemecolor is used-->
|
||||
<Color x:Key="commentboxcolor">#E0E5C1</Color> <!--% commentbox background-->
|
||||
<Color x:Key="paperboxcolor">#E0E5C1</Color> <!--% paperbox background-->
|
||||
<Color x:Key="tablecolor">#E0E5C1</Color> <!--% table even row background-->
|
||||
|
||||
<!--% Element colors that do not respond to \setthemecolor-->
|
||||
<Color x:Key="quoteboxcolor">#F7F2E5</Color> <!--% quotebox background-->
|
||||
<Color x:Key="statblockribbon">#E69A28</Color> <!--% stat block top/bottom borders (gold)-->
|
||||
<Color x:Key="statblockbg">#FDF1DC</Color> <!--% stat block background (tan)-->
|
||||
|
||||
<!--% Sets the themecolor and colors for all themed elements
|
||||
% If called without the optional color, resets the color of all themed elements to the current themecolor
|
||||
\newcommand{\setthemecolor}[1][themecolor]{%
|
||||
\colorlet{themecolor}{#1}
|
||||
\colorlet{commentboxcolor}{#1}
|
||||
\colorlet{paperboxcolor}{#1}
|
||||
\colorlet{tablecolor}{#1}
|
||||
}-->
|
||||
|
||||
<!--% Backwards-compatible aliases and colours-->
|
||||
<Color x:Key="commentgreen">#E0E5C1</Color>
|
||||
<Color x:Key="itemtablepink">#F3D7C1</Color>
|
||||
<Color x:Key="monstertan">#FDF1DC</Color>
|
||||
<Color x:Key="monstertandark">#F0DBB5</Color>
|
||||
|
||||
<Style TargetType="Label" x:Key="section">
|
||||
<Setter Property="FontSize" Value="Large" />
|
||||
<Setter Property="TextColor" Value="{StaticResource titlered}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Label" x:Key="subsection">
|
||||
<Setter Property="FontSize" Value="Medium" />
|
||||
<Setter Property="TextColor" Value="{StaticResource titlered}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Label" x:Key="subsubsection">
|
||||
<Setter Property="FontSize" Value="Small" />
|
||||
<Setter Property="TextColor" Value="{StaticResource titlered}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="ContentPage">
|
||||
<Setter Property="BackgroundColor" Value="{StaticResource bgtan}" />
|
||||
</Style>
|
||||
|
||||
<OnPlatform x:Key="LibertineR" x:TypeArguments="x:String">
|
||||
<On Platform="iOS" Value="Lobster-Regular" />
|
||||
<On Platform="Android" Value="LinLibertine_R.ttf#Linux Libertine" />
|
||||
<On Platform="UWP, WinRT, WinPhone" Value="Assets/Fonts/LinLibertine_R.ttf#Linux Libertine" />
|
||||
</OnPlatform>
|
||||
<Style TargetType="Label">
|
||||
<Setter Property="FontFamily" Value="{DynamicResource LibertineR}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="NavigationPage">
|
||||
<Setter Property="BarBackgroundColor" Value="{StaticResource Primary}" />
|
||||
<Setter Property="BarTextColor" Value="White" />
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
x:Class="AideDeJeu.Views.ItemDetailPage"
|
||||
Title="{Binding Title}">
|
||||
<StackLayout Spacing="20" Padding="15">
|
||||
<Label Text="Text:" FontSize="Medium" />
|
||||
<Label Text="{Binding Item.Text}" FontSize="Small"/>
|
||||
<Label Text="Description:" FontSize="Medium" />
|
||||
<Label Text="{Binding Item.Description}" FontSize="Small"/>
|
||||
<Label Text="{Binding Item.Text}" Style="{StaticResource Key=section}" />
|
||||
<Label Text="{Binding Item.Description}" Style="{StaticResource Key=subsection}" />
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
224
AideDeJeu/AideDeJeuLib/Cards.cs
Normal file
224
AideDeJeu/AideDeJeuLib/Cards.cs
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
/*public class CardDataOwner
|
||||
{
|
||||
public CardData[] CardDatas { get; set; }
|
||||
}*/
|
||||
[DataContract]
|
||||
public class CardData
|
||||
{
|
||||
[DataMember(Name = "count")]
|
||||
public int Count { get; set; }
|
||||
[DataMember(Name = "color")]
|
||||
public string Color { get; set; }
|
||||
[DataMember(Name = "title")]
|
||||
public string Title { get; set; }
|
||||
[DataMember(Name = "title_size")]
|
||||
public string TitleSize { get; set; }
|
||||
[DataMember(Name = "icon")]
|
||||
public string Icon { get; set; }
|
||||
[DataMember(Name = "icon_back")]
|
||||
public string IconBack { get; set; }
|
||||
[DataMember(Name = "contents")]
|
||||
public string[] ContentsToString { get { return Contents.Select(cc => cc.ToString()).ToArray(); } }
|
||||
[IgnoreDataMember]
|
||||
public CardContent[] Contents { get; set; }
|
||||
[DataMember(Name = "tags")]
|
||||
public string[] Tags { get; set; }
|
||||
[DataMember(Name = "background_image")]
|
||||
public string BackgroundImage { get; set; }
|
||||
}
|
||||
|
||||
public interface CardContent
|
||||
{
|
||||
int Height { get; }
|
||||
}
|
||||
|
||||
public class SubtitleCardContent : CardContent
|
||||
{
|
||||
public string Subtitle { get; set; }
|
||||
|
||||
public SubtitleCardContent(string subtitle)
|
||||
{
|
||||
Subtitle = subtitle;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "subtitle | " + Subtitle;
|
||||
}
|
||||
|
||||
public int Height { get { return 12; } }
|
||||
}
|
||||
|
||||
public class RuleCardContent : CardContent
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "rule";
|
||||
}
|
||||
|
||||
public int Height { get { return 15; } }
|
||||
}
|
||||
|
||||
public class PropertyCardContent : CardContent
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
public PropertyCardContent(string name, string value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "property | " + Name + " | " + Value;
|
||||
}
|
||||
|
||||
public int Height { get { return ((Name.Length + Value.Length) / 35 + 1) * 15; } }
|
||||
}
|
||||
|
||||
public class FillCardContent : CardContent
|
||||
{
|
||||
public int Fill { get; set; }
|
||||
|
||||
public FillCardContent(int fill)
|
||||
{
|
||||
Fill = fill;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "fill | " + Fill;
|
||||
}
|
||||
|
||||
public int Height { get { return 1; } }
|
||||
}
|
||||
|
||||
public class TextCardContent : CardContent
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
||||
public TextCardContent(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "text | " + Text;
|
||||
}
|
||||
|
||||
public int Height { get { return (Text.Length / 35 + 1) * 15 + 6; } }
|
||||
}
|
||||
|
||||
public class SectionCardContent : CardContent
|
||||
{
|
||||
public string Section { get; set; }
|
||||
|
||||
public SectionCardContent(string section)
|
||||
{
|
||||
Section = section;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "section | " + Section;
|
||||
}
|
||||
|
||||
public int Height { get { return 20; } }
|
||||
}
|
||||
|
||||
public class DescriptionCardContent : CardContent
|
||||
{
|
||||
public string Quality { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public DescriptionCardContent(string quality, string text)
|
||||
{
|
||||
Quality = quality;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "description | " + Quality + " | " + Text;
|
||||
}
|
||||
|
||||
public int Height { get { return ((Quality.Length + Text.Length) / 35 + 1) * 15 + 6; } }
|
||||
}
|
||||
|
||||
public class BulletCardContent : CardContent
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
||||
public BulletCardContent(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "bullet | " + Text;
|
||||
}
|
||||
|
||||
public int Height { get { return (Text.Length / 30 + 1) * 15; } }
|
||||
}
|
||||
|
||||
public class BoxesCardContent : CardContent
|
||||
{
|
||||
public int Count { get; set; }
|
||||
|
||||
public int Size { get; set; }
|
||||
|
||||
public BoxesCardContent(int count, int size)
|
||||
{
|
||||
Count = count;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "boxes | " + Count + " | " + Size;
|
||||
}
|
||||
|
||||
public int Height { get { return 16; } }
|
||||
}
|
||||
|
||||
public class DndstatsCardContent : CardContent
|
||||
{
|
||||
public int Strength { get; set; }
|
||||
public int Dexterity { get; set; }
|
||||
public int Constitution { get; set; }
|
||||
public int Intelligence { get; set; }
|
||||
public int Wisdom { get; set; }
|
||||
public int Charisma { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return "dndstats | " + Strength + " | " + Dexterity + " | " + Constitution + " | " + Intelligence + " | " + Wisdom + " | " + Charisma;
|
||||
}
|
||||
|
||||
public int Height { get { return 20; } }
|
||||
}
|
||||
|
||||
public class EmptyCardContent : CardContent
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public int Height { get { return 0; } }
|
||||
}
|
||||
|
||||
}
|
||||
191
AideDeJeu/AideDeJeuLib/Converters.cs
Normal file
191
AideDeJeu/AideDeJeuLib/Converters.cs
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
using HtmlAgilityPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
public static class Converters
|
||||
{
|
||||
public static CardContent TextToCardContent(string text)
|
||||
{
|
||||
if (text.StartsWith("•"))
|
||||
{
|
||||
return new BulletCardContent(text.Substring(1));
|
||||
}
|
||||
else if (text.Trim(new char[] { ' ', '\n' }) == ".")
|
||||
{
|
||||
return new EmptyCardContent();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TextCardContent(text);
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] SplitText(string text)
|
||||
{
|
||||
var texts = new List<string>();
|
||||
string str = "";
|
||||
bool autoreturn = true;
|
||||
foreach (var car in text)
|
||||
{
|
||||
if (car == '\n')
|
||||
{
|
||||
texts.Add(str);
|
||||
str = "";
|
||||
autoreturn = true;
|
||||
}
|
||||
else if (car == '.')
|
||||
{
|
||||
if (autoreturn)
|
||||
{
|
||||
texts.Add(str + '.');
|
||||
str = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
str += car;
|
||||
}
|
||||
}
|
||||
else if (car == '•')
|
||||
{
|
||||
texts.Add(str);
|
||||
str = "•";
|
||||
autoreturn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
str += car;
|
||||
}
|
||||
}
|
||||
if (str.Length > 0)
|
||||
{
|
||||
texts.Add(str);
|
||||
}
|
||||
return texts.ToArray();
|
||||
}
|
||||
|
||||
public static CardContent[] ToContents(HtmlNode description)
|
||||
{
|
||||
var contents = new List<CardContent>();
|
||||
string currentText = "";
|
||||
foreach (var content in description.ChildNodes)
|
||||
{
|
||||
//Debug.WriteLine(content.NodeType + " " + content.Name + " " + content.InnerText);
|
||||
if (content.NodeType == HtmlNodeType.Element && content.Name == "strong")
|
||||
{
|
||||
if (currentText.Length > 0)
|
||||
{
|
||||
contents.Add(TextToCardContent(currentText));
|
||||
currentText = "";
|
||||
}
|
||||
contents.Add(new SectionCardContent(content.InnerText));
|
||||
}
|
||||
else if (content.NodeType == HtmlNodeType.Element && content.Name == "em")
|
||||
{
|
||||
currentText += "<em>" + content.InnerText + "</em>";
|
||||
}
|
||||
else if (content.NodeType == HtmlNodeType.Text)
|
||||
{
|
||||
var texts = SplitText(content.InnerText);
|
||||
for (int i = 0; i < texts.Length - 1; i++)
|
||||
{
|
||||
contents.Add(TextToCardContent(currentText + texts[i]));
|
||||
currentText = "";
|
||||
}
|
||||
currentText += texts[texts.Length - 1];
|
||||
}
|
||||
}
|
||||
if (currentText.Length > 0)
|
||||
{
|
||||
contents.Add(TextToCardContent(currentText));
|
||||
currentText = "";
|
||||
}
|
||||
return contents.ToArray();
|
||||
}
|
||||
|
||||
public static CardData ToBaseCardData(IReadOnlyDictionary<string, string> context, Spell spell)
|
||||
{
|
||||
string color = context["color"];
|
||||
string backgroundImage = context["background_image"];
|
||||
var cardData = new CardData();
|
||||
cardData.Count = 1;
|
||||
cardData.Color = color;
|
||||
cardData.Title = spell.Title;
|
||||
cardData.TitleSize = "10";
|
||||
cardData.Icon = "white-book-" + spell.Level;
|
||||
cardData.IconBack = "robe";
|
||||
cardData.BackgroundImage = backgroundImage;
|
||||
cardData.Tags = new string[]
|
||||
{
|
||||
"sort",
|
||||
"magicien",
|
||||
};
|
||||
return cardData;
|
||||
}
|
||||
public static CardData[] ToCardDatas(IReadOnlyDictionary<string, string> context, Spell spell)
|
||||
{
|
||||
var cardDatas = new List<CardData>();
|
||||
var cardData = ToBaseCardData(context, spell);
|
||||
|
||||
var contents = new List<CardContent>();
|
||||
contents.AddRange(new CardContent[]
|
||||
{
|
||||
new SubtitleCardContent(spell.LevelType),
|
||||
new RuleCardContent(),
|
||||
new PropertyCardContent("Temps d'incantation", spell.CastingTime),
|
||||
new PropertyCardContent("Portée", spell.Range),
|
||||
new PropertyCardContent("Composants", spell.Components),
|
||||
new RuleCardContent(),
|
||||
//new FillCardContent(1),
|
||||
//new TextCardContent(spell.Description),
|
||||
});
|
||||
var description = ToContents(spell.DescriptionDiv);
|
||||
foreach (var line in description)
|
||||
{
|
||||
int size = contents.Sum(cc => cc.Height);
|
||||
if (line.Height == 0)
|
||||
{
|
||||
|
||||
}
|
||||
else if (size + line.Height <= 295)
|
||||
{
|
||||
contents.Add(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
CardContent section = null;
|
||||
if (contents.LastOrDefault() is SectionCardContent)
|
||||
{
|
||||
section = contents.LastOrDefault();
|
||||
contents.RemoveAt(contents.Count - 1);
|
||||
}
|
||||
cardData.Contents = contents.ToArray();
|
||||
cardDatas.Add(cardData);
|
||||
|
||||
cardData = ToBaseCardData(context, spell);
|
||||
contents = new List<CardContent>();
|
||||
if (section != null)
|
||||
{
|
||||
contents.Add(section);
|
||||
}
|
||||
contents.Add(line);
|
||||
}
|
||||
}
|
||||
cardData.Contents = contents.ToArray();
|
||||
cardDatas.Add(cardData);
|
||||
|
||||
if (cardDatas.Count > 1)
|
||||
{
|
||||
for (int i = 0; i < cardDatas.Count; i++)
|
||||
{
|
||||
cardDatas[i].Title += string.Format(" ({0}/{1})", i + 1, cardDatas.Count);
|
||||
}
|
||||
}
|
||||
return cardDatas.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,16 +13,22 @@ namespace AideDeJeuLib
|
|||
{
|
||||
public class Scrappers
|
||||
{
|
||||
public HttpClient GetHttpClient()
|
||||
{
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
||||
return client;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<string>> GetSpellIds(string classe, int niveauMin = 0, int niveauMax = 9)
|
||||
{
|
||||
string html = null;
|
||||
using (var client = new HttpClient())
|
||||
using (var client = GetHttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
||||
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
||||
// https://www.aidedd.org/dnd/sorts.php?vf=rayon-de-givre
|
||||
// https://www.aidedd.org/regles/sorts/
|
||||
|
|
@ -37,13 +43,8 @@ namespace AideDeJeuLib
|
|||
public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds)
|
||||
{
|
||||
string html = null;
|
||||
using (var client = new HttpClient())
|
||||
using (var client = GetHttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
||||
var content = new MultipartFormDataContent();
|
||||
content.Add(new StringContent("card"), "format");
|
||||
foreach (var spellId in spellIds)
|
||||
|
|
@ -80,7 +81,7 @@ namespace AideDeJeuLib
|
|||
}
|
||||
return newSpells;
|
||||
}
|
||||
public async Task<string> OnGetAsync(Dictionary<string, string> context)
|
||||
public async Task<string> OnGetAsync(IReadOnlyDictionary<string, string> context)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
//client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(new System.Net.Http.Headers.ProductHeaderValue("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0")));
|
||||
|
|
@ -147,7 +148,7 @@ namespace AideDeJeuLib
|
|||
newSpell.NoOverflow = spell.SelectSingleNode("div[@class='nooverflow']")?.InnerText;
|
||||
newSpell.Source = spell.SelectSingleNode("div[@class='source']").InnerText;
|
||||
newSpells.Add(newSpell);
|
||||
cardDatas.AddRange(ToCardDatas(context, newSpell));
|
||||
cardDatas.AddRange(Converters.ToCardDatas(context, newSpell));
|
||||
}
|
||||
//Debug.WriteLine(htmlSpell);
|
||||
|
||||
|
|
@ -187,418 +188,6 @@ namespace AideDeJeuLib
|
|||
|
||||
}
|
||||
|
||||
public CardContent TextToCardContent(string text)
|
||||
{
|
||||
if (text.StartsWith("•"))
|
||||
{
|
||||
return new BulletCardContent(text.Substring(1));
|
||||
}
|
||||
else if (text.Trim(new char[] { ' ', '\n' }) == ".")
|
||||
{
|
||||
return new EmptyCardContent();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TextCardContent(text);
|
||||
}
|
||||
}
|
||||
|
||||
public string[] SplitText(string text)
|
||||
{
|
||||
var texts = new List<string>();
|
||||
string str = "";
|
||||
bool autoreturn = true;
|
||||
foreach (var car in text)
|
||||
{
|
||||
if (car == '\n')
|
||||
{
|
||||
texts.Add(str);
|
||||
str = "";
|
||||
autoreturn = true;
|
||||
}
|
||||
else if (car == '.')
|
||||
{
|
||||
if (autoreturn)
|
||||
{
|
||||
texts.Add(str + '.');
|
||||
str = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
str += car;
|
||||
}
|
||||
}
|
||||
else if (car == '•')
|
||||
{
|
||||
texts.Add(str);
|
||||
str = "•";
|
||||
autoreturn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
str += car;
|
||||
}
|
||||
}
|
||||
if (str.Length > 0)
|
||||
{
|
||||
texts.Add(str);
|
||||
}
|
||||
return texts.ToArray();
|
||||
}
|
||||
|
||||
public CardContent[] ToContents(HtmlNode description)
|
||||
{
|
||||
var contents = new List<CardContent>();
|
||||
string currentText = "";
|
||||
foreach (var content in description.ChildNodes)
|
||||
{
|
||||
//Debug.WriteLine(content.NodeType + " " + content.Name + " " + content.InnerText);
|
||||
if (content.NodeType == HtmlNodeType.Element && content.Name == "strong")
|
||||
{
|
||||
if (currentText.Length > 0)
|
||||
{
|
||||
contents.Add(TextToCardContent(currentText));
|
||||
currentText = "";
|
||||
}
|
||||
contents.Add(new SectionCardContent(content.InnerText));
|
||||
}
|
||||
else if (content.NodeType == HtmlNodeType.Element && content.Name == "em")
|
||||
{
|
||||
currentText += "<em>" + content.InnerText + "</em>";
|
||||
}
|
||||
else if (content.NodeType == HtmlNodeType.Text)
|
||||
{
|
||||
var texts = SplitText(content.InnerText);
|
||||
for (int i = 0; i < texts.Length - 1; i++)
|
||||
{
|
||||
contents.Add(TextToCardContent(currentText + texts[i]));
|
||||
currentText = "";
|
||||
}
|
||||
currentText += texts[texts.Length - 1];
|
||||
}
|
||||
}
|
||||
if (currentText.Length > 0)
|
||||
{
|
||||
contents.Add(TextToCardContent(currentText));
|
||||
currentText = "";
|
||||
}
|
||||
return contents.ToArray();
|
||||
}
|
||||
|
||||
public CardData ToBaseCardData(Dictionary<string, string> context, Spell spell)
|
||||
{
|
||||
string color = context["color"];
|
||||
string backgroundImage = context["background_image"];
|
||||
var cardData = new CardData();
|
||||
cardData.Count = 1;
|
||||
cardData.Color = color;
|
||||
cardData.Title = spell.Title;
|
||||
cardData.TitleSize = "10";
|
||||
cardData.Icon = "white-book-" + spell.Level;
|
||||
cardData.IconBack = "robe";
|
||||
cardData.BackgroundImage = backgroundImage;
|
||||
cardData.Tags = new string[]
|
||||
{
|
||||
"sort",
|
||||
"magicien",
|
||||
};
|
||||
return cardData;
|
||||
}
|
||||
public CardData[] ToCardDatas(Dictionary<string, string> context, Spell spell)
|
||||
{
|
||||
var cardDatas = new List<CardData>();
|
||||
var cardData = ToBaseCardData(context, spell);
|
||||
|
||||
var contents = new List<CardContent>();
|
||||
contents.AddRange(new CardContent[]
|
||||
{
|
||||
new SubtitleCardContent(spell.LevelType),
|
||||
new RuleCardContent(),
|
||||
new PropertyCardContent("Temps d'incantation", spell.CastingTime),
|
||||
new PropertyCardContent("Portée", spell.Range),
|
||||
new PropertyCardContent("Composants", spell.Components),
|
||||
new RuleCardContent(),
|
||||
//new FillCardContent(1),
|
||||
//new TextCardContent(spell.Description),
|
||||
});
|
||||
var description = ToContents(spell.DescriptionDiv);
|
||||
foreach (var line in description)
|
||||
{
|
||||
int size = contents.Sum(cc => cc.Height);
|
||||
if (line.Height == 0)
|
||||
{
|
||||
|
||||
}
|
||||
else if (size + line.Height <= 295)
|
||||
{
|
||||
contents.Add(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
CardContent section = null;
|
||||
if (contents.LastOrDefault() is SectionCardContent)
|
||||
{
|
||||
section = contents.LastOrDefault();
|
||||
contents.RemoveAt(contents.Count - 1);
|
||||
}
|
||||
cardData.Contents = contents.ToArray();
|
||||
cardDatas.Add(cardData);
|
||||
|
||||
cardData = ToBaseCardData(context, spell);
|
||||
contents = new List<CardContent>();
|
||||
if (section != null)
|
||||
{
|
||||
contents.Add(section);
|
||||
}
|
||||
contents.Add(line);
|
||||
}
|
||||
}
|
||||
cardData.Contents = contents.ToArray();
|
||||
cardDatas.Add(cardData);
|
||||
|
||||
if (cardDatas.Count > 1)
|
||||
{
|
||||
for (int i = 0; i < cardDatas.Count; i++)
|
||||
{
|
||||
cardDatas[i].Title += string.Format(" ({0}/{1})", i + 1, cardDatas.Count);
|
||||
}
|
||||
}
|
||||
return cardDatas.ToArray();
|
||||
}
|
||||
|
||||
public class Spell
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string TitleUS { get; set; }
|
||||
public string LevelType { get; set; }
|
||||
public string Level { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string CastingTime { get; set; }
|
||||
public string Range { get; set; }
|
||||
public string Components { get; set; }
|
||||
public string Duration { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DescriptionText { get; set; }
|
||||
public HtmlNode DescriptionDiv { get; set; }
|
||||
public string Overflow { get; set; }
|
||||
public string NoOverflow { get; set; }
|
||||
public string Source { get; set; }
|
||||
}
|
||||
|
||||
/*public class CardDataOwner
|
||||
{
|
||||
public CardData[] CardDatas { get; set; }
|
||||
}*/
|
||||
[DataContract]
|
||||
public class CardData
|
||||
{
|
||||
[DataMember(Name = "count")]
|
||||
public int Count { get; set; }
|
||||
[DataMember(Name = "color")]
|
||||
public string Color { get; set; }
|
||||
[DataMember(Name = "title")]
|
||||
public string Title { get; set; }
|
||||
[DataMember(Name = "title_size")]
|
||||
public string TitleSize { get; set; }
|
||||
[DataMember(Name = "icon")]
|
||||
public string Icon { get; set; }
|
||||
[DataMember(Name = "icon_back")]
|
||||
public string IconBack { get; set; }
|
||||
[DataMember(Name = "contents")]
|
||||
public string[] ContentsToString { get { return Contents.Select(cc => cc.ToString()).ToArray(); } }
|
||||
[IgnoreDataMember]
|
||||
public CardContent[] Contents { get; set; }
|
||||
[DataMember(Name = "tags")]
|
||||
public string[] Tags { get; set; }
|
||||
[DataMember(Name = "background_image")]
|
||||
public string BackgroundImage { get; set; }
|
||||
}
|
||||
|
||||
public interface CardContent
|
||||
{
|
||||
int Height { get; }
|
||||
}
|
||||
|
||||
public class SubtitleCardContent : CardContent
|
||||
{
|
||||
public string Subtitle { get; set; }
|
||||
|
||||
public SubtitleCardContent(string subtitle)
|
||||
{
|
||||
Subtitle = subtitle;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "subtitle | " + Subtitle;
|
||||
}
|
||||
|
||||
public int Height { get { return 12; } }
|
||||
}
|
||||
|
||||
public class RuleCardContent : CardContent
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "rule";
|
||||
}
|
||||
|
||||
public int Height { get { return 15; } }
|
||||
}
|
||||
|
||||
public class PropertyCardContent : CardContent
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
public PropertyCardContent(string name, string value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "property | " + Name + " | " + Value;
|
||||
}
|
||||
|
||||
public int Height { get { return ((Name.Length + Value.Length) / 35 + 1) * 15; } }
|
||||
}
|
||||
|
||||
public class FillCardContent : CardContent
|
||||
{
|
||||
public int Fill { get; set; }
|
||||
|
||||
public FillCardContent(int fill)
|
||||
{
|
||||
Fill = fill;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "fill | " + Fill;
|
||||
}
|
||||
|
||||
public int Height { get { return 1; } }
|
||||
}
|
||||
|
||||
public class TextCardContent : CardContent
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
||||
public TextCardContent(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "text | " + Text;
|
||||
}
|
||||
|
||||
public int Height { get { return (Text.Length / 35 + 1) * 15 + 6; } }
|
||||
}
|
||||
|
||||
public class SectionCardContent : CardContent
|
||||
{
|
||||
public string Section { get; set; }
|
||||
|
||||
public SectionCardContent(string section)
|
||||
{
|
||||
Section = section;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "section | " + Section;
|
||||
}
|
||||
|
||||
public int Height { get { return 20; } }
|
||||
}
|
||||
|
||||
public class DescriptionCardContent : CardContent
|
||||
{
|
||||
public string Quality { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public DescriptionCardContent(string quality, string text)
|
||||
{
|
||||
Quality = quality;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "description | " + Quality + " | " + Text;
|
||||
}
|
||||
|
||||
public int Height { get { return ((Quality.Length + Text.Length) / 35 + 1) * 15 + 6; } }
|
||||
}
|
||||
|
||||
public class BulletCardContent : CardContent
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
||||
public BulletCardContent(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "bullet | " + Text;
|
||||
}
|
||||
|
||||
public int Height { get { return (Text.Length / 30 + 1) * 15; } }
|
||||
}
|
||||
|
||||
public class BoxesCardContent : CardContent
|
||||
{
|
||||
public int Count { get; set; }
|
||||
|
||||
public int Size { get; set; }
|
||||
|
||||
public BoxesCardContent(int count, int size)
|
||||
{
|
||||
Count = count;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "boxes | " + Count + " | " + Size;
|
||||
}
|
||||
|
||||
public int Height { get { return 16; } }
|
||||
}
|
||||
|
||||
public class DndstatsCardContent : CardContent
|
||||
{
|
||||
public int Strength { get; set; }
|
||||
public int Dexterity { get; set; }
|
||||
public int Constitution { get; set; }
|
||||
public int Intelligence { get; set; }
|
||||
public int Wisdom { get; set; }
|
||||
public int Charisma { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
return "dndstats | " + Strength + " | " + Dexterity + " | " + Constitution + " | " + Intelligence + " | " + Wisdom + " | " + Charisma;
|
||||
}
|
||||
|
||||
public int Height { get { return 20; } }
|
||||
}
|
||||
|
||||
public class EmptyCardContent : CardContent
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public int Height { get { return 0; } }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
26
AideDeJeu/AideDeJeuLib/Spell.cs
Normal file
26
AideDeJeu/AideDeJeuLib/Spell.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using HtmlAgilityPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
public class Spell
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string TitleUS { get; set; }
|
||||
public string LevelType { get; set; }
|
||||
public string Level { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string CastingTime { get; set; }
|
||||
public string Range { get; set; }
|
||||
public string Components { get; set; }
|
||||
public string Duration { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DescriptionText { get; set; }
|
||||
public HtmlNode DescriptionDiv { get; set; }
|
||||
public string Overflow { get; set; }
|
||||
public string NoOverflow { get; set; }
|
||||
public string Source { get; set; }
|
||||
}
|
||||
}
|
||||
BIN
AideDeJeu/linux_libertine.zip
Normal file
BIN
AideDeJeu/linux_libertine.zip
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue