From a7437dd6916292de01fc5d383138747eac7c7cee Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Tue, 10 Feb 2015 13:36:29 -0500 Subject: [PATCH] Added logic to override (incorrect) form values from veekun. --- VeekunImport/Program.cs | 44 ++++++++++++++++++++- VeekunImport/VeekunImport.csproj | 21 ++++++----- VeekunImport/form_values.txt | 65 ++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 VeekunImport/form_values.txt diff --git a/VeekunImport/Program.cs b/VeekunImport/Program.cs index 6b5e69a6..1958502b 100644 --- a/VeekunImport/Program.cs +++ b/VeekunImport/Program.cs @@ -68,8 +68,7 @@ namespace VeekunImport { lineNumber++; String[] fields = line.Split('\t'); - // todo: allow and reject blank lines at the end. - if (fields.Length == 0) throw new Exception("families_map.txt has a blank line."); + if (fields.Length == 0) continue; int[] fieldsInt = fields.Select(s => Convert.ToInt32(s)).ToArray(); familyList.Add(fieldsInt); foreach (int x in fieldsInt) @@ -189,6 +188,45 @@ namespace VeekunImport rdPokemon.Close(); // pkmncf_pokedex_pokemon_forms + /* + * List overrideFamilies = new List(); + using (FileStream fs = File.Open("families.txt", FileMode.Open)) + { + StreamReader sr = new StreamReader(fs, Encoding.UTF8); + String line; + while ((line = sr.ReadLine()) != null) + { + String[] fields = line.Split('\t'); + overrideFamilies.Add(new Family(null, + Convert.ToInt32(fields[0]), + Convert.ToInt32(fields[1]), + Convert.ToInt32(fields[2]), + Convert.ToInt32(fields[3]), + Convert.ToInt32(fields[4]), + Convert.ToInt32(fields[5]), + Convert.ToByte(fields[6]) + )); + } + } + + */ + + // xxx: DRY these file parsers up by adding a helper that takes + // a filename and a lambda of what to run for each line in the document. + Dictionary formValueMap = new Dictionary(); + using (FileStream fs = File.Open("form_values.txt", FileMode.Open)) + { + StreamReader sr = new StreamReader(fs, Encoding.UTF8); + String line; + while ((line = sr.ReadLine()) != null) + { + String[] fields = line.Split('\t'); + if (fields.Length == 0) continue; + if (fields.Length != 3) throw new Exception("form_values.txt has a line with unexpected number of tabs."); + formValueMap.Add(Convert.ToInt32(fields[1]), Convert.ToByte(fields[2])); + } + } + SQLiteDataReader rdForms = (SQLiteDataReader)connVeekun.ExecuteReader("SELECT id, " + "(SELECT species_id FROM pokemon WHERE id = pokemon_id) AS NationalDex, " + "form_order - 1 AS FormValue, " + @@ -215,6 +253,8 @@ namespace VeekunImport int weight = Convert.ToInt32(rdForms["weight"]); int experience = Convert.ToInt32(rdForms["experience"]); + if (formValueMap.ContainsKey(id)) FormValue = formValueMap[id]; + Form f = new Form(null, id, NationalDex, FormValue, GetLocalizedString(rdForms, "name_"), diff --git a/VeekunImport/VeekunImport.csproj b/VeekunImport/VeekunImport.csproj index 18cc1e20..00ac9635 100644 --- a/VeekunImport/VeekunImport.csproj +++ b/VeekunImport/VeekunImport.csproj @@ -54,31 +54,34 @@ Always - PreserveNewest + Always - PreserveNewest + Always - PreserveNewest + Always - PreserveNewest + Always - PreserveNewest + Always - PreserveNewest + Always + + + Always - PreserveNewest + Always - PreserveNewest + Always - PreserveNewest + Always Always diff --git a/VeekunImport/form_values.txt b/VeekunImport/form_values.txt new file mode 100644 index 00000000..bb27b026 --- /dev/null +++ b/VeekunImport/form_values.txt @@ -0,0 +1,65 @@ +201 201 0 +201 10001 1 +201 10002 2 +201 10003 3 +201 10004 4 +201 10005 5 +201 10006 6 +201 10007 7 +201 10008 8 +201 10009 9 +201 10010 10 +201 10011 11 +201 10012 12 +201 10013 13 +201 10014 14 +201 10015 15 +201 10016 16 +201 10017 17 +201 10018 18 +201 10019 19 +201 10020 20 +201 10021 21 +201 10022 22 +201 10023 23 +201 10024 24 +201 10025 25 +201 10026 26 +201 10027 27 +493 493 0 +493 10045 1 +493 10047 2 +493 10052 3 +493 10050 4 +493 10054 5 +493 10041 6 +493 10048 7 +493 10055 8 +493 10046 9 +493 10056 10 +493 10049 11 +493 10044 12 +493 10053 13 +493 10051 14 +493 10043 15 +493 10042 16 +493 10057 31 +493 10085 17 +646 646 0 +646 10083 1 +646 10082 2 +649 649 0 +649 10075 1 +649 10076 2 +649 10077 3 +649 10078 4 +676 676 0 +676 10115 1 +676 10116 2 +676 10117 3 +676 10118 4 +676 10119 5 +676 10120 6 +676 10121 7 +676 10122 8 +676 10123 9 \ No newline at end of file