From 37b80488df5efe78918bd999a679c85d8c98125a Mon Sep 17 00:00:00 2001 From: Knose Date: Mon, 26 Jul 2021 22:22:29 +0200 Subject: [PATCH] Change Card structure. Rename MenuCLI classes. --- Class/CardMajorArcana.cs | 14 -- Class/CardMinorArcana.cs | 16 -- Class/Deck.cs | 4 +- .../{MenuEntryFunc.cs => FuncEntry.cs} | 4 +- .../{AbstractMenuEntry.cs => MenuEntry.cs} | 4 +- Class/MenuCLI/{ListMenu.cs => MenuList.cs} | 4 +- Class/Options.cs | 6 +- Class/TarotCard.cs | 12 + Class/Utilities.cs | 26 +- Data/base_majorarcana.json | 90 ------- Data/base_minorarcana.json | 227 ------------------ Data/default_cards.json | 84 +++++++ Program.cs | 3 +- 13 files changed, 110 insertions(+), 384 deletions(-) delete mode 100644 Class/CardMajorArcana.cs delete mode 100644 Class/CardMinorArcana.cs rename Class/MenuCLI/{MenuEntryFunc.cs => FuncEntry.cs} (66%) rename Class/MenuCLI/{AbstractMenuEntry.cs => MenuEntry.cs} (81%) rename Class/MenuCLI/{ListMenu.cs => MenuList.cs} (92%) create mode 100644 Class/TarotCard.cs delete mode 100644 Data/base_majorarcana.json delete mode 100644 Data/base_minorarcana.json create mode 100644 Data/default_cards.json diff --git a/Class/CardMajorArcana.cs b/Class/CardMajorArcana.cs deleted file mode 100644 index 0a97fa6..0000000 --- a/Class/CardMajorArcana.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace tarot{ - public class CardMajorArcana : ICard{ - public readonly int Value; - private readonly string _name; - public CardMajorArcana(int value, string name){ - this.Value = value % 22; - this._name = Utilities.ToRoman(this.Value) + " - " + name; - } - - public override string ToString(){ - return this._name; - } - } -} \ No newline at end of file diff --git a/Class/CardMinorArcana.cs b/Class/CardMinorArcana.cs deleted file mode 100644 index 3fcb29a..0000000 --- a/Class/CardMinorArcana.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace tarot{ - public class CardMinorArcana : ICard{ - public readonly int Value; - public readonly string Suit; - private readonly string _name; - public CardMinorArcana(int value, string suit){ - this.Value = (value % 14) + 1; - this.Suit = suit; - this._name = Utilities.ToMinorArcanaValueNotation(this.Value) + " of " + this.Suit; - } - - public override string ToString(){ - return this._name; - } - } -} \ No newline at end of file diff --git a/Class/Deck.cs b/Class/Deck.cs index 5f9b2cf..cf95ab3 100644 --- a/Class/Deck.cs +++ b/Class/Deck.cs @@ -15,8 +15,8 @@ public Deck(){ this._deck = new List(); } - public void AddToDeck(IEnumerable collection){ - this._deck.AddRange(collection); + public void AddToDeck(string filePath){ + _deck.AddRange(Utilities.Deserialize>(filePath)); } public ICard RequeueCard() { diff --git a/Class/MenuCLI/MenuEntryFunc.cs b/Class/MenuCLI/FuncEntry.cs similarity index 66% rename from Class/MenuCLI/MenuEntryFunc.cs rename to Class/MenuCLI/FuncEntry.cs index 6ff5217..410859c 100644 --- a/Class/MenuCLI/MenuEntryFunc.cs +++ b/Class/MenuCLI/FuncEntry.cs @@ -2,10 +2,10 @@ using Subscription; namespace MenuCLI{ - public class MenuEntryFunc : AbstractMenuEntry{ + public class FuncEntry : MenuEntry{ private Func _func; - public MenuEntryFunc(string text, Func func, ISubscriber subscriber = null) : base(text, subscriber){ + public FuncEntry(string text, Func func, ISubscriber subscriber = null) : base(text, subscriber){ this._func = func; } diff --git a/Class/MenuCLI/AbstractMenuEntry.cs b/Class/MenuCLI/MenuEntry.cs similarity index 81% rename from Class/MenuCLI/AbstractMenuEntry.cs rename to Class/MenuCLI/MenuEntry.cs index a131baf..6b0a9db 100644 --- a/Class/MenuCLI/AbstractMenuEntry.cs +++ b/Class/MenuCLI/MenuEntry.cs @@ -2,11 +2,11 @@ using Subscription; namespace MenuCLI{ - public abstract class AbstractMenuEntry : IMenuEntry, ISubscribable{ + public abstract class MenuEntry : IMenuEntry, ISubscribable{ protected string _text; protected readonly List> _subscribers; - protected AbstractMenuEntry(string text, ISubscriber subscriber = null){ + protected MenuEntry(string text, ISubscriber subscriber = null){ this._text = text; this._subscribers = new List>(); if (subscriber is not null) _subscribers.Add(subscriber); diff --git a/Class/MenuCLI/ListMenu.cs b/Class/MenuCLI/MenuList.cs similarity index 92% rename from Class/MenuCLI/ListMenu.cs rename to Class/MenuCLI/MenuList.cs index d8dc4cd..322adc1 100644 --- a/Class/MenuCLI/ListMenu.cs +++ b/Class/MenuCLI/MenuList.cs @@ -2,12 +2,12 @@ using tarot; namespace MenuCLI{ - public class ListMenu : IMenu{ + public class MenuList : IMenu{ private IMenuEntry[] _entries; private string _cursor; private int _selection = 0; - public ListMenu(IMenuEntry[] entries, string cursor){ + public MenuList(IMenuEntry[] entries, string cursor){ this._entries = entries; this._cursor = cursor; } diff --git a/Class/Options.cs b/Class/Options.cs index 296e425..399251c 100644 --- a/Class/Options.cs +++ b/Class/Options.cs @@ -3,15 +3,15 @@ namespace tarot{ [Verb("get", HelpText = "Retrieve cards from the deck.")] public class GetOptions{ - [Value(0, MetaName = "amount", MetaValue = "int", Default = 1, HelpText = "Amount of cards to retrieve.")] + [Value(0, MetaName = "amount", MetaValue = "int", Required = false, Default = 1, HelpText = "Amount of cards to retrieve.")] public uint Amount{get; set;} } [Verb("shuffle", HelpText = "Shuffle the deck")] public class ShuffleOptions{ - [Value(0, MetaName = "type", MetaValue = "string", Default = "riffle", HelpText = "What shuffle to perform.")] + [Value(0, MetaName = "type", MetaValue = "string", Required = false, Default = "riffle", HelpText = "What shuffle to perform.")] public string Type{get; set;} - [Value(1, MetaName = "amount", MetaValue = "int", Default = 1, HelpText = "Number of shuffles to perform.")] + [Value(1, MetaName = "amount", MetaValue = "int", Required = false, Default = 1, HelpText = "Number of shuffles to perform.")] public int Amount{get; set;} [Option('q',"quiet", HelpText = "Suppress stdout.")] public bool Quiet{get; set;} diff --git a/Class/TarotCard.cs b/Class/TarotCard.cs new file mode 100644 index 0000000..07937bc --- /dev/null +++ b/Class/TarotCard.cs @@ -0,0 +1,12 @@ +namespace tarot{ + public class TarotCard : ICard{ + private readonly string _name; + public TarotCard(int id, string name){ + this._name = name; + } + + public override string ToString(){ + return this._name; + } + } +} \ No newline at end of file diff --git a/Class/Utilities.cs b/Class/Utilities.cs index 87b320d..f2e452f 100644 --- a/Class/Utilities.cs +++ b/Class/Utilities.cs @@ -12,30 +12,8 @@ public static class Utilities{ (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I") }; - public static List DeserializeMajorArcana(string file){ - return JsonConvert.DeserializeObject>(File.ReadAllText(file)); - } - - public static List DeserializeMinorArcana(string file){ - return JsonConvert.DeserializeObject>(File.ReadAllText(file)); - } - - public static string ToMinorArcanaValueNotation(int number){ - number = Math.Max(Math.Min(number, 14), 1); - switch (number){ - case 1: - return "Ace"; - case 11: - return "Page"; - case 12: - return "Knight"; - case 13: - return "Queen"; - case 14: - return "King"; - default: - return ToRoman(number); - } + public static T Deserialize(string filePath){ + return JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } public static string ToRoman(int number){ diff --git a/Data/base_majorarcana.json b/Data/base_majorarcana.json deleted file mode 100644 index 276784d..0000000 --- a/Data/base_majorarcana.json +++ /dev/null @@ -1,90 +0,0 @@ -[ - { - "Value": 0, - "Name": "The Fool" - }, - { - "Value": 1, - "Name": "The Magician" - }, - { - "Value": 2, - "Name": "The High Priestess" - }, - { - "Value": 3, - "Name": "The Empress" - }, - { - "Value": 4, - "Name": "The Emperor" - }, - { - "Value": 5, - "Name": "The Hierophant" - }, - { - "Value": 6, - "Name": "The Lovers" - }, - { - "Value": 7, - "Name": "The Chariot" - }, - { - "Value": 8, - "Name": "Strength" - }, - { - "Value": 9, - "Name": "The Hermit" - }, - { - "Value": 10, - "Name": "Wheel of Fortune" - }, - { - "Value": 11, - "Name": "Justice" - }, - { - "Value": 12, - "Name": "The Hanged Man" - }, - { - "Value": 13, - "Name": "Death" - }, - { - "Value": 14, - "Name": "Temperance" - }, - { - "Value": 15, - "Name": "The Devil" - }, - { - "Value": 16, - "Name": "The Tower" - }, - { - "Value": 17, - "Name": "The Star" - }, - { - "Value": 18, - "Name": "The Moon" - }, - { - "Value": 19, - "Name": "The Sun" - }, - { - "Value": 20, - "Name": "Judgement" - }, - { - "Value": 21, - "Name": "The World" - } -] \ No newline at end of file diff --git a/Data/base_minorarcana.json b/Data/base_minorarcana.json deleted file mode 100644 index c092e5f..0000000 --- a/Data/base_minorarcana.json +++ /dev/null @@ -1,227 +0,0 @@ - -[ - { - "Value": 1, - "Suit": "Staffs" - }, - { - "Value": 2, - "Suit": "Staffs" - }, - { - "Value": 3, - "Suit": "Staffs" - }, - { - "Value": 4, - "Suit": "Staffs" - }, - { - "Value": 5, - "Suit": "Staffs" - }, - { - "Value": 6, - "Suit": "Staffs" - }, - { - "Value": 7, - "Suit": "Staffs" - }, - { - "Value": 8, - "Suit": "Staffs" - }, - { - "Value": 9, - "Suit": "Staffs" - }, - { - "Value": 10, - "Suit": "Staffs" - }, - { - "Value": 11, - "Suit": "Staffs" - }, - { - "Value": 12, - "Suit": "Staffs" - }, - { - "Value": 13, - "Suit": "Staffs" - }, - { - "Value": 14, - "Suit": "Staffs" - }, - { - "Value": 1, - "Suit": "Cups" - }, - { - "Value": 2, - "Suit": "Cups" - }, - { - "Value": 3, - "Suit": "Cups" - }, - { - "Value": 4, - "Suit": "Cups" - }, - { - "Value": 5, - "Suit": "Cups" - }, - { - "Value": 6, - "Suit": "Cups" - }, - { - "Value": 7, - "Suit": "Cups" - }, - { - "Value": 8, - "Suit": "Cups" - }, - { - "Value": 9, - "Suit": "Cups" - }, - { - "Value": 10, - "Suit": "Cups" - }, - { - "Value": 11, - "Suit": "Cups" - }, - { - "Value": 12, - "Suit": "Cups" - }, - { - "Value": 13, - "Suit": "Cups" - }, - { - "Value": 14, - "Suit": "Cups" - }, - { - "Value": 1, - "Suit": "Swords" - }, - { - "Value": 2, - "Suit": "Swords" - }, - { - "Value": 3, - "Suit": "Swords" - }, - { - "Value": 4, - "Suit": "Swords" - }, - { - "Value": 5, - "Suit": "Swords" - }, - { - "Value": 6, - "Suit": "Swords" - }, - { - "Value": 7, - "Suit": "Swords" - }, - { - "Value": 8, - "Suit": "Swords" - }, - { - "Value": 9, - "Suit": "Swords" - }, - { - "Value": 10, - "Suit": "Swords" - }, - { - "Value": 11, - "Suit": "Swords" - }, - { - "Value": 12, - "Suit": "Swords" - }, - { - "Value": 13, - "Suit": "Swords" - }, - { - "Value": 14, - "Suit": "Swords" - }, - { - "Value": 1, - "Suit": "Pentacles" - }, - { - "Value": 2, - "Suit": "Pentacles" - }, - { - "Value": 3, - "Suit": "Pentacles" - }, - { - "Value": 4, - "Suit": "Pentacles" - }, - { - "Value": 5, - "Suit": "Pentacles" - }, - { - "Value": 6, - "Suit": "Pentacles" - }, - { - "Value": 7, - "Suit": "Pentacles" - }, - { - "Value": 8, - "Suit": "Pentacles" - }, - { - "Value": 9, - "Suit": "Pentacles" - }, - { - "Value": 10, - "Suit": "Pentacles" - }, - { - "Value": 11, - "Suit": "Pentacles" - }, - { - "Value": 12, - "Suit": "Pentacles" - }, - { - "Value": 13, - "Suit": "Pentacles" - }, - { - "Value": 14, - "Suit": "Pentacles" - } -] \ No newline at end of file diff --git a/Data/default_cards.json b/Data/default_cards.json new file mode 100644 index 0000000..128f779 --- /dev/null +++ b/Data/default_cards.json @@ -0,0 +1,84 @@ +[ + {"Name": "0 The Fool"}, + {"Name": "I The Magician"}, + {"Name": "II The High Priestess"}, + {"Name": "III The Empress"}, + {"Name": "IV The Emperor"}, + {"Name": "V The Hierophant"}, + {"Name": "VI The Lovers"}, + {"Name": "VII The Chariot"}, + {"Name": "VIII Strength"}, + {"Name": "IX The Hermit"}, + {"Name": "X Wheel of Fortune"}, + {"Name": "XI Justice"}, + {"Name": "XII The Hanged Man"}, + {"Name": "XIII Death"}, + {"Name": "XIV Temperance"}, + {"Name": "XV The Devil"}, + {"Name": "XVI The Tower"}, + {"Name": "XVII The Star"}, + {"Name": "XVIII The Moon"}, + {"Name": "XIX The Sun"}, + {"Name": "XX Judgement"}, + {"Name": "XXI The World"}, + + {"Name": "Ace of Staffs"}, + {"Name": "Two of Staffs"}, + {"Name": "Three of Staffs"}, + {"Name": "Four of Staffs"}, + {"Name": "Five of Staffs"}, + {"Name": "Six of Staffs"}, + {"Name": "Seven of Staffs"}, + {"Name": "Eight of Staffs"}, + {"Name": "Nine of Staffs"}, + {"Name": "Ten of Staffs"}, + {"Name": "Page of Staffs"}, + {"Name": "Knight of Staffs"}, + {"Name": "Queen of Staffs"}, + {"Name": "King of Staffs"}, + + {"Name": "Ace of Cups"}, + {"Name": "Two of Cups"}, + {"Name": "Three of Cups"}, + {"Name": "Four of Cups"}, + {"Name": "Five of Cups"}, + {"Name": "Six of Cups"}, + {"Name": "Seven of Cups"}, + {"Name": "Eight of Cups"}, + {"Name": "Nine of Cups"}, + {"Name": "Ten of Cups"}, + {"Name": "Page of Cups"}, + {"Name": "Knight of Cups"}, + {"Name": "Queen of Cups"}, + {"Name": "King of Cups"}, + + {"Name": "Ace of Swords"}, + {"Name": "Two of Swords"}, + {"Name": "Three of Swords"}, + {"Name": "Four of Swords"}, + {"Name": "Five of Swords"}, + {"Name": "Six of Swords"}, + {"Name": "Seven of Swords"}, + {"Name": "Eight of Swords"}, + {"Name": "Nine of Swords"}, + {"Name": "Ten of Swords"}, + {"Name": "Page of Swords"}, + {"Name": "Knight of Swords"}, + {"Name": "Queen of Swords"}, + {"Name": "King of Swords"}, + + {"Name": "Ace of Pentacles"}, + {"Name": "Two of Pentacles"}, + {"Name": "Three of Pentacles"}, + {"Name": "Four of Pentacles"}, + {"Name": "Five of Pentacles"}, + {"Name": "Six of Pentacles"}, + {"Name": "Seven of Pentacles"}, + {"Name": "Eight of Pentacles"}, + {"Name": "Nine of Pentacles"}, + {"Name": "Ten of Pentacles"}, + {"Name": "Page of Pentacles"}, + {"Name": "Knight of Pentacles"}, + {"Name": "Queen of Pentacles"}, + {"Name": "King of Pentacles"} +] \ No newline at end of file diff --git a/Program.cs b/Program.cs index a1bf27d..88b732e 100644 --- a/Program.cs +++ b/Program.cs @@ -12,8 +12,7 @@ static int Main(string[] args){ Type[] types = {typeof(ShuffleOptions), typeof(GetOptions)}; Deck deck = new Deck(); - deck.AddToDeck(Utilities.DeserializeMajorArcana(@"Data/base_majorarcana.json")); - deck.AddToDeck(Utilities.DeserializeMinorArcana(@"Data/base_minorarcana.json")); + deck.AddToDeck(@"Data/default_cards.json"); return Parser.Default.ParseArguments(args, types) .MapResult(