-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata properties for SaveGame (#4)
* Add helper properties for metadata in SaveGame * Bump version and remove preview package dependency
- Loading branch information
Showing
7 changed files
with
284 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace LibCK2.Game | ||
{ | ||
public readonly struct GameDate | ||
{ | ||
public int Year { get; } | ||
public int Month { get; } | ||
public int Day { get; } | ||
|
||
public GameDate(int year, int month, int day) => (Year, Month, Day) = (year, month, day); | ||
|
||
public override string ToString() => $"{Year}.{Month}.{Day}"; | ||
|
||
private static readonly Regex r_tDate = new Regex(@"(\d+)\.(\d+)\.(\d+)", RegexOptions.Compiled); | ||
public static GameDate Parse(string value) | ||
{ | ||
if (value == null) | ||
throw new ArgumentNullException(nameof(value)); | ||
|
||
var m = r_tDate.Match(value); | ||
if (!m.Success) | ||
throw new FormatException($"Value was not in the correct format"); | ||
|
||
return Parse(m); | ||
} | ||
internal static GameDate Parse(Match m) | ||
=> new GameDate(year: int.Parse(m.Groups[1].Value), month: int.Parse(m.Groups[2].Value), day: int.Parse(m.Groups[3].Value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace LibCK2.Parsing | ||
{ | ||
internal static class AsyncEnumerableExtensions | ||
{ | ||
public static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> asyncEnumerable) | ||
{ | ||
var ret = new List<T>(); | ||
await foreach(var val in asyncEnumerable) | ||
{ | ||
ret.Add(val); | ||
} | ||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.