Skip to content

Commit

Permalink
added offline variant support
Browse files Browse the repository at this point in the history
  • Loading branch information
GHXX committed Jun 27, 2021
1 parent 2399822 commit ff3cd07
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
35 changes: 35 additions & 0 deletions DataInterfaceConsole/Actions/LoadPredefinedOfflineVariant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using FiveDChessDataInterface.Variants;
using System;

namespace DataInterfaceConsole.Actions
{
class LoadPredefinedOfflineVariant : BaseAction
{
public override string Name => "Load Predefined Variant [OFFLINE]";

protected override void Run()
{
WaitForIngame();
var variants = GithubVariantGetter.GetAllVariants(true, true);

WriteLineIndented("Select a variant from the following:");
for (int i = 0; i < variants.Length; i++)
{
WriteLineIndented($"{(i + 1).ToString().PadLeft((int)Math.Ceiling(Math.Log10(variants.Length)))}. {variants[i].Name} by {variants[i].Author}");
}

if (int.TryParse(Util.ConsoleReadLineWhile(() => this.di.IsValid()), out int input) && input > 0 && input <= variants.Length)
{
var chosenVariant = variants[input - 1];
WriteLineIndented($"Loading variant '{chosenVariant.Name}'...");
var gb = chosenVariant.GetGameBuilder();
this.di.SetChessBoardArrayFromBuilder(gb);
WriteLineIndented($"Variant loaded and written to memory.");
}
else
{
WriteLineIndented("Invalid input. Not loading any variant.");
}
}
}
}
5 changes: 4 additions & 1 deletion DataInterfaceConsole/Actions/LoadPredefinedVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ namespace DataInterfaceConsole.Actions
{
class LoadPredefinedVariant : BaseAction
{
public override string Name => "Load Predefined Variant";
public override string Name => "Load Predefined Variant [ONLINE]";

protected override void Run()
{
WaitForIngame();

if (!GithubVariantGetter.IsCached)
WriteLineIndented("Getting variants from github...");
var variants = GithubVariantGetter.GetAllVariants();

WriteLineIndented("Select a variant from the following:");
Expand Down

0 comments on commit ff3cd07

Please sign in to comment.