Skip to content

Commit

Permalink
Fixes cost and level not working, hopefully
Browse files Browse the repository at this point in the history
Updates nightly steps
  • Loading branch information
ronelm2000 committed Oct 8, 2024
1 parent 24d36bd commit a3d22bb
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Install dependencies
Expand Down
35 changes: 35 additions & 0 deletions Montage.Weiss.Tools.GUI/Utilities/Parsers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Montage.Weiss.Tools.GUI.Utilities;
internal static class Parsers
{
/// <summary>
/// Implements Parse, but also handles typical exceptions from the System variant, except for FormatException.
/// </summary>
/// <param name="text">Text to format</param>
/// <param name="style">Style</param>
/// <param name="provider">Provider if provided</param>
/// <returns></returns>
internal static int? ParseInt(ReadOnlySpan<char> text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = null)
{
try
{
return int.Parse(text, style, provider);
}
catch (OverflowException e)
{
return int.MaxValue;
}
catch (FormatException e)
{
return null;
} catch (ArgumentNullException e)
{
return null;
}
}
}
20 changes: 20 additions & 0 deletions Montage.Weiss.Tools.GUI/Utilities/Strings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Montage.Weiss.Tools.GUI.Utilities;
internal static class Strings
{
internal static string? Or(params Func<string>[] values) // will be turned into Span/IEnumerable in .NET 9
{
foreach (var span in values)
{
var possibleResult = span();
if (!String.IsNullOrWhiteSpace(possibleResult))
return possibleResult;
}
return null;
}
}
14 changes: 10 additions & 4 deletions Montage.Weiss.Tools.GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
using Avalonia.Controls;
using System.Text.RegularExpressions;
using Avalonia.Threading;
using JasperFx.Core;
using Montage.Weiss.Tools.GUI.Utilities;

namespace Montage.Weiss.Tools.GUI.ViewModels;

Expand Down Expand Up @@ -283,15 +285,19 @@ Func<WeissSchwarzCard,bool> TranslateMatch(Match scryfallMatch)
else if (scryfallMatch.Groups[1].Value.Equals("l", StringComparison.CurrentCultureIgnoreCase) ||
scryfallMatch.Groups[1].Value.Equals("level", StringComparison.CurrentCultureIgnoreCase))
{
if (int.TryParse(scryfallMatch.Groups[2].Value, out var level))
return c => (c.Level ?? 0) == level;
var levelString = Strings.Or(() => scryfallMatch.Groups[2].Value, () => scryfallMatch.Groups[3].Value);
var level = Parsers.ParseInt(levelString.AsSpan(), style: System.Globalization.NumberStyles.Number);
if (level is not null)
return c => (c.Level ?? 0) == level!;
else
return c => true;
}
else if (scryfallMatch.Groups[1].Value.Equals("c", StringComparison.CurrentCultureIgnoreCase) ||
else if (scryfallMatch.Groups[1].Value.Equals("co", StringComparison.CurrentCultureIgnoreCase) ||
scryfallMatch.Groups[1].Value.Equals("cost", StringComparison.CurrentCultureIgnoreCase))
{
if (int.TryParse(scryfallMatch.Groups[2].Value, out var cost))
var costString = Strings.Or(() => scryfallMatch.Groups[2].Value, () => scryfallMatch.Groups[3].Value);
var cost = Parsers.ParseInt(costString.AsSpan(), style: System.Globalization.NumberStyles.Number);
if (cost is not null)
return c => (c.Cost ?? 0) == cost;
else
return c => true;
Expand Down
29 changes: 29 additions & 0 deletions Montage.Weiss.Tools.GUI/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,35 @@
</ScrollViewer>
</Grid>
</Border>

<!-- Inline Dialogs -->

<Border Grid.ColumnSpan="3"
Name="DialogToastBox"
Background="{Binding $parent[Window].Background}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
IsVisible="False"
>
<StackPanel>
<TextBlock Text="Parse Set" Margin="5,5,5,10" />
<TextBox Watermark="Set URL..." MinWidth="400"/>
<StackPanel Orientation="Horizontal">
<Button MinWidth="200"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
>
Cancel
</Button>
<Button MinWidth="200"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
>
Parse
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>

</DockPanel>
Expand Down

0 comments on commit a3d22bb

Please sign in to comment.