Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Jun 14, 2024
2 parents 3039871 + b24a888 commit feb597d
Show file tree
Hide file tree
Showing 33 changed files with 653 additions and 170 deletions.
6 changes: 6 additions & 0 deletions src/StatisticAnalysisTool.Extractor/Extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public async Task ExtractIndexedItemGameDataAsync(string outputDirPath, string i
await ItemData.CreateItemDataAsync(_mainGameServerFolderString, _localizationData, outputDirPath, indexedItemsFileName);
}

public async Task ExtractSpellGameDataAsync(string outputDirPath)
{
await LoadLocationDataAsync();
await SpellData.ExtractAsJsonAsync(_localizationData, outputDirPath);
}

public async Task ExtractGameDataAsync(string outputDirPath, string[] binFileNamesToExtract)
{
await LoadLocationDataAsync();
Expand Down
4 changes: 2 additions & 2 deletions src/StatisticAnalysisTool.Extractor/ItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ private static void ExtractFromByteArray(byte[] itemDataByteArray, Stream output

private static void SetLocalization(LocalizationData data, ItemContainer item)
{
if (data.LocalizedDescriptions.TryGetValue(item.LocalizationDescriptionVariable, out var descriptions))
if (data.ItemLocalizedDescriptions.TryGetValue(item.LocalizationDescriptionVariable, out var descriptions))
{
item.LocalizedDescriptions = descriptions;
}

if (data.LocalizedNames.TryGetValue(item.LocalizationNameVariable, out var names))
if (data.ItemLocalizedNames.TryGetValue(item.LocalizationNameVariable, out var names))
{
item.LocalizedNames = names;
}
Expand Down
46 changes: 32 additions & 14 deletions src/StatisticAnalysisTool.Extractor/LocalizationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ namespace StatisticAnalysisTool.Extractor;
internal class LocalizationData : IDisposable
{
public const string ItemPrefix = "@ITEMS_";
public const string SpellPrefix = "@SPELLS_";
public const string DescPostfix = "_DESC";

public Dictionary<string, Dictionary<string, string>> LocalizedNames = new();
public Dictionary<string, Dictionary<string, string>> LocalizedDescriptions = new();
public Dictionary<string, Dictionary<string, string>> ItemLocalizedNames = new();
public Dictionary<string, Dictionary<string, string>> ItemLocalizedDescriptions = new();

public Dictionary<string, Dictionary<string, string>> SpellLocalizedNames = new();
public Dictionary<string, Dictionary<string, string>> SpellLocalizedDescriptions = new();

public async Task LoadDataAsync(string mainGameFolder)
{
Expand All @@ -21,7 +25,7 @@ await Task.Run(async () =>
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(Encoding.UTF8.GetString(localizationData.ToArray()));
using var rootNode = xmlDoc.LastChild?.LastChild?.ChildNodes;
var rootNode = xmlDoc.LastChild?.LastChild?.ChildNodes;
if (rootNode is null)
{
Expand All @@ -37,7 +41,7 @@ await Task.Run(async () =>
var tuId = node.Attributes?["tuid"];
if (tuId?.Value.StartsWith(ItemPrefix) != true)
if (tuId is null)
{
continue;
}
Expand All @@ -54,16 +58,28 @@ await Task.Run(async () =>
{
continue;
}
// Is item description
if (tuId.Value.EndsWith(DescPostfix))
if (tuId.Value.StartsWith(ItemPrefix))
{
LocalizedDescriptions[tuId.Value] = languages;
if (tuId.Value.EndsWith(DescPostfix))
{
ItemLocalizedDescriptions[tuId.Value] = languages;
}
else
{
ItemLocalizedNames[tuId.Value] = languages;
}
}
// Is item name
else
else if (tuId.Value.StartsWith(SpellPrefix))
{
LocalizedNames[tuId.Value] = languages;
if (tuId.Value.EndsWith(DescPostfix))
{
SpellLocalizedDescriptions[tuId.Value] = languages;
}
else
{
SpellLocalizedNames[tuId.Value] = languages;
}
}
}
});
Expand All @@ -73,13 +89,15 @@ await Task.Run(async () =>

public bool IsDataLoaded()
{
return LocalizedNames.Count > 0 && LocalizedDescriptions.Count > 0;
return ItemLocalizedNames.Count > 0 && ItemLocalizedDescriptions.Count > 0 && SpellLocalizedNames.Count > 0 && SpellLocalizedDescriptions.Count > 0;
}

public void Dispose()
{
LocalizedNames.Clear();
LocalizedDescriptions.Clear();
ItemLocalizedNames.Clear();
ItemLocalizedDescriptions.Clear();
SpellLocalizedNames.Clear();
SpellLocalizedDescriptions.Clear();
GC.SuppressFinalize(this);
}
}
42 changes: 42 additions & 0 deletions src/StatisticAnalysisTool.Extractor/SpellData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Text.Json;

namespace StatisticAnalysisTool.Extractor;

internal class SpellData
{
public static async Task ExtractAsJsonAsync(LocalizationData localizationData, string outputFolderPath)
{
var spells = new List<SpellLoc>();

foreach (var spellName in localizationData.SpellLocalizedNames)
{
var tuId = spellName.Key;
var descriptions = localizationData.SpellLocalizedDescriptions.FirstOrDefault(x => x.Key.Contains(tuId)).Value ?? new Dictionary<string, string>();

var uniqueName = tuId.Replace("@SPELLS_", "").Replace("_DESC", "");

spells.Add(new SpellLoc
{
UniqueName = uniqueName,
LocalizedNames = spellName.Value,
LocalizedDescriptions = descriptions
});
}

var json = JsonSerializer.Serialize(spells, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
});

var outputFilePath = Path.Combine(outputFolderPath, "spells-localization.json");
await File.WriteAllTextAsync(outputFilePath, json);
}

internal class SpellLoc
{
public string? UniqueName { get; init; }
public Dictionary<string, string>? LocalizedNames { get; init; }
public Dictionary<string, string>? LocalizedDescriptions { get; init; }
}
}
3 changes: 3 additions & 0 deletions src/StatisticsAnalysisTool/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<setting name="GuildFileName" serializeAs="String">
<value>Guild.json</value>
</setting>
<setting name="SpellLocalizationsFileName" serializeAs="String">
<value>spells-localization.json</value>
</setting>
</StatisticsAnalysisTool.Properties.Settings>
</userSettings>
<applicationSettings>
Expand Down
Binary file added src/StatisticsAnalysisTool/Assets/auto_attack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions src/StatisticsAnalysisTool/Common/ExtensionMethod.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using StatisticsAnalysisTool.Common.UserSettings;
using StatisticsAnalysisTool.Enumerations;
using StatisticsAnalysisTool.Localization;
using StatisticsAnalysisTool.Models.NetworkModel;
Expand Down Expand Up @@ -252,7 +251,7 @@ public static double GetDamagePercentage(this List<KeyValuePair<Guid, PlayerGame
var totalDamage = playerObjects.Sum(x => x.Value.Damage);
return 100.00 / totalDamage * playerDamage;
}

public static double GetHealPercentage(this List<KeyValuePair<Guid, PlayerGameObject>> playerObjects, double playerHeal)
{
var totalHeal = playerObjects.Sum(x => x.Value.Heal);
Expand Down Expand Up @@ -388,12 +387,40 @@ public static async Task<string> SerializeJsonStringAsync(this object obj, JsonS

#endregion

#region Lists / Arrays
#region List / Collection / Array

public static bool IsInBounds<T>(this IEnumerable<T> array, long index)
{
return index >= 0 && index < array.Count() - 1;
}

public static void SortByDescending<T, TKey>(this ObservableCollection<T> collection, Func<T, TKey> keySelector)
{
var sorted = collection.OrderByDescending(keySelector).ToList();
for (int i = 0; i < sorted.Count; i++)
{
collection.Move(collection.IndexOf(sorted[i]), i);
}
}

public static void SortByDescending<T, TKey>(this List<T> list, Func<T, TKey> keySelector)
{
list.Sort((x, y) => Comparer<TKey>.Default.Compare(keySelector(y), keySelector(x)));
}

public static void SortByAscending<T, TKey>(this ObservableCollection<T> collection, Func<T, TKey> keySelector)
{
var sorted = collection.OrderBy(keySelector).ToList();
for (int i = 0; i < sorted.Count; i++)
{
collection.Move(collection.IndexOf(sorted[i]), i);
}
}

public static void SortByAscending<T, TKey>(this List<T> list, Func<T, TKey> keySelector)
{
list.Sort((x, y) => Comparer<TKey>.Default.Compare(keySelector(x), keySelector(y)));
}

#endregion
}
4 changes: 2 additions & 2 deletions src/StatisticsAnalysisTool/Common/ImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ private static BitmapImage SetImage(string webPath, string uniqueName, int pixel

try
{

var userImage = new BitmapImage
{
CacheOption = BitmapCacheOption.OnDemand
};
downloading.Add(uniqueName, userImage);

downloading.TryAdd(uniqueName, userImage);
userImage.BeginInit();
userImage.DecodePixelHeight = pixelHeight;
userImage.DecodePixelWidth = pixelWidth;
Expand Down
9 changes: 7 additions & 2 deletions src/StatisticsAnalysisTool/DamageMeter/DamageMeterFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DamageMeterFragment : BaseViewModel
private double _overhealedPercentageOfTotalHealing;
private double _overhealed;
private Visibility _spellsContainerVisibility = Visibility.Collapsed;
private ObservableCollection<SpellFragment> _spells = new ();
private ObservableCollection<UsedSpellFragment> _spells = new ();

public DamageMeterFragment(DamageMeterFragment damageMeterFragment)
{
Expand All @@ -47,6 +47,7 @@ public DamageMeterFragment(DamageMeterFragment damageMeterFragment)
HealPercentage = damageMeterFragment.HealPercentage;
Name = damageMeterFragment.Name;
CauserMainHand = damageMeterFragment.CauserMainHand;
Spells = damageMeterFragment.Spells;
}

public DamageMeterFragment()
Expand Down Expand Up @@ -247,7 +248,7 @@ public double OverhealedPercentageOfTotalHealing

#region Spells

public ObservableCollection<SpellFragment> Spells
public ObservableCollection<UsedSpellFragment> Spells
{
get => _spells;
set
Expand Down Expand Up @@ -301,6 +302,10 @@ private void PerformShowSpells(object value)
public static string TranslationCombatTime => LanguageController.Translation("COMBAT_TIME");
public static string TranslationHealingWithoutOverhealed => LanguageController.Translation("HEALING_WITHOUT_OVERHEALED");
public static string TranslationOverhealedPercentageOfTotalHealing => LanguageController.Translation("OVERHEALED_PERCENTAGE_OF_TOTAL_HEALING");
public static string TranslationDmgPercent => LanguageController.Translation("DMG_PERCENT");
public static string TranslationName => LanguageController.Translation("NAME");
public static string TranslationDamageHeal => LanguageController.Translation("DAMAGE_HEAL");
public static string TranslationTicks => LanguageController.Translation("TICKS");

public override bool Equals(object obj)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Windows;
using System.Windows.Input;

Expand Down Expand Up @@ -36,10 +35,17 @@ public DamageMeterSnapshotFragment(DamageMeterFragment damageMeterFragment)
OverhealedPercentageOfTotalHealing = damageMeterFragment.OverhealedPercentageOfTotalHealing;
Spells = damageMeterFragment.Spells.Select(x => new SpellsSnapshotFragment()
{
Index = x.Index,
SpellIndex = x.SpellIndex,
ItemIndex = x.ItemIndex,
UniqueName = x.UniqueName,
DamageHealValue = x.DamageHealValue,
DamageHealShortString = x.DamageHealShortString
DamageHealShortString = x.DamageHealShortString,
Target = x.Target,
Category = x.Category,
Ticks = x.Ticks,
DamageInPercent = x.DamageInPercent,
DamagePercentage = x.DamagePercentage,
HealthChangeType = x.HealthChangeType
}).ToList();
}

Expand Down Expand Up @@ -122,7 +128,6 @@ public double Hps

public List<SpellsSnapshotFragment> Spells { get; init; }

[JsonIgnore]
public Visibility SpellsContainerVisibility
{
get => _spellsContainerVisibility;
Expand All @@ -144,6 +149,10 @@ private void PerformShowSpells(object value)
public ICommand ShowSpells => _showSpells ??= new CommandHandler(PerformShowSpells, true);

public string TranslationCombatTime => LanguageController.Translation("COMBAT_TIME");
public static string TranslationDmgPercent => LanguageController.Translation("DMG_PERCENT");
public static string TranslationName => LanguageController.Translation("NAME");
public static string TranslationDamageHeal => LanguageController.Translation("DAMAGE_HEAL");
public static string TranslationTicks => LanguageController.Translation("TICKS");

public string CauserMainHandItemUniqueName
{
Expand All @@ -156,7 +165,6 @@ public string CauserMainHandItemUniqueName
}
}

[JsonIgnore]
public Item CauserMainHand => ItemController.GetItemByUniqueName(CauserMainHandItemUniqueName);
public string ShopSubCategory { get; set; }
}
21 changes: 16 additions & 5 deletions src/StatisticsAnalysisTool/DamageMeter/SnapshotMapping.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using StatisticsAnalysisTool.Enumerations;
using System.Linq;

namespace StatisticsAnalysisTool.DamageMeter;

Expand Down Expand Up @@ -76,21 +77,31 @@ private static SpellFragmentDto Mapping(SpellsSnapshotFragment snapshot)
{
return new SpellFragmentDto()
{
Index = snapshot.Index,
SpellIndex = snapshot.SpellIndex,
ItemIndex = snapshot.ItemIndex,
UniqueName = snapshot.UniqueName,
DamageHealValue = snapshot.DamageHealValue,
DamageHealShortString = snapshot.DamageHealShortString
DamageHealShortString = snapshot.DamageHealShortString,
Target = snapshot.Target,
Category = snapshot.Category,
Ticks = snapshot.Ticks,
HealthChangeType = snapshot.HealthChangeType
};
}

private static SpellsSnapshotFragment Mapping(SpellFragmentDto snapshotDto)
{
return new SpellsSnapshotFragment()
{
Index = snapshotDto.Index,
SpellIndex = snapshotDto.SpellIndex,
ItemIndex = snapshotDto.ItemIndex,
UniqueName = snapshotDto.UniqueName,
DamageHealValue = snapshotDto.DamageHealValue,
DamageHealShortString = snapshotDto.DamageHealShortString
DamageHealShortString = snapshotDto.DamageHealShortString,
Target = snapshotDto.Target,
Category = snapshotDto.Category,
Ticks = snapshotDto.Ticks,
HealthChangeType = snapshotDto.HealthChangeType
};
}
}
Loading

0 comments on commit feb597d

Please sign in to comment.