1818
1919using System ;
2020using System . Collections . Generic ;
21+ using System . ComponentModel ;
2122using System . IO ;
2223using System . Linq ;
2324using System . Text ;
@@ -69,16 +70,16 @@ public class DataModel
6970 public IReadOnlyList < string > Enchantments { get ; private set ; }
7071
7172 private const int MaxErrors = 5 ;
72- private int ErrorCount = 0 ;
7373
7474 private List < IReadOnlyList < string > > conflicts { get ; } = new List < IReadOnlyList < string > > ( ) ;
7575 public IReadOnlyList < IReadOnlyList < string > > DivinationCardNameConflicts => conflicts ;
7676
7777 public void Load ( )
7878 {
79- ErrorCount = 0 ;
8079 LoadUniquesCsv ( ) ;
8180 LoadEnchantsCsv ( ) ;
81+ UniquesErrors . Clear ( ) ;
82+ EnchantsErrors . Clear ( ) ;
8283 GetJsonData ( HC ) ;
8384 GetJsonData ( SC ) ;
8485 string filterString = Util . ReadWebPage ( FiltersUrl + filterFile ) ;
@@ -93,6 +94,19 @@ public void Load()
9394 VersionMinor = int . Parse ( m . Groups [ 2 ] . Value ) ;
9495 VersionRelease = int . Parse ( m . Groups [ 3 ] . Value ) ;
9596 Version = VersionMajor . ToString ( ) + "." + VersionMinor + "." + VersionRelease ;
97+
98+ if ( UniquesErrors . Count > 0 || EnchantsErrors . Count > 0 ) {
99+ UniquesErrors = UniquesErrors . Distinct ( ) . OrderBy ( x => x . BaseType ) . ThenBy ( x => x . Name ) . ToList ( ) ;
100+ EnchantsErrors = EnchantsErrors . Distinct ( ) . OrderBy ( x => x . BaseType ) . ThenBy ( x => x . Name ) . ToList ( ) ;
101+ List < string > errs = new List < string > ( ) ;
102+ if ( UniquesErrors . Count > 0 ) {
103+ errs . Add ( UniquesErrors . Count + " uniques" ) ;
104+ }
105+ if ( EnchantsErrors . Count > 0 ) {
106+ errs . Add ( EnchantsErrors . Count + " enchantments" ) ;
107+ }
108+ MessageBox . Show ( "Missing " + string . Join ( ", " , errs ) + "\n \n These will be copied to the clipboard. Add them to the CSV files." , "Load JSON" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
109+ }
96110 }
97111
98112 public void Load ( string filename )
@@ -109,9 +123,6 @@ public void Load(string filename)
109123
110124 public void Load ( string [ ] lines )
111125 {
112- ErrorCount = 0 ;
113- //HC.ClearFilterValues();
114- //SC.ClearFilterValues();
115126 GetFilterData ( lines ) ;
116127
117128 DivinationCards = SC . DivinationCards . Keys . OrderBy ( x => x ) . ToList ( ) ;
@@ -133,6 +144,17 @@ public void Load(string[] lines)
133144 Enchantments = SC . Enchantments . Keys . OrderBy ( x => x ) . ToList ( ) ;
134145 }
135146
147+ private List < JsonData > UniquesErrors = new List < JsonData > ( ) ;
148+ private List < JsonData > EnchantsErrors = new List < JsonData > ( ) ;
149+
150+ public string GetErrorsString ( )
151+ {
152+ return "Type\t BaseType\t Name" + Environment . NewLine +
153+ string . Join ( Environment . NewLine ,
154+ UniquesErrors . Select ( e => "Unique\t " + e . BaseType + "\t " + e . Name )
155+ . Concat ( EnchantsErrors . Select ( e => "Enchants\t " + e . BaseType + "\t " + e . Name ) ) ) ;
156+ }
157+
136158 private void GetJsonData ( LeagueData data )
137159 {
138160 string leagueStr = data . IsHardcore ? "Hardcore " + league : league ;
@@ -167,13 +189,9 @@ private void EnchantJsonHandler(JsonData jdata, LeagueData data)
167189 if ( ! data . EnchantmentsDescriptions . TryGetValue ( description , out Enchantment ench ) ) {
168190 ench = new Enchantment ( description ) ;
169191 data . EnchantmentsDescriptions . Add ( description , ench ) ;
170- MessageBox . Show ( "JSON: The CSV file is missing Enchantment: " + description , "Error" , MessageBoxButtons . OK ) ;
171- ErrorCount ++ ;
192+ EnchantsErrors . Add ( jdata ) ;
172193 }
173194 ench . Load ( jdata ) ;
174- if ( ErrorCount > MaxErrors ) {
175- Environment . Exit ( 1 ) ;
176- }
177195 }
178196
179197 private void UniqueJsonHandler ( JsonData jdata , LeagueData data )
@@ -182,25 +200,17 @@ private void UniqueJsonHandler(JsonData jdata, LeagueData data)
182200 if ( ! data . Uniques . TryGetValue ( baseTy , out UniqueBaseType uniq ) ) {
183201 uniq = new UniqueBaseType ( baseTy ) ;
184202 data . Uniques . Add ( baseTy , uniq ) ;
185- if ( ! data . IsHardcore ) {
186- MessageBox . Show ( "JSON: The CSV file is missing BaseType: " + baseTy , "Error" , MessageBoxButtons . OK ) ;
187- ErrorCount ++ ;
188- }
189- }
190- if ( ! uniq . Add ( jdata ) && ! data . IsHardcore ) {
191- MessageBox . Show ( "JSON: The CSV file is missing: " + jdata . BaseType + " " + jdata . Name , "Error" , MessageBoxButtons . OK ) ;
192- ErrorCount ++ ;
193203 }
194- if ( ErrorCount > MaxErrors ) {
195- Environment . Exit ( 1 ) ;
204+ if ( ! uniq . Add ( jdata ) ) {
205+ UniquesErrors . Add ( jdata ) ;
196206 }
197207 }
198208
199209 private void DivinationJsonHandler ( JsonData jdata , LeagueData data )
200210 {
201211 string name = jdata . Name ;
202- if ( ! data . DivinationCards . TryGetValue ( name , out DivinationCard div ) ) {
203- div = new DivinationCard ( ) ;
212+ if ( ! data . DivinationCards . ContainsKey ( name ) ) {
213+ DivinationCard div = new DivinationCard ( ) ;
204214 data . DivinationCards . Add ( name , div ) ;
205215 }
206216 data . DivinationCards [ name ] . Load ( jdata ) ;
@@ -241,6 +251,10 @@ private void LoadEnchantsCsv()
241251 : Util . ReadWebPage ( repoURL + helmEnchantCsvFile , "" , Encoding . UTF8 ) ;
242252 EnchantCsv [ ] records = engine . ReadString ( csvText ) ;
243253 foreach ( EnchantCsv csvdata in records ) {
254+ if ( string . IsNullOrWhiteSpace ( csvdata . Description ) )
255+ continue ; // skip unknowns
256+ if ( csvdata . Description [ 0 ] == '=' )
257+ csvdata . Description = csvdata . Description . Substring ( 1 ) ;
244258 if ( ! SC . Enchantments . ContainsKey ( csvdata . Description ) ) {
245259 Enchantment scData = new Enchantment ( csvdata . Name ) ;
246260 SC . Enchantments . Add ( csvdata . Name , scData ) ;
@@ -364,8 +378,6 @@ private void GetFilterEnchantsData(IEnumerable<string> lines)
364378 else if ( line . Contains ( "10c+" ) )
365379 value = EnchantmentValue . Chaos10 ;
366380 else {
367- //if (!line.Contains("Other"))
368- // MessageBox.Show("Unexpected Enchant input: " + line, "Error", MessageBoxButtons.OK);
369381 lines = lines . Skip ( 1 ) ;
370382 continue ;
371383 }
0 commit comments