Skip to content

Commit

Permalink
feat: georgian added
Browse files Browse the repository at this point in the history
chore: memory consumption reduced
  • Loading branch information
eymenefealtun committed Sep 7, 2023
1 parent b855bd7 commit 4706f95
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 22 deletions.
1 change: 1 addition & 0 deletions TarotType.Main/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ComboBoxItem Content="Azerbaijani" />
<ComboBoxItem Content="English" />
<ComboBoxItem Content="French" />
<ComboBoxItem Content="Georgian" />
<ComboBoxItem Content="Greek" />
<ComboBoxItem Content="Kurdish" />
<ComboBoxItem Content="Persian" />
Expand Down
49 changes: 36 additions & 13 deletions TarotType.Main/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using TarotType.Main.Properties;
using TarotType.Main.Settings;
using TarotType.Main.Utilities;
using TarotType.Main.Utilities.Words.EnglishFolder;
using TarotType.Main.View;
using System.Resources;

namespace TarotType.Main
{
Expand Down Expand Up @@ -54,12 +52,13 @@ public int Second
bool _canComboBoxChangedFired = false;
bool _canSettignsChange = false;
public bool IsRefreshing = false;
public static bool _anotherArray = true;


public static string[] _sourceWords;
public static string[] _secondSourceWords;
public static string[] _resultWordArray;
public static Random _random;
public static ResourceManager _resources;

string _lightThemeCode = "#eeeee4";
string _darkThemeCode = "#1e1e1e";
Expand All @@ -69,12 +68,17 @@ public MainWindow()
InitializeComponent();

_random = new Random();
_resources = new ResourceManager(typeof(Resources));

_words1 = new List<Label>();
_words2 = new List<Label>();



WordManager wordManager = new WordManager(_numberOfWordsInEachCall);
SourceManager sourceManager = new SourceManager();



_dispatcherTimer = new DispatcherTimer();
_dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
_dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
Expand All @@ -87,10 +91,13 @@ public MainWindow()

string initialLanguageName = nameof(English);

_anotherArray = true;
Preferences.LanguageName = initialLanguageName;
cBoxLanguages.SelectedValue = initialLanguageName;

_sourceWords = SourceManager.GetLanguageArray(SourceManager.CurrentLanguage);
//_sourceWords = SourceManager.GetLanguageArray(SourceManager.CurrentLanguage);
//SetCurrentLanguageArray();

_resultWordArray = new string[_numberOfWordsInEachCall];

if (SourceManager.CurrentLanguage.FlowDirection() == SourceManager.flowDirections.right)
Expand Down Expand Up @@ -220,7 +227,7 @@ private void CurrentTextRight(Label lbl)
{
lbl.Background = Brushes.LightGray;
_numberOfTrueKeyStroke++;
}
}

private void GetAnotherStack(List<Label> words2)
{
Expand Down Expand Up @@ -273,13 +280,14 @@ private void RefreshStack(StackPanel panel, List<Label> labels)
panel.Children.Clear();
labels.Clear();

_resultWordArray = WordManager.GetRandomWord(_numberOfWordsInEachCall);
_resultWordArray = WordManager.GetRandomWord();

int currentLength = 0;



for (int i = 0; i < _resultWordArray.Length; i++)
{

Label lbl = new Label();
lbl.Background = i == 0 && labels == _words1 ? Brushes.LightGray : Brushes.Transparent; //First word set to Light Gray
lbl.Content = _resultWordArray[i];
Expand All @@ -298,9 +306,8 @@ private void RefreshStack(StackPanel panel, List<Label> labels)

labels.Add(lbl);
panel.Children.Insert(i, lbl);

panel.FlowDirection = SourceManager.CurrentLanguage.FlowDirection() == SourceManager.flowDirections.right ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
}
panel.FlowDirection = SourceManager.CurrentLanguage.FlowDirection() == SourceManager.flowDirections.right ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
}

private void btnTheme_Click(object sender, RoutedEventArgs e)
Expand All @@ -309,15 +316,31 @@ private void btnTheme_Click(object sender, RoutedEventArgs e)
SettingsChanged(Preferences.CurrentTheme, cBoxLanguages.SelectedValue.ToString());
}


