Skip to content

Commit

Permalink
Add current spreads-file
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarcederberg committed Jul 30, 2021
1 parent edd38f0 commit e4020a2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 58 deletions.
6 changes: 5 additions & 1 deletion Classes/ISpread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ public interface ISpread<T, U> where T : IDeck<U> where U : ICard {

public string SerializeSpread();

public string SerializeCards();

public void PrintSpread();

public int GetLength();
public void PrintPositions();

public int Length();
}
}
30 changes: 20 additions & 10 deletions Classes/TarotSpread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,43 @@

namespace tarot{
public class TarotSpread : ISpread<TarotDeck, TarotCard>{
public string[] Positions;

private TarotCard[] _spread_cards;
private string[] _spread_positions;

public TarotSpread(string[] positions, TarotDeck deck){
this._spread_positions = positions;
this._spread_cards = new TarotCard[GetLength()];
AddCards(deck);
public TarotSpread(string[] positions){
this.Positions = positions;
this._spread_cards = new TarotCard[Length()];
}

public void AddCards(TarotDeck deck){
for (int i = 0; i < GetLength(); i++){
for (int i = 0; i < Length(); i++){
this._spread_cards[i] = deck.RequeueCard();
}
}

public string SerializeSpread(){
return Utilities.Serialize<TarotSpread>(this);
}

public string SerializeCards(){
return Utilities.Serialize<TarotCard[]>(this._spread_cards);
}

public void PrintSpread(){
for (int i = 0; i < GetLength(); i++){
Console.WriteLine($"{i+1}. {_spread_positions[i]}:\n\t{_spread_cards[i]}");
for (int i = 0; i < Length(); i++){
Console.WriteLine($"{i+1}. {Positions[i]}:\n\t{_spread_cards[i]}");
}
}

public void PrintPositions(){
for (int i = 0; i < Length(); i++){
Console.WriteLine($"{i+1}. {Positions[i]}");
}
}

public int GetLength(){
return _spread_positions.Length;
public int Length(){
return Positions.Length;
}
}
}
20 changes: 13 additions & 7 deletions Data/default_spreads.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
{
"Linear 3 Card Spread": [
"Linear 3 Card Spread": {
"Positions": [
"Past, you, situation, idea",
"Present, your path/relationship, action, process",
"Future, your potential/partner, outcome, aspiration"
],
"Making Decisions": [
]
},
"Making Decisions": {
"Positions": [
"Your motivation",
"Ideal outcome",
"Your values",
"Option 1, likely outcome",
"Option 2, likely outcome"
],
"Hierarchy of Needs": [
]
},
"Hierarchy of Needs": {
"Positions": [
"Physiological",
"Safety",
"Love and belonging",
"Esteem",
"Self-actualization"
]
}
]
}
}
62 changes: 34 additions & 28 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Program{
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"tarot/"
);
static string currentDeckFilePath = Path.Combine(localApplicationDataPath,@"current_deck.json");
static string currentSpreadsFilePath = Path.Combine(localApplicationDataPath,@"current_spreads.json");

static string configurationDataPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".config/tarot/"
Expand All @@ -23,21 +24,21 @@ class Program{

static int Main(string[] args){
TarotDeck deck = new TarotDeck();
Dictionary<string, string[]> spreads_uninitialized = new Dictionary<string, string[]>();
Dictionary<string, TarotSpread> spreads = new Dictionary<string, TarotSpread>();
Type[] types = {typeof(ShuffleOptions), typeof(GetOptions), typeof(ResetOptions), typeof(SpreadOptions)};
HandleFiles(deck, spreads_uninitialized);

HandleFiles(deck, spreads);

return Parser.Default.ParseArguments(args, types).MapResult(
(GetOptions options) => Get(options, deck),
(ShuffleOptions options) => Shuffle(options, deck),
(ResetOptions options) => Reset(options, deck),
(SpreadOptions options) => Spread(options, spreads_uninitialized, deck),
(SpreadOptions options) => Spread(options, spreads, deck),
errors => 1
);
}

private static void HandleFiles(TarotDeck deck, Dictionary<string, string[]> spreads){
private static void HandleFiles(TarotDeck deck, Dictionary<string, TarotSpread> spreads){
Directory.CreateDirectory(localApplicationDataPath);
Directory.CreateDirectory(configurationDataPath);

Expand All @@ -47,7 +48,13 @@ private static void HandleFiles(TarotDeck deck, Dictionary<string, string[]> spr
deck.DeserializeDeck(defaultCardsFilePath);
File.WriteAllText(currentDeckFilePath, deck.SerializeDeck());
}
spreads = Utilities.Deserialize<Dictionary<string, string[]>>(defaultSpreadsFilePath);

if(File.Exists(currentSpreadsFilePath)){
spreads.AddRange(Utilities.Deserialize<Dictionary<string, TarotSpread>>(currentSpreadsFilePath));
}else{
spreads.AddRange(spreads = Utilities.Deserialize<Dictionary<string, TarotSpread>>(defaultSpreadsFilePath));
File.WriteAllText(currentSpreadsFilePath, Utilities.Serialize(spreads));
}

if(File.Exists(userCardsFilePath)){
try{
Expand All @@ -59,15 +66,18 @@ private static void HandleFiles(TarotDeck deck, Dictionary<string, string[]> spr

if(File.Exists(userSpreadsFilePath)){
try{
spreads.AddRange(Utilities.Deserialize<Dictionary<string, string[]>>(userSpreadsFilePath));
spreads.AddRange(Utilities.Deserialize<Dictionary<string, TarotSpread>>(userSpreadsFilePath));
}catch (System.Exception){};
}else{
File.WriteAllText(userSpreadsFilePath, File.ReadAllText(templateSpreadsFilePath));
}
}

static void SaveDeck(TarotDeck deck){
File.WriteAllText(currentDeckFilePath, deck.SerializeDeck());
}

private static int Get(GetOptions options, TarotDeck deck){
Console.WriteLine(options.Amount);
options.Amount = Math.Max(1, options.Amount);
for (int i = 0; i < options.Amount; i++){
Console.WriteLine(deck.RequeueCard().ToString());
Expand Down Expand Up @@ -118,29 +128,29 @@ private static int Reset(ResetOptions options, TarotDeck deck){
return 0;
}

private static int Spread(SpreadOptions options, Dictionary<string, string[]> spreads_unitit, TarotDeck deck){
List<string> spreadNames = new List<string>(spreads_unitit.Keys);
private static int Spread(SpreadOptions options, Dictionary<string, TarotSpread> spreads, TarotDeck deck){
List<string> names = new List<string>(spreads.Keys);

if(options.ListAll){
spreadNames.Sort();
for (int i = 0; i < spreadNames.Count; i++){
string name = spreadNames[i];
if(options.ListAll){
names.Sort();
for (int i = 0; i < names.Count; i++){
string name = names[i];
Console.WriteLine($"{i+1}. {name}:");
string[] positions = spreads_unitit[name];
for (int j = 0; j < positions.Length; j++){
Console.WriteLine($"\t{j+1}) {positions[j]}");
TarotSpread spread = spreads[name];
for (int j = 0; j < spread.Length(); j++){
Console.WriteLine($"\t{j+1}) {spread.Positions[j]}");
}
}
}else if(options.Name != default){
if(spreadNames.Contains(options.Name)){
if(names.Contains(options.Name)){
TarotSpread spread = spreads[options.Name];
if(options.List){
Console.WriteLine($"{options.Name}:");
string[] positions = spreads_unitit[options.Name];
for (int i = 0; i < positions.Length; i++){
Console.WriteLine($"\t{i+1}) {positions[i]}");
Console.WriteLine($"{options.Name}:");
for (int j = 0; j < spread.Length(); j++){
Console.WriteLine($"\t{j+1}) {spread.Positions[j]}");
}
}else{
TarotSpread spread = new TarotSpread(spreads_unitit[options.Name], deck);
spread.AddCards(deck);
spread.PrintSpread();
}
}else{
Expand All @@ -152,10 +162,6 @@ private static int Spread(SpreadOptions options, Dictionary<string, string[]> sp
}
SaveDeck(deck);
return 0;
}

static void SaveDeck(TarotDeck deck){
File.WriteAllText(currentDeckFilePath, deck.SerializeDeck());
}
}
}
}
23 changes: 12 additions & 11 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ C# Tarot-reading application

### Investigate

- [ ] Possibility to create an API-like system? Library?
- [ ] Newtonsoft.json vs. built-in .json- handler?
- [ ] Possibility to create an API-like system? Library?
- [ ] Newtonsoft.json vs. built-in .json- handler?

### Todo

- [ ] Function to reset deck, either from original or from own chosen file.
- [ ] Flags for retrieving in .json-format.
- [ ] Current Spreads-file, similar to current deck. Reset spread, either from original or from own chosen file.
- [ ] Add tarot card meanings/keywords.
- [ ] Create a Minor Arcana creator (If type is minor arcana in .json, create an entire range of that suit (X of "Name")).
- [ ] Rework shuffling.
- [ ] Commands to swap, or insert cards at specific positions in deck, for posibility to do interactive shuffling..
- [ ] Refactor input-handling.
- [ ] Customize help.
- [ ] Function to reset deck and/or spreads, either from original or from own chosen file.
- [ ] Flags for retrieving in .json-format.
- [ ] Add tarot card meanings/keywords.
- [ ] Customize help.
- [ ] Create a Minor Arcana creator (If type is minor arcana in .json, create an entire range of that suit (X of "Name")).
- [ ] Commands to swap, or insert cards at specific positions in deck, for posibility to do interactive shuffling..
- [ ] ⚠️Refactor input-handling.
- [ ] ⚠️Rework shuffling.
- [ ] 🐞Error-handling for parsing/saving files

### In Progress


### Done ✓

- [x] Current Spreads-file, similar to current deck.

2 changes: 1 addition & 1 deletion Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void AddRange<T,U>(this Dictionary<T,U> target, Dictionary<T,U> so
if(target is null) throw new ArgumentNullException(nameof(target));
if(source is null) throw new ArgumentNullException(nameof(source));
foreach(T key in source.Keys){
U value = target[key];
U value = source[key];
if(target.ContainsKey(key)){
target[key] = value;
}else{
Expand Down

0 comments on commit e4020a2

Please sign in to comment.