diff --git a/Classes/ISpread.cs b/Classes/ISpread.cs index 1623f3c..218113a 100644 --- a/Classes/ISpread.cs +++ b/Classes/ISpread.cs @@ -1,6 +1,6 @@ namespace tarot{ public interface ISpread where T : IDeck where U : ICard { - public void AddCards(T deck); + public void EnqueueCards(T deck); public string SerializeSpread(); diff --git a/Classes/TarotSpread.cs b/Classes/TarotSpread.cs index 37dc530..9209329 100644 --- a/Classes/TarotSpread.cs +++ b/Classes/TarotSpread.cs @@ -11,7 +11,7 @@ public TarotSpread(string[] positions){ this._spread_cards = new TarotCard[Length()]; } - public void AddCards(TarotDeck deck){ + public void EnqueueCards(TarotDeck deck){ for (int i = 0; i < Length(); i++){ this._spread_cards[i] = deck.RequeueCard(); } diff --git a/Options.cs b/Options.cs index 3d3f1ee..ffbccac 100644 --- a/Options.cs +++ b/Options.cs @@ -40,15 +40,15 @@ public class SpreadOptions{ public string Name{get; set;} } - [Verb("list", HelpText = "List all available cards or spreads.")] - public class ListOption{ - [Option('c',"card", SetName = "cards", MetaValue = "string", Required = true, HelpText = "List all, or a specific card.")] + [Verb("view", HelpText = "View all available cards or spreads.")] + public class ViewOptions{ + [Option('c',"card", SetName = "cards", MetaValue = "string", Required = true, HelpText = "List all, or view a specific card.")] public bool Card{get; set;} - [Option('s',"spread", SetName = "spread", MetaValue = "string", Required = true, HelpText = "List all, or a specific spread.")] + [Option('s',"spread", SetName = "spread", MetaValue = "string", Required = true, HelpText = "List all, or view a specific spread.")] public bool Spread{get; set;} - [Value(0, MetaName = "name", MetaValue = "string", Required = false, HelpText = "Name of card or spread to list. Leave empty for all.")] + [Value(0, MetaName = "name", MetaValue = "string", Required = false, HelpText = "Name of card or spread to view. Leave empty for all.")] public string Name{get; set;} } diff --git a/Program.cs b/Program.cs index 590a6c4..af69643 100644 --- a/Program.cs +++ b/Program.cs @@ -27,7 +27,7 @@ class Program{ static int Main(string[] args){ TarotDeck deck = new TarotDeck(); TarotSpreads spreads = new TarotSpreads(); - Type[] types = {typeof(ShuffleOptions), typeof(GetOptions), typeof(ResetOptions), typeof(SpreadOptions), typeof(ListOption), + Type[] types = {typeof(ShuffleOptions), typeof(GetOptions), typeof(ResetOptions), typeof(SpreadOptions), typeof(ViewOptions), typeof(MoveOptions), typeof(SwapOptions)}; HandleFiles(deck, spreads); @@ -37,7 +37,7 @@ static int Main(string[] args){ (ShuffleOptions options) => Shuffle(options, deck), (ResetOptions options) => Reset(options, deck, spreads), (SpreadOptions options) => Spread(options, deck, spreads), - (ListOption options) => List(options, deck, spreads), + (ViewOptions options) => View(options, deck, spreads), (MoveOptions options) => Move(options, deck), (SwapOptions options) => Swap(options, deck), errors => 1 @@ -162,10 +162,11 @@ private static int Reset(ResetOptions options, TarotDeck deck, TarotSpreads spre private static int Spread(SpreadOptions options, TarotDeck deck, TarotSpreads spreads){ List names = new List(spreads.Keys); - - if(names.Contains(options.Name)){ - TarotSpread spread = spreads[options.Name]; - spread.AddCards(deck); + string name = names.Find(n => n.ToLower() == options.Name.ToLower()); + + if(name is not null){ + TarotSpread spread = spreads[name]; + spread.EnqueueCards(deck); spread.PrintSpread(); SaveDeck(deck); return 0; @@ -175,75 +176,80 @@ private static int Spread(SpreadOptions options, TarotDeck deck, TarotSpreads sp } } - private static int List(ListOption options, TarotDeck deck, TarotSpreads spreads){ - if(options.Card){ - if(options.Name != default){ - TarotCard card = deck.Cards.Find((TarotCard c) => c.Name.ToLower() == options.Name.ToLower()); - - if(card is not null){ - Console.WriteLine($"{card.GetName()}:\n\t{card.GetKeywords()}"); - }else{ - Console.WriteLine("That card does not exist."); - return 1; - } - }else{ - foreach (TarotCard card in deck.Cards) - { - Console.WriteLine($"{card.GetName()}:\n\t{card.GetKeywords()}"); - } - } - }else if(options.Spread){ - List names = new List(spreads.Keys); - names.Sort(); - - if(options.Name != default){ - string name = names.Find((string n) => n.ToLower() == options.Name.ToLower()); - - if(name is not null){ - TarotSpread spread = spreads[name]; + private static int View(ViewOptions options, TarotDeck deck, TarotSpreads spreads){ + if(options.Card){ + if(options.Name != default){ + TarotCard card = deck.Cards.Find(c => c.Name.ToLower() == options.Name.ToLower()); - Console.WriteLine($"{name}:"); - for (int i = 0; i < spread.Length(); i++){ - Console.WriteLine($"\t{i+1}. {spread.Positions[i]}"); - } - }else{ - Console.WriteLine("That spread does not exist."); - return 1; - } - }else{ - foreach(string name in names){ + if(card is not null){ + Console.WriteLine($"{card.GetName()}:\n\t{card.GetKeywords()}"); + }else{ + Console.WriteLine("That card does not exist."); + return 1; + } + }else{ + List cards_in_order = Utilities.Deserialize>(defaultCardsFilePath); + try{ + cards_in_order.AddRange(Utilities.Deserialize>(userCardsFilePath)); + }catch (System.Exception){} + + for (int i = 0; i < cards_in_order.Count; i++){ + TarotCard card = cards_in_order[i]; + Console.WriteLine($"{card.GetName()}:\n\tKeywords: {card.GetKeywords()}"); + } + } + }else if(options.Spread){ + List names = new List(spreads.Keys); + names.Sort(); + + if(options.Name != default){ + string name = names.Find(n => n.ToLower() == options.Name.ToLower()); + + if(name is not null){ + TarotSpread spread = spreads[name]; + + Console.WriteLine($"{name}:"); + for (int i = 0; i < spread.Length(); i++){ + Console.WriteLine($"\t{i+1}. {spread.Positions[i]}"); + } + }else{ + Console.WriteLine("That spread does not exist."); + return 1; + } + }else{ + foreach(string name in names){ TarotSpread spread = spreads[name]; Console.WriteLine($"{name}:"); for (int i = 0; i < spread.Length(); i++){ Console.WriteLine($"\t{i+1}. {spread.Positions[i]}"); } - } - } - } - return 0; - } - - private static int Move(MoveOptions options, TarotDeck deck){ - if(options.OldIndex > deck.Cards.Count -1 || options.OldIndex < 0 || - options.NewIndex > deck.Cards.Count -1 || options.NewIndex < 0){ - Console.WriteLine($"Positional index is outside of the deck range [0,{deck.Cards.Count -1}]."); - return 1; - }else{ - deck.MoveCard(options.OldIndex, options.NewIndex); - return 0; - } - } - - private static int Swap(SwapOptions options, TarotDeck deck){ - if(options.FirstIndex > deck.Cards.Count -1 || options.FirstIndex < 0 || - options.SecondIndex > deck.Cards.Count -1 || options.SecondIndex < 0){ - Console.WriteLine($"Positional index is outside of the deck range [0,{deck.Cards.Count -1}]."); - return 1; - }else{ - deck.SwapCards(options.FirstIndex, options.SecondIndex); - return 0; - } - } + } + } + } + return 0; + } + + private static int Move(MoveOptions options, TarotDeck deck){ + if(options.OldIndex > deck.Cards.Count -1 || options.OldIndex < 0 || + options.NewIndex > deck.Cards.Count -1 || options.NewIndex < 0){ + Console.WriteLine($"Positional index is outside of the deck range [0,{deck.Cards.Count -1}]."); + return 1; + }else{ + deck.MoveCard(options.OldIndex, options.NewIndex); + return 0; + } + } + + private static int Swap(SwapOptions options, TarotDeck deck){ + if(options.FirstIndex > deck.Cards.Count -1 || options.FirstIndex < 0 || + options.SecondIndex > deck.Cards.Count -1 || options.SecondIndex < 0){ + Console.WriteLine($"Positional index is outside of the deck range [0,{deck.Cards.Count -1}]."); + return 1; + }else{ + deck.SwapCards(options.FirstIndex, options.SecondIndex); + return 0; + } + } } } \ No newline at end of file diff --git a/TODO.md b/TODO.md index d81f8b8..e864b8d 100644 --- a/TODO.md +++ b/TODO.md @@ -11,7 +11,6 @@ C# Tarot-reading application ### Todo -- [ ] List cards in order - [ ] Flags for retrieving in .json-format. - [ ] Add option for drawing reverse cards - [ ] ⚠️Switch uint arguments to int, handle out-of-range cases. @@ -19,15 +18,17 @@ C# Tarot-reading application - [ ] ⚠️Refactor input-handling. - [ ] ⚠️Add documentation - [ ] ⚠️Rework shuffling. -- [ ] 🐞Error-handling for parsing/saving files +- [ ] ⚠️Error-handling for parsing/saving files ### In Progress + ### Done ✓ +- [x] List cards in order - [x] Move listing spreads and viewing one single spread to a verb that also allows viewing a specific card or all cards - [x] Add tarot card meanings/keywords. - [x] Function to reset deck and/or spreads, either from original or from own chosen file. - [x] Current Spreads-file, similar to current deck. -- [x] Commands to swap, or insert cards at specific positions in deck, for posibility to do interactive shuffling. +- [x] Commands to swap, or insert cards at specific positions in deck, for posibility to do interactive shuffling.