Skip to content

Commit

Permalink
Add reset option, update copyright text
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarcederberg committed Jul 28, 2021
1 parent 4ef292f commit 58e5aa6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
8 changes: 7 additions & 1 deletion Class/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GetOptions{
public uint Amount{get; set;}
}

[Verb("shuffle", HelpText = "Shuffle the deck")]
[Verb("shuffle", HelpText = "Shuffle the deck.")]
public class ShuffleOptions{
[Value(0, MetaName = "type", MetaValue = "string", Required = false, Default = "riffle", HelpText = "What shuffle to perform.")]
public string Type{get; set;}
Expand All @@ -16,4 +16,10 @@ public class ShuffleOptions{
[Option('q',"quiet", HelpText = "Suppress stdout.")]
public bool Quiet{get; set;}
}

[Verb("reset", HelpText = "Reset deck to default.")]
public class ResetOptions{
[Option('q',"quiet", HelpText = "Suppress stdout.")]
public bool Quiet{get; set;}
}
}
33 changes: 23 additions & 10 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,34 @@ class Program{
static int Main(string[] args){
Directory.CreateDirectory(configPath);
TarotDeck deck = new TarotDeck();

if(File.Exists(filePath)){
deck.DeserializeDeck(filePath);
}else{
deck.DeserializeDeck(defaultFilePath);
File.WriteAllText(filePath, deck.SerializeDeck());
}

Type[] types = {typeof(ShuffleOptions), typeof(GetOptions)};
Type[] types = {typeof(ShuffleOptions), typeof(GetOptions), typeof(ResetOptions)};
return Parser.Default.ParseArguments(args, types)
.MapResult(
(GetOptions options) => {
options.Amount = Math.Max(1, options.Amount);
.MapResult(
(GetOptions options) => Get(options, deck),
(ShuffleOptions options) => Shuffle(options, deck),
(ResetOptions options) => Reset(options, deck),
errors => 1);
}

private static int Get(GetOptions options, TarotDeck deck){
options.Amount = Math.Max(1, options.Amount);
for (int i = 0; i < options.Amount; i++){
Console.WriteLine(deck.RequeueCard().ToString());
}
File.WriteAllText(filePath, deck.SerializeDeck());
return 0;
},
(ShuffleOptions options) => {
options.Amount = Math.Max(1, options.Amount);
}

private static int Shuffle(ShuffleOptions options, TarotDeck deck){
options.Amount = Math.Max(1, options.Amount);
switch(options.Type.ToLower()){
case "riffle":
for (int i = 0; i < options.Amount; i++){
Expand Down Expand Up @@ -63,8 +71,13 @@ static int Main(string[] args){
}
File.WriteAllText(filePath, deck.SerializeDeck());
return 0;
},
errors => 1);
}

private static int Reset(ResetOptions options, TarotDeck deck){
deck.DeserializeDeck(defaultFilePath);
if(!options.Quiet) Console.WriteLine("The deck has been reset to default.");
File.WriteAllText(filePath, deck.SerializeDeck());
return 0;
}
}
}
}
15 changes: 5 additions & 10 deletions tarot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Company>oscarcederberg</Company>
<Copyright>Copyright (C) 2021 Oscar Cederberg
This program comes with ABSOLUTELY NO WARRANTY; Check the GNU General Public
License Version 3 (GPLv3) for more details. This is free software, and you are
welcome to redistribute it under the GPLv3 terms and conditions.</Copyright>
<Version>0.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<None Update="Data\base_majorarcana.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\base_minorarcana.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>

0 comments on commit 58e5aa6

Please sign in to comment.