Skip to content

Commit 297125b

Browse files
committed
Inspirational id is now taken *after* the list is filtered. This gets rid of an issue with IndexOutOfRangeException.
1 parent 97ffd8d commit 297125b

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

SalemOptimizer/InspirationalDatabase.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ public static class InspirationalDatabase
1515
public static List<Inspirational> Inspirationals { get { return inspirationals.Value; } }
1616

1717
static List<Inspirational> Load()
18-
{
19-
return
20-
File.ReadAllLines("Inspirationals.tab")
21-
.Select(row => row.Split('\t'))
22-
.Select
23-
(
24-
(cols, index) =>
25-
new Inspirational
26-
{
27-
Id = index,
28-
Name = cols[0],
29-
Proficiencies =
30-
cols
31-
.Select((val, idx) => new { Index = idx, Value = val })
32-
.Where(i => i.Index >= 2 && i.Index <= 16 && !string.IsNullOrWhiteSpace(i.Value))
33-
.ToDictionary(i => (ProficiencyKind)(i.Index - 2), i => int.Parse(i.Value)),
34-
Uses = int.Parse(cols[18]),
35-
Weight = string.IsNullOrWhiteSpace(cols[1]) ? 1d : double.Parse(cols[1], CultureInfo.InvariantCulture)
36-
}
37-
)
38-
.Where(i => i.Proficiencies.Count > 0)
39-
.ToList();
18+
{
19+
return
20+
File.ReadAllLines("Inspirationals.tab")
21+
.Select(row => row.Split('\t'))
22+
.Select
23+
(
24+
(cols, index) =>
25+
new Inspirational
26+
{
27+
Name = cols[0],
28+
Proficiencies =
29+
cols
30+
.Select((val, idx) => new { Index = idx, Value = val })
31+
.Where(i => i.Index >= 2 && i.Index <= 16 && !string.IsNullOrWhiteSpace(i.Value))
32+
.ToDictionary(i => (ProficiencyKind)(i.Index - 2), i => int.Parse(i.Value)),
33+
Uses = int.Parse(cols[18]),
34+
Weight = string.IsNullOrWhiteSpace(cols[1]) ? 1d : double.Parse(cols[1], CultureInfo.InvariantCulture)
35+
}
36+
)
37+
.Where(i => i.Proficiencies.Count > 0)
38+
.Select((inspirational, index) => { inspirational.Id = index; return inspirational; })
39+
.ToList();
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)