Skip to content

Commit

Permalink
Fixed CraftingBase
Browse files Browse the repository at this point in the history
Converted Dictionary to HashSet
  • Loading branch information
smad2005 committed Oct 14, 2015
1 parent 1d309c1 commit 17fa7bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/Hud/Loot/CraftingBase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using PoeHUD.Models.Enums;

namespace PoeHUD.Hud.Loot
Expand All @@ -11,5 +12,16 @@ public struct CraftingBase
public int MinQuality { get; set; }

public ItemRarity[] Rarities { get; set; }

public override int GetHashCode()
{
return Name.ToLowerInvariant().GetHashCode();
}

public override bool Equals(object obj)
{
var strct = (CraftingBase)obj;
return Name.Equals(strct.Name, StringComparison.InvariantCultureIgnoreCase);
}
}
}
35 changes: 15 additions & 20 deletions src/Hud/Loot/ItemAlertPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ItemAlertPlugin : SizedPluginWithMapIcons<ItemAlertSettings>

private readonly Dictionary<EntityWrapper, AlertDrawStyle> currentAlerts;

private readonly Dictionary<string, CraftingBase> craftingBases;
private readonly HashSet<CraftingBase> craftingBases;

private readonly HashSet<string> currencyNames;

Expand All @@ -56,8 +56,6 @@ public ItemAlertPlugin(GameController gameController, Graphics graphics, ItemAle
GameController.Area.OnAreaChange += OnAreaChange;
PoeFilterInit(settings.FilePath);
settings.FilePath.OnFileChanged += () => PoeFilterInit(settings.FilePath);


}

private void PoeFilterInit(string path)
Expand Down Expand Up @@ -141,10 +139,11 @@ public override void Render()
shouldUpdate = true;
}
else
{
if (Settings.ShowText & (!Settings.HideOthers | entityLabel.CanPickUp))
{
position = DrawText(playerPos, position, BOTTOM_MARGIN, kv, text);
}
}

}
Size = new Size2F(0, position.Y); //bug absent width

Expand Down Expand Up @@ -214,13 +213,13 @@ protected override void OnEntityRemoved(EntityWrapper entity)
currentLabels.Remove(entity.Address);
}

private static Dictionary<string, CraftingBase> LoadCraftingBases()
private static HashSet<CraftingBase> LoadCraftingBases()
{
if (!File.Exists("config/crafting_bases.txt"))
{
return new Dictionary<string, CraftingBase>();
return new HashSet<CraftingBase>();
}
var dictionary = new Dictionary<string, CraftingBase>(StringComparer.OrdinalIgnoreCase);
var hashSet = new HashSet<CraftingBase>();
var parseErrors = new List<string>();
string[] array = File.ReadAllLines("config/crafting_bases.txt");
foreach (string text in array.Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith("#")))
Expand Down Expand Up @@ -255,22 +254,19 @@ private static Dictionary<string, CraftingBase> LoadCraftingBases()
}
}

if (!dictionary.ContainsKey(itemName))
{
dictionary.Add(itemName, item);
}
else
if (!hashSet.Add(item))
{
parseErrors.Add("Duplicate definition for item was ignored: " + text);
}

}

if (parseErrors.Any())
{
throw new Exception("Error parsing config/crafting_bases.txt\r\n" + string.Join(Environment.NewLine, parseErrors));
}

return dictionary;
return hashSet;
}

private static HashSet<string> LoadCurrency()
Expand Down Expand Up @@ -367,18 +363,17 @@ private ItemUsefulProperties GetItemUsefulProperties(IEntity item)
{
Contract.Requires(item != null);
Contract.Ensures(Contract.Result<ItemUsefulProperties>() != null);

string name = GameController.Files.BaseItemTypes.Translate(item.Path).BaseName;

string name = GameController.Files.BaseItemTypes.Translate(item.Path).BaseName;
CraftingBase craftingBase = new CraftingBase();
if (Settings.Crafting)
{
foreach (KeyValuePair<string, CraftingBase> cb in craftingBases)
foreach (CraftingBase cb in craftingBases)
{
if (cb.Key.Equals(name)
|| (new Regex(cb.Value.Name)).Match(name).Success)
if (cb.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)
|| (new Regex(cb.Name)).Match(name).Success)
{
craftingBase = cb.Value;
craftingBase = cb;
break;
}
}
Expand Down

0 comments on commit 17fa7bb

Please sign in to comment.