1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Parsing et affichage des vo et alt

This commit is contained in:
Yan Maniez 2018-05-04 00:23:24 +02:00
parent db7564f2ff
commit bdeba80797
12 changed files with 62 additions and 15 deletions

View file

@ -108,6 +108,30 @@ namespace AideDeJeu.Tools
} }
} }
public class ItemTypeConverter<T> : IValueConverter
{
public T Spells { get; set; }
public T Monsters { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var itemType = value as ViewModels.ItemsViewModel.ItemType?;
if (itemType == ViewModels.ItemsViewModel.ItemType.Spell)
{
return Spells;
}
if (itemType == ViewModels.ItemsViewModel.ItemType.Monster)
{
return Monsters;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
public class ItemTypeToStringConverter : ItemTypeConverter<string> { }
} }

View file

@ -11,7 +11,7 @@ namespace AideDeJeu.ViewModels
{ {
Title = "À propos de ..."; Title = "À propos de ...";
OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://github.com/Nioux/AideDeJeu"))); OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://nioux.github.io/AideDeJeu/")));
} }
public ICommand OpenWebCommand { get; } public ICommand OpenWebCommand { get; }

View file

@ -56,14 +56,16 @@ namespace AideDeJeu.ViewModels
public Command SwitchToSpells { get; set; } public Command SwitchToSpells { get; set; }
public Command SwitchToMonsters { get; set; } public Command SwitchToMonsters { get; set; }
public Command AboutCommand { get; set; }
public ItemsViewModel() public ItemsViewModel(INavigation navigation)
{ {
//Title = "Browse"; //Title = "Browse";
//Items = new ObservableCollection<Item>(); //Items = new ObservableCollection<Item>();
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand()); LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
SwitchToSpells = new Command(() => ItemsType = ItemType.Spell); SwitchToSpells = new Command(() => ItemsType = ItemType.Spell);
SwitchToMonsters = new Command(() => ItemsType = ItemType.Monster); SwitchToMonsters = new Command(() => ItemsType = ItemType.Monster);
AboutCommand = new Command(async() => await navigation.PushAsync(new Views.AboutPage()));
} }
async Task ExecuteLoadItemsCommand() async Task ExecuteLoadItemsCommand()
@ -72,7 +74,7 @@ namespace AideDeJeu.ViewModels
{ {
await Spells.ExecuteLoadItemsCommand(); await Spells.ExecuteLoadItemsCommand();
} }
if (ItemsType == ItemType.Monster) else if (ItemsType == ItemType.Monster)
{ {
await Monsters.ExecuteLoadItemsCommand(); await Monsters.ExecuteLoadItemsCommand();
} }

View file

