Skip to content

Commit

Permalink
3.12.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ffhighwind committed Sep 24, 2020
1 parent cd17c4e commit 0dd084a
Show file tree
Hide file tree
Showing 22 changed files with 1,738 additions and 1,527 deletions.
60 changes: 36 additions & 24 deletions DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -69,16 +70,16 @@ public class DataModel
public IReadOnlyList<string> Enchantments { get; private set; }

private const int MaxErrors = 5;
private int ErrorCount = 0;

private List<IReadOnlyList<string>> conflicts { get; } = new List<IReadOnlyList<string>>();
public IReadOnlyList<IReadOnlyList<string>> DivinationCardNameConflicts => conflicts;

public void Load()
{
ErrorCount = 0;
LoadUniquesCsv();
LoadEnchantsCsv();
UniquesErrors.Clear();
EnchantsErrors.Clear();
GetJsonData(HC);
GetJsonData(SC);
string filterString = Util.ReadWebPage(FiltersUrl + filterFile);
Expand All @@ -93,6 +94,19 @@ public void Load()
VersionMinor = int.Parse(m.Groups[2].Value);
VersionRelease = int.Parse(m.Groups[3].Value);
Version = VersionMajor.ToString() + "." + VersionMinor + "." + VersionRelease;

if (UniquesErrors.Count > 0 || EnchantsErrors.Count > 0) {
UniquesErrors = UniquesErrors.Distinct().OrderBy(x => x.BaseType).ThenBy(x => x.Name).ToList();
EnchantsErrors = EnchantsErrors.Distinct().OrderBy(x => x.BaseType).ThenBy(x => x.Name).ToList();
List<string> errs = new List<string>();
if (UniquesErrors.Count > 0) {
errs.Add(UniquesErrors.Count + " uniques");
}
if (EnchantsErrors.Count > 0) {
errs.Add(EnchantsErrors.Count + " enchantments");
}
MessageBox.Show("Missing " + string.Join(", ", errs) + "\n\nThese will be copied to the clipboard. Add them to the CSV files.", "Load JSON", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public void Load(string filename)
Expand All @@ -109,9 +123,6 @@ public void Load(string filename)

public void Load(string[] lines)
{
ErrorCount = 0;
//HC.ClearFilterValues();
//SC.ClearFilterValues();
GetFilterData(lines);

DivinationCards = SC.DivinationCards.Keys.OrderBy(x => x).ToList();
Expand All @@ -133,6 +144,17 @@ public void Load(string[] lines)
Enchantments = SC.Enchantments.Keys.OrderBy(x => x).ToList();
}

private List<JsonData> UniquesErrors = new List<JsonData>();
private List<JsonData> EnchantsErrors = new List<JsonData>();

public string GetErrorsString()
{
return "Type\tBaseType\tName" + Environment.NewLine +
string.Join(Environment.NewLine,
UniquesErrors.Select(e => "Unique\t" + e.BaseType + "\t" + e.Name)
.Concat(EnchantsErrors.Select(e => "Enchants\t" + e.BaseType + "\t" + e.Name)));
}

private void GetJsonData(LeagueData data)
{
string leagueStr = data.IsHardcore ? "Hardcore " + league : league;
Expand Down Expand Up @@ -167,13 +189,9 @@ private void EnchantJsonHandler(JsonData jdata, LeagueData data)
if (!data.EnchantmentsDescriptions.TryGetValue(description, out Enchantment ench)) {
ench = new Enchantment(description);
data.EnchantmentsDescriptions.Add(description, ench);
MessageBox.Show("JSON: The CSV file is missing Enchantment: " + description, "Error", MessageBoxButtons.OK);
ErrorCount++;
EnchantsErrors.Add(jdata);
}
ench.Load(jdata);
if (ErrorCount > MaxErrors) {
Environment.Exit(1);
}
}

private void UniqueJsonHandler(JsonData jdata, LeagueData data)
Expand All @@ -182,25 +200,17 @@ private void UniqueJsonHandler(JsonData jdata, LeagueData data)
if (!data.Uniques.TryGetValue(baseTy, out UniqueBaseType uniq)) {
uniq = new UniqueBaseType(baseTy);
data.Uniques.Add(baseTy, uniq);
if (!data.IsHardcore) {
MessageBox.Show("JSON: The CSV file is missing BaseType: " + baseTy, "Error", MessageBoxButtons.OK);
ErrorCount++;
}
}
if (!uniq.Add(jdata) && !data.IsHardcore) {
MessageBox.Show("JSON: The CSV file is missing: " + jdata.BaseType + " " + jdata.Name, "Error", MessageBoxButtons.OK);
ErrorCount++;
}
if (ErrorCount > MaxErrors) {
Environment.Exit(1);
if (!uniq.Add(jdata)) {
UniquesErrors.Add(jdata);
}
}

private void DivinationJsonHandler(JsonData jdata, LeagueData data)
{
string name = jdata.Name;
if (!data.DivinationCards.TryGetValue(name, out DivinationCard div)) {
div = new DivinationCard();
if (!data.DivinationCards.ContainsKey(name)) {
DivinationCard div = new DivinationCard();
data.DivinationCards.Add(name, div);
}
data.DivinationCards[name].Load(jdata);
Expand Down Expand Up @@ -241,6 +251,10 @@ private void LoadEnchantsCsv()
: Util.ReadWebPage(repoURL + helmEnchantCsvFile, "", Encoding.UTF8);
EnchantCsv[] records = engine.ReadString(csvText);
foreach (EnchantCsv csvdata in records) {
if (string.IsNullOrWhiteSpace(csvdata.Description))
continue; // skip unknowns
if (csvdata.Description[0] == '=')
csvdata.Description = csvdata.Description.Substring(1);
if (!SC.Enchantments.ContainsKey(csvdata.Description)) {
Enchantment scData = new Enchantment(csvdata.Name);
SC.Enchantments.Add(csvdata.Name, scData);
Expand Down Expand Up @@ -364,8 +378,6 @@ private void GetFilterEnchantsData(IEnumerable<string> lines)
else if (line.Contains("10c+"))
value = EnchantmentValue.Chaos10;
else {
//if (!line.Contains("Other"))
// MessageBox.Show("Unexpected Enchant input: " + line, "Error", MessageBoxButtons.OK);
lines = lines.Skip(1);
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions Enchants/EnchantCsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace PoE_Price_Lister
[IgnoreFirst(1)]
public class EnchantCsv
{
[FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.AllowForRead)]
public string Item { get; set; }

[FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.AllowForRead)]
public string Name { get; set; }

Expand All @@ -40,6 +43,8 @@ internal class DifficultyConverter : ConverterBase
{
public override object StringToField(string from)
{
if (from.Equals("Eternal Labyrinth of Potential"))
return EnchantmentSource.EternalLabyrinthOfPotential;
if (from.Equals("Merciless Labyrinth"))
return EnchantmentSource.MercilessLab;
if (from.Equals("Eternal Labyrinth"))
Expand Down
1 change: 1 addition & 0 deletions Enchants/EnchantmentSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public enum EnchantmentSource
CruelLab,
MercilessLab,
EternalLab,
EternalLabyrinthOfPotential,
}
}
28 changes: 24 additions & 4 deletions JsonData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#endregion

using System;

using System.Collections.Generic;
using Newtonsoft.Json;

namespace PoE_Price_Lister
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class JsonData
{
public sealed class JsonData : IEquatable<JsonData>
{
public JsonData() { }

//[JsonProperty(PropertyName = "id")]
Expand Down Expand Up @@ -98,7 +98,27 @@ public JsonData() { }
[JsonProperty(PropertyName = "count")]
public int Count { get; set; } // too low means low accuracy

public override string ToString()
public override bool Equals(object obj)
{
return Equals(obj as JsonData);
}

public bool Equals(JsonData other)
{
return other != null &&
Name == other.Name &&
BaseType == other.BaseType;
}

public override int GetHashCode()
{
int hashCode = -1412448124;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(BaseType);
return hashCode;
}

public override string ToString()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
Expand Down
7 changes: 7 additions & 0 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ await Task.Run(
buttonGenFilter.Enabled = true;
buttonLoad.Enabled = true;
Text += " (v" + model.Version + ")";

string errors = model.GetErrorsString();
if (errors.Length > 0) {
Invoke(new Action(() => {
Clipboard.SetText(errors);
}));
}
}

private void LoadDataGridViews()
Expand Down
1 change: 1 addition & 0 deletions PoE Price Lister.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="poe_helm_enchants.csv" />
<None Include="README.md" />
<None Include="Resources\FilterNova-AutoUpdater.ahk" />
<None Include="Resources\Filters\filter font enlarger.ahk" />
Expand Down
Binary file modified Resources/Filters/Filters.zip
Binary file not shown.
Loading

0 comments on commit 0dd084a

Please sign in to comment.