Skip to content

Commit

Permalink
Fixed Maxroll builds for non-English languages
Browse files Browse the repository at this point in the history
  • Loading branch information
josdemmers committed May 19, 2024
1 parent 904350c commit cfbf10e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
4 changes: 2 additions & 2 deletions D4Companion.Interfaces/IAffixManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public interface IAffixManager
ItemAffix GetAffix(string affixId, string itemType);
string GetAffixDescription(string affixId);
string GetAffixId(int affixSno);
AffixInfo? GetAffixInfo(AffixInfo affixInfo);
AffixInfo? GetAffixInfoFromFull(int affixSno);
AffixInfo? GetAffixInfoEnUS(AffixInfo affixInfo);
AffixInfo? GetAffixInfoEnUSFull(int affixSno);
ItemAffix GetAspect(string aspectId, string itemType);
string GetAspectDescription(string aspectId);
string GetAspectId(int aspectSno);
Expand Down
43 changes: 33 additions & 10 deletions D4Companion.Services/AffixManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class AffixManager : IAffixManager
private readonly ISettingsManager _settingsManager;

private List<AffixInfo> _affixes = new List<AffixInfo>();
private List<AffixInfo> _affixesFull = new List<AffixInfo>();
private List<AffixInfo> _affixesEnUS = new List<AffixInfo>();
private List<AffixInfo> _affixesEnUSFull = new List<AffixInfo>();
private List<AffixPreset> _affixPresets = new List<AffixPreset>();
private List<AspectInfo> _aspects = new List<AspectInfo>();
private List<SigilInfo> _sigils = new List<SigilInfo>();
Expand All @@ -41,7 +42,7 @@ public AffixManager(IEventAggregator eventAggregator, ILogger<AffixManager> logg

// Init store data
InitAffixData();
InitAffixDataFull();
InitAffixDataEnUS();
InitAspectData();
InitSigilData();
InitSigilDungeonTierData();
Expand Down Expand Up @@ -249,10 +250,13 @@ private void InitAffixData()
}
}

private void InitAffixDataFull()
/// <summary>
/// Used for Maxroll builds to import builds when app setting is not set to English.
/// </summary>
private void InitAffixDataEnUS()
{
_affixesFull.Clear();
string resourcePath = @$".\Data\Affixes.Full.enUS.json";
_affixesEnUS.Clear();
string resourcePath = @$".\Data\Affixes.enUS.json";
using (FileStream? stream = File.OpenRead(resourcePath))
{
if (stream != null)
Expand All @@ -266,7 +270,26 @@ private void InitAffixDataFull()
options.Converters.Add(new BoolConverter());
options.Converters.Add(new IntConverter());

_affixesFull = JsonSerializer.Deserialize<List<AffixInfo>>(stream, options) ?? new List<AffixInfo>();
_affixesEnUS = JsonSerializer.Deserialize<List<AffixInfo>>(stream, options) ?? new List<AffixInfo>();
}
}

_affixesEnUSFull.Clear();
string resourcePathFull = @$".\Data\Affixes.Full.enUS.json";
using (FileStream? stream = File.OpenRead(resourcePathFull))
{
if (stream != null)
{
// create the options
var options = new JsonSerializerOptions()
{
WriteIndented = true
};
// register the converter
options.Converters.Add(new BoolConverter());
options.Converters.Add(new IntConverter());

_affixesEnUSFull = JsonSerializer.Deserialize<List<AffixInfo>>(stream, options) ?? new List<AffixInfo>();
}
}
}
Expand Down Expand Up @@ -407,9 +430,9 @@ public string GetAffixId(int affixSno)
/// </summary>
/// <param name="affixInfo"></param>
/// <returns></returns>
public AffixInfo? GetAffixInfo(AffixInfo affixInfo)
public AffixInfo? GetAffixInfoEnUS(AffixInfo affixInfo)
{
return _affixes.FirstOrDefault(a => a.DescriptionClean.Equals(affixInfo.DescriptionClean));
return _affixesEnUS.FirstOrDefault(a => a.DescriptionClean.Equals(affixInfo.DescriptionClean));
}

/// <summary>
Expand All @@ -418,9 +441,9 @@ public string GetAffixId(int affixSno)
/// </summary>
/// <param name="affixSno"></param>
/// <returns></returns>
public AffixInfo? GetAffixInfoFromFull(int affixSno)
public AffixInfo? GetAffixInfoEnUSFull(int affixSno)
{
return _affixesFull.FirstOrDefault(a => a.IdSno == affixSno);
return _affixesEnUSFull.FirstOrDefault(a => a.IdSno == affixSno);
}

public ItemAffix GetAspect(string aspectId, string itemType)
Expand Down
8 changes: 4 additions & 4 deletions D4Companion.Services/BuildsManagerMaxroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
foreach (var explicitAffix in maxrollBuild.Data.Items[item.Value].Explicits)
{
int affixSno = explicitAffix.Nid;
AffixInfo? affixInfoFull = _affixManager.GetAffixInfoFromFull(affixSno);
AffixInfo? affixInfoFull = _affixManager.GetAffixInfoEnUSFull(affixSno);

if (affixInfoFull == null)
{
Expand All @@ -165,7 +165,7 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
}
else
{
AffixInfo? affixInfo = _affixManager.GetAffixInfo(affixInfoFull);
AffixInfo? affixInfo = _affixManager.GetAffixInfoEnUS(affixInfoFull);
if (affixInfo == null)
{
_logger.LogWarning($"{MethodBase.GetCurrentMethod()?.Name}: Unknown affix: ({affixInfoFull.IdSno}) {affixInfoFull.IdName}");
Expand All @@ -192,7 +192,7 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
foreach (var temperedAffix in maxrollBuild.Data.Items[item.Value].Tempered)
{
int affixSno = temperedAffix.Nid;
AffixInfo? affixInfoFull = _affixManager.GetAffixInfoFromFull(affixSno);
AffixInfo? affixInfoFull = _affixManager.GetAffixInfoEnUSFull(affixSno);

if (affixInfoFull == null)
{
Expand All @@ -204,7 +204,7 @@ public void CreatePresetFromMaxrollBuild(MaxrollBuild maxrollBuild, string profi
}
else
{
AffixInfo? affixInfo = _affixManager.GetAffixInfo(affixInfoFull);
AffixInfo? affixInfo = _affixManager.GetAffixInfoEnUS(affixInfoFull);
if (affixInfo == null)
{
_logger.LogWarning($"{MethodBase.GetCurrentMethod()?.Name}: Unknown tempered affix: ({affixInfoFull.IdSno}) {affixInfoFull.IdName}");
Expand Down

0 comments on commit cfbf10e

Please sign in to comment.