@ -128,7 +128,7 @@ namespace AideDeJeu.ViewModels
LoadItemsCommand.Execute(null); LoadItemsCommand.Execute(null);
} }
} }
private int _MaxPower = 9; private int _MaxPower = 11;
public int MaxPower public int MaxPower
{ {
get get

View file

@ -27,7 +27,7 @@
<FormattedString.Spans> <FormattedString.Spans>
<Span Text="Aide de Jeu" FontAttributes="Bold" FontSize="22" /> <Span Text="Aide de Jeu" FontAttributes="Bold" FontSize="22" />
<Span Text=" " /> <Span Text=" " />
<Span Text="1.0" ForegroundColor="{StaticResource LightTextColor}" /> <Span Text="1.01" ForegroundColor="{StaticResource LightTextColor}" />
</FormattedString.Spans> </FormattedString.Spans>
</FormattedString> </FormattedString>
</Label.FormattedText> </Label.FormattedText>

View file

@ -6,7 +6,7 @@
x:Class="AideDeJeu.Views.ItemsPage" x:Class="AideDeJeu.Views.ItemsPage"
x:Name="This" x:Name="This"
IsPresented="False" IsPresented="False"
Title="Liste des sorts" Title="{Binding ItemsType,Converter={StaticResource ItemTypeToStringConverter}}"
> >
<MasterDetailPage.Resources> <MasterDetailPage.Resources>
<ResourceDictionary> <ResourceDictionary>
@ -67,6 +67,10 @@
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>
</ControlTemplate> </ControlTemplate>
<tools:ItemTypeToStringConverter
x:Key="ItemTypeToStringConverter"
Spells="Sorts"
Monsters="Monstres" />
<tools:ItemsTypeTemplateConverter <tools:ItemsTypeTemplateConverter
x:Key="ItemsTypeTemplateConverter" x:Key="ItemsTypeTemplateConverter"
SpellsTemplate="{StaticResource SpellsMasterDataTemplate}" SpellsTemplate="{StaticResource SpellsMasterDataTemplate}"
@ -74,17 +78,17 @@
</ResourceDictionary> </ResourceDictionary>
</MasterDetailPage.Resources> </MasterDetailPage.Resources>
<MasterDetailPage.Master> <MasterDetailPage.Master>
<ContentPage Title="Liste des sorts"> <ContentPage Title="Liste des sorts 3">
<ContentView ControlTemplate="{Binding ItemsType, Converter={StaticResource ItemsTypeTemplateConverter}}" BindingContext="{Binding}" /> <ContentView ControlTemplate="{Binding ItemsType, Converter={StaticResource ItemsTypeTemplateConverter}}" BindingContext="{Binding}" />
<!--<ContentView ControlTemplate="{StaticResource SpellsMasterDataTemplate}" BindingContext="{Binding}" />--> <!--<ContentView ControlTemplate="{StaticResource SpellsMasterDataTemplate}" BindingContext="{Binding}" />-->
</ContentPage> </ContentPage>
</MasterDetailPage.Master> </MasterDetailPage.Master>
<MasterDetailPage.Detail> <MasterDetailPage.Detail>
<ContentPage Title="Liste des sorts"> <ContentPage Title="Liste des sorts 2">
<ContentPage.ToolbarItems> <ContentPage.ToolbarItems>
<ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="spell_book.png" Command="{Binding SwitchToSpells}" /> <ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="spell_book.png" Command="{Binding SwitchToSpells}" />
<ToolbarItem Name="Monsters" Text="Monstres" Order="Primary" Icon="dragon_head.png" Command="{Binding SwitchToMonsters}" /> <ToolbarItem Name="Monsters" Text="Monstres" Order="Primary" Icon="dragon_head.png" Command="{Binding SwitchToMonsters}" />
<ToolbarItem Name="About" Text="A propos de" Order="Primary" Icon="wooden_sign.png" Command="{Binding SwitchToMonsters}" /> <ToolbarItem Name="About" Text="À propos de..." Order="Primary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" />
<!--<ToolbarItem Name="Home" Text="Accueil" Order="Primary" Icon="ic_home.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/" /> <!--<ToolbarItem Name="Home" Text="Accueil" Order="Primary" Icon="ic_home.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/" />
<ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="ic_home.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/" />--> <ToolbarItem Name="Spells" Text="Sorts" Order="Primary" Icon="ic_home.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/" />-->
<!--<ToolbarItem Name="Blog" Text="Blog" Order="Primary" Icon="ic_blog.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Blog/" /> <!--<ToolbarItem Name="Blog" Text="Blog" Order="Primary" Icon="ic_blog.png" Command="{Binding OpenUrl}" CommandParameter="http://www.pathfinder-fr.org/Blog/" />

View file

@ -17,7 +17,8 @@ namespace AideDeJeu.Views
{ {
InitializeComponent (); InitializeComponent ();
BindingContext = viewModel = new ItemsViewModel(); BindingContext = viewModel = new ItemsViewModel(Navigation);
} }
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args) async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
@ -54,5 +55,7 @@ namespace AideDeJeu.Views
if (viewModel.Items.Count == 0) if (viewModel.Items.Count == 0)
viewModel.LoadItemsCommand.Execute(null); viewModel.LoadItemsCommand.Execute(null);
} }
} }
} }

View file

@ -18,6 +18,8 @@
<skia:SKCanvasView PaintSurface="PaintHeaderBar" HorizontalOptions="FillAndExpand" HeightRequest="8" /> <skia:SKCanvasView PaintSurface="PaintHeaderBar" HorizontalOptions="FillAndExpand" HeightRequest="8" />
<Label Text="{Binding Item.Name}" Style="{StaticResource Key=subsection}" /> <Label Text="{Binding Item.Name}" Style="{StaticResource Key=subsection}" />
<Label Text="{Binding Item.NameVO}" Style="{StaticResource Key=content}" />
<Label Text="{Binding Item.NamePHB}" Style="{StaticResource Key=content}" />
<!--<Label Text=" " />--> <!--<Label Text=" " />-->

