Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Mar 2, 2023
2 parents f0138a2 + 6d1b53d commit 3e664c3
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 80 deletions.
9 changes: 7 additions & 2 deletions src/StatisticsAnalysisTool/Common/CraftingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static double GetCraftingTax(int foodValue, Item item, double itemQuantit
return 0;
}
}

public static double GetSetupFeePerFoodConsumed(int foodValue, int numberOfMaterials, ItemTier tier, ItemLevel level, IEnumerable<CraftResource> craftResource)
{
var tierFactor = (tier, level) switch
Expand All @@ -205,27 +205,32 @@ public static double GetSetupFeePerFoodConsumed(int foodValue, int numberOfMater
(ItemTier.T4, ItemLevel.Level1) => 3.6f,
(ItemTier.T4, ItemLevel.Level2) => 7.2f,
(ItemTier.T4, ItemLevel.Level3) => 14.4f,
(ItemTier.T4, ItemLevel.Level4) => 28.8f,
(ItemTier.T5, ItemLevel.Level0) => 3.6f,
(ItemTier.T5, ItemLevel.Level1) => 7.2f,
(ItemTier.T5, ItemLevel.Level2) => 14.4f,
(ItemTier.T5, ItemLevel.Level3) => 28.8f,
(ItemTier.T5, ItemLevel.Level4) => 57.6f,
(ItemTier.T6, ItemLevel.Level0) => 7.2f,
(ItemTier.T6, ItemLevel.Level1) => 14.4f,
(ItemTier.T6, ItemLevel.Level2) => 28.8f,
(ItemTier.T6, ItemLevel.Level3) => 57.6f,
(ItemTier.T6, ItemLevel.Level4) => 115.2f,
(ItemTier.T7, ItemLevel.Level0) => 14.4f,
(ItemTier.T7, ItemLevel.Level1) => 28.8f,
(ItemTier.T7, ItemLevel.Level2) => 57.6f,
(ItemTier.T7, ItemLevel.Level3) => 115.2f,
(ItemTier.T7, ItemLevel.Level4) => 230.4f,
(ItemTier.T8, ItemLevel.Level0) => 28.8f,
(ItemTier.T8, ItemLevel.Level1) => 57.6f,
(ItemTier.T8, ItemLevel.Level2) => 115.2f,
(ItemTier.T8, ItemLevel.Level3) => 230.4f,
(ItemTier.T8, ItemLevel.Level4) => 460.8f,
_ => 1
};

var safeFoodValue = (foodValue <= 0) ? 1d : foodValue;
return safeFoodValue / 100d * numberOfMaterials * (tierFactor + GetArtifactFactor(craftResource));
return Math.Round(safeFoodValue / 100d * numberOfMaterials * (tierFactor + GetArtifactFactor(craftResource)));
}

private static double GetArtifactFactor(IEnumerable<CraftResource> requiredResources, double craftingTaxDefault = 0.0d)
Expand Down
2 changes: 1 addition & 1 deletion src/StatisticsAnalysisTool/Common/HttpClientUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static async Task<bool> DownloadFileAsync(this HttpClient client, string
var percentage = bytesProcessed * 100.0 / totalBytes;
if (mainWindowViewModel != null)
{
mainWindowViewModel.ToolTaskProgressBarValue = percentage;
mainWindowViewModel.ToolTaskProgressBarValue = percentage ?? 0;
}
}

Expand Down
84 changes: 68 additions & 16 deletions src/StatisticsAnalysisTool/Common/LanguageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
using System.Windows;
using System.Windows.Markup;
using System.Xml;
using System.Xml.Linq;

namespace StatisticsAnalysisTool.Common;
// TODO: Change language controller - one language file for all and refactoring

public static class LanguageController
{
private static readonly Dictionary<string, string> Translations = new();
Expand Down Expand Up @@ -121,8 +122,8 @@ public static bool SetLanguage()
}

var fileInfos = (from file in LanguageFiles
where file.FileName.ToUpper() == CurrentCultureInfo?.TextInfo.CultureName.ToUpper()
select new FileInformation(file.FileName, file.FilePath)).FirstOrDefault();
where file.FileName.ToUpper() == CurrentCultureInfo?.TextInfo.CultureName.ToUpper()
select new FileInformation(file.FileName, file.FilePath)).FirstOrDefault();