private void SetCurrentLanguageArray()
{
if (_anotherArray == true)
{
_sourceWords = SourceManager.GetLanguageArray(SourceManager.CurrentLanguage);
_secondSourceWords = null;
_anotherArray = false;
}
else
{
_secondSourceWords = SourceManager.GetLanguageArray(SourceManager.CurrentLanguage);
_sourceWords = null;
_anotherArray = true;
}

}
private void cBoxLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

SettingsChanged(Preferences.CurrentTheme, cBoxLanguages.SelectedValue.ToString());

Mouse.OverrideCursor = Cursors.Wait;

_sourceWords = SourceManager.GetLanguageArray(SourceManager.CurrentLanguage);

SetCurrentLanguageArray();

FlowDirection flowDirection = SourceManager.CurrentLanguage.FlowDirection() == SourceManager.flowDirections.right ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;

Expand All @@ -344,7 +367,7 @@ private void SettingsChanged(string themeCode, string languageName)
this.Background = (SolidColorBrush)new BrushConverter().ConvertFrom(Preferences.CurrentTheme);

}

}

}
7 changes: 7 additions & 0 deletions TarotType.Main/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions TarotType.Main/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
<data name="French" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Words\French\French.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="Georgian" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Words\Georgian\Georgian.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="Greek" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Words\Greek\Greek.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
Expand Down
16 changes: 13 additions & 3 deletions TarotType.Main/Utilities/SourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
using TarotType.Main.Utilities.Words.Greek;
using TarotType.Main.Utilities.Words.EnglishFolder;
using TarotType.Main.Settings;
using TarotType.Main.Properties;
using System.Resources;

namespace TarotType.Main.Utilities
{
public static class SourceManager
public class SourceManager
{
public static ResourceManager _resources;
public SourceManager()
{
_resources = new ResourceManager(typeof(Resources));
}


public static Language? CurrentLanguage { get; set; }

Expand All @@ -31,6 +39,7 @@ public static class SourceManager
{ new Persian(), languages.Persian},
{ new Spanish(), languages.Spanish},
{ new Turkish(), languages.Turkish},
{ new Georgian(), languages.Georgian},
};

public enum languages
Expand All @@ -44,7 +53,8 @@ public enum languages
Kurdish,
Persian,
Spanish,
Turkish
Turkish,
Georgian
}

public enum flowDirections
Expand All @@ -55,7 +65,7 @@ public enum flowDirections

public static string[] GetLanguageArray(Language language)
{
return MainWindow._resources.GetString(Preferences.LanguageName).Split(',');
return _resources.GetString(Preferences.LanguageName).Split(',');
}

}
Expand Down
26 changes: 20 additions & 6 deletions TarotType.Main/Utilities/WordManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
namespace TarotType.Main.Utilities
{
public static class WordManager
public class WordManager
{
public static string[] GetRandomWord(int wordPerEachCall)
static string[] _resultWordArray;

public WordManager(int wordPerEachCall)
{
_resultWordArray = new string[wordPerEachCall];
}

public WordManager()
{
string[] resultWordArray = new string[wordPerEachCall];

for (int i = 0; i < resultWordArray.Length; i++)
resultWordArray[i] = MainWindow._sourceWords[MainWindow._random.Next(0, MainWindow._sourceWords.Length)];
}

public static string[] GetRandomWord()
{
if (MainWindow._anotherArray == false)
for (int i = 0; i < _resultWordArray.Length; i++)
_resultWordArray[i] = MainWindow._sourceWords[MainWindow._random.Next(0, MainWindow._sourceWords.Length)];
else
for (int i = 0; i < _resultWordArray.Length; i++)
_resultWordArray[i] = MainWindow._secondSourceWords[MainWindow._random.Next(0, MainWindow._secondSourceWords.Length)];

return resultWordArray;
return _resultWordArray;
}


Expand Down
17 changes: 17 additions & 0 deletions TarotType.Main/Words/Georgian/Georgian.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace TarotType.Main.Utilities.Words.Greek
{
public class Georgian : Language
{
string _path = @"Words\Georgian\Georgian.txt";
SourceManager.flowDirections _flowDirection = SourceManager.flowDirections.left;
public override SourceManager.flowDirections FlowDirection()
{
return _flowDirection;
}

public override string Path()
{
return _path;
}
}
}
1 change: 1 addition & 0 deletions TarotType.Main/Words/Georgian/Georgian.txt

Large diffs are not rendered by default.

0 comments on commit 4706f95

Please sign in to comment.