View file

@ -5,7 +5,9 @@
Title="{Binding Title}"> Title="{Binding Title}">
<ScrollView> <ScrollView>
<StackLayout Orientation="Vertical" Padding="15"> <StackLayout Orientation="Vertical" Padding="15">
<Label Text="{Binding Item.Name}" Style="{StaticResource Key=subsubsection}" /> <Label Text="{Binding Item.Name}" Style="{StaticResource Key=subsection}" />
<Label Text="{Binding Item.NameVO}" Style="{StaticResource Key=content}" />
<Label Text="{Binding Item.NamePHB}" Style="{StaticResource Key=content}" />
<Label Text=" " /> <Label Text=" " />

View file

@ -11,6 +11,7 @@ namespace AideDeJeuLib.Monsters
public string Id { get; set; } public string Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string NameVO { get; set; } public string NameVO { get; set; }
public string NamePHB { get; set; }
public string Power { get; set; } public string Power { get; set; }
public string Type { get; set; } public string Type { get; set; }
public string Size { get; set; } public string Size { get; set; }
@ -48,7 +49,12 @@ namespace AideDeJeuLib.Monsters
var monster = new Monster(); var monster = new Monster();
var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]"); var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]");
monster.Name = divMonster?.SelectSingleNode("h1").InnerText; monster.Name = divMonster?.SelectSingleNode("h1").InnerText;
monster.NameVO = divMonster?.SelectSingleNode("div[contains(@class,'trad')]/a")?.InnerText;
var altNames = divMonster.SelectSingleNode("div[@class='trad']").InnerText;
var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
monster.NameVO = matchNames.Groups["vo"].Value;
monster.NamePHB = matchNames.Groups["alt"].Value;
var divSansSerif = divMonster?.SelectSingleNode("div[contains(@class,'sansSerif')]"); var divSansSerif = divMonster?.SelectSingleNode("div[contains(@class,'sansSerif')]");
var typeSizeAlignment = divSansSerif?.SelectSingleNode("h2/em")?.InnerText; var typeSizeAlignment = divSansSerif?.SelectSingleNode("h2/em")?.InnerText;
if (typeSizeAlignment != null) if (typeSizeAlignment != null)

View file

@ -11,7 +11,8 @@ namespace AideDeJeuLib.Spells
{ {
public string Id { get; set; } public string Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string NameUS { get; set; } public string NameVO { get; set; }
public string NamePHB { get; set; }
public string LevelType { get; set; } public string LevelType { get; set; }
public string Level { get; set; } public string Level { get; set; }
public string Type { get; set; } public string Type { get; set; }
@ -51,7 +52,10 @@ namespace AideDeJeuLib.Spells
{ {
var spell = new Spell(); var spell = new Spell();
spell.Name = nodeSpell.SelectSingleNode("h1").InnerText; spell.Name = nodeSpell.SelectSingleNode("h1").InnerText;
spell.NameUS = nodeSpell.SelectSingleNode("div[@class='trad']").InnerText; var altNames = nodeSpell.SelectSingleNode("div[@class='trad']").InnerText;
var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
spell.NameVO = matchNames.Groups["vo"].Value;
spell.NamePHB = matchNames.Groups["alt"].Value;
spell.LevelType = nodeSpell.SelectSingleNode("h2/em").InnerText; spell.LevelType = nodeSpell.SelectSingleNode("h2/em").InnerText;
spell.Level = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1]; spell.Level = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1];
spell.Type = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1]; spell.Type = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1];

View file

@ -109,7 +109,7 @@ namespace AideDeJeuLib.Spells
{ {
var newSpell = new Spell(); var newSpell = new Spell();
newSpell.Name = spell.SelectSingleNode("h1").InnerText; newSpell.Name = spell.SelectSingleNode("h1").InnerText;
newSpell.NameUS = spell.SelectSingleNode("div[@class='trad']").InnerText; newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText;
newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText; newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText;
newSpell.Level = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1]; newSpell.Level = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1];
newSpell.Type = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1]; newSpell.Type = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1];