if (fileInfos == null)
{
Expand Down Expand Up @@ -157,10 +158,27 @@ private static bool ReadAndAddLanguageFile(string filePath)
try
{
Translations.Clear();
var xmlReader = XmlReader.Create(filePath);
var xmlReader = XmlReader.Create(filePath, new XmlReaderSettings()
{
Async = true
});

while (xmlReader.Read())
if (xmlReader.Name == "translation" && xmlReader.HasAttributes)
AddTranslationsToDictionary(xmlReader);
{
if (xmlReader.Name != "translation" || !xmlReader.HasAttributes)
{
continue;
}

var translationLine = GetTranslationLine(xmlReader);

if (string.IsNullOrEmpty(translationLine.Item1) || string.IsNullOrEmpty(translationLine.Item2))
{
continue;
}

Translations.Add(translationLine.Item1, translationLine.Item2);
}
}
catch (Exception e)
{
Expand All @@ -173,19 +191,23 @@ private static bool ReadAndAddLanguageFile(string filePath)
return true;
}

private static void AddTranslationsToDictionary(XmlReader xmlReader)
private static Tuple<string, string> GetTranslationLine(XmlReader xmlReader)
{
while (xmlReader.MoveToNextAttribute())
var name = xmlReader.GetAttribute("name");
var value = xmlReader.ReadString();

if (name == null || string.IsNullOrEmpty(value))
{
if (Translations.ContainsKey(xmlReader.Value))
{
Log.Warn($"{nameof(AddTranslationsToDictionary)}: {Translation("DOUBLE_VALUE_EXISTS_IN_THE_LANGUAGE_FILE")}: {xmlReader.Value}");
}
else if (xmlReader.Name == "name")
{
Translations.Add(xmlReader.Value, xmlReader.ReadString());
}
return new Tuple<string, string>(string.Empty, string.Empty);
}

if (Translations.ContainsKey(name))
{
Log.Warn($"{nameof(GetTranslationLine)}: {Translation("DOUBLE_VALUE_EXISTS_IN_THE_LANGUAGE_FILE")}: {name}");
return new Tuple<string, string>(string.Empty, string.Empty);
}

return new Tuple<string, string>(name, value);
}

private static void InitializeLanguageFilesFromDirectory()
Expand Down Expand Up @@ -215,4 +237,34 @@ private static void InitializeLanguageFilesFromDirectory()
LanguageFiles.Add(fileInfo);
}
}

public static void GetPercentageTranslationValues(string mainLanguageFileName = "en-US")
{
var mainLanguageFile = LanguageFiles.FirstOrDefault(x => string.Equals(x.FileName, mainLanguageFileName, StringComparison.CurrentCultureIgnoreCase));
if (mainLanguageFile == null)
{
return;
}

var mainLanguageFileCount = CountTranslations(mainLanguageFile.FilePath);
mainLanguageFile.PercentageTranslations = 100;

foreach (FileInformation fileInformation in LanguageFiles.Where(x => x.FileName != mainLanguageFileName).ToList())
{
var countTranslations = CountTranslations(fileInformation.FilePath);
double percentageValue = 100d / mainLanguageFileCount * countTranslations;

var fileInfo = LanguageFiles.FirstOrDefault(x => x.FileName == fileInformation.FileName);
if (fileInfo != null)
{
fileInfo.PercentageTranslations = (percentageValue > 100d) ? 100 : percentageValue;
}
}
}

private static int CountTranslations(string filePath)
{
var xml = XDocument.Load(filePath);
return xml.Descendants("translation").Count();
}
}
13 changes: 12 additions & 1 deletion src/StatisticsAnalysisTool/Gathering/Gathered.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Gathered : INotifyPropertyChanged
private int _gainedTotalAmount;
private bool _isSelectedForDeletion;
private FixPoint _estimatedMarketValue;
private string _totalMarketValueWithCulture;

public Gathered()
{
Expand Down Expand Up @@ -89,6 +90,8 @@ public int GainedTotalAmount
set
{
_gainedTotalAmount = value;

TotalMarketValueWithCulture = Utilities.LongWithCulture(FixPoint.FromFloatingPointValue(_gainedTotalAmount * EstimatedMarketValue.IntegerValue).IntegerValue);
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -128,7 +131,15 @@ public FixPoint TotalMarketValue
get => FixPoint.FromFloatingPointValue(GainedTotalAmount * EstimatedMarketValue.IntegerValue);
}

public string TotalMarketValueWithCulture => Utilities.LongWithCulture(TotalMarketValue.IntegerValue);
public string TotalMarketValueWithCulture
{
get => _totalMarketValueWithCulture;
set
{
_totalMarketValueWithCulture = value;
OnPropertyChanged();
}
}

public string ClusterIndex { get; init; }
public MapType MapType { get; init; }
Expand Down
Loading

0 comments on commit 3e664c3

Please sign in to comment.