From 61bda8e871e9303b75c3a9f05af950180a074e79 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Mon, 9 Feb 2015 10:56:25 -0500 Subject: [PATCH] Plumbing to lookup the forms of a given species --- library/Pokedex/Pokedex.cs | 14 ++++++++++++++ library/Pokedex/PokedexRecordBase.cs | 1 + library/Pokedex/Species.cs | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/library/Pokedex/Pokedex.cs b/library/Pokedex/Pokedex.cs index 09090986..49337d4a 100644 --- a/library/Pokedex/Pokedex.cs +++ b/library/Pokedex/Pokedex.cs @@ -56,6 +56,13 @@ namespace PkmnFoundations.Pokedex private void BuildAdditionalIndexes() { + m_forms_by_value = new Dictionary>(); + foreach (var pair in m_species) + m_forms_by_value.Add(pair.Key, new Dictionary()); + + foreach (var pair in m_forms) + m_forms_by_value[pair.Value.SpeciesID].Add(pair.Value.Value, pair.Value); + Dictionary items3 = new Dictionary(); Dictionary items4 = new Dictionary(); Dictionary items5 = new Dictionary(); @@ -106,6 +113,7 @@ namespace PkmnFoundations.Pokedex private Dictionary m_species; private Dictionary m_families; private Dictionary m_forms; + private Dictionary> m_forms_by_value; private Dictionary> m_form_stats; //private Dictionary m_evolutions; @@ -116,6 +124,7 @@ namespace PkmnFoundations.Pokedex private Dictionary> m_items_generations; + // todo: add ReadOnlyIndexer1d class, replace these methods with them public Species Species(int national_dex) { return m_species[national_dex]; @@ -131,6 +140,11 @@ namespace PkmnFoundations.Pokedex return m_forms[id]; } + internal Dictionary FormsByValue(int national_dex) + { + return m_forms_by_value[national_dex]; + } + public SortedDictionary FormStats(int form_id) { return m_form_stats[form_id]; diff --git a/library/Pokedex/PokedexRecordBase.cs b/library/Pokedex/PokedexRecordBase.cs index 36ead274..1e39dbbc 100644 --- a/library/Pokedex/PokedexRecordBase.cs +++ b/library/Pokedex/PokedexRecordBase.cs @@ -11,6 +11,7 @@ namespace PkmnFoundations.Pokedex { internal PokedexRecordBase(Pokedex pokedex) { + if (pokedex == null) throw new ArgumentNullException("pokedex"); m_pokedex = pokedex; m_lazy_pairs = new List>(); } diff --git a/library/Pokedex/Species.cs b/library/Pokedex/Species.cs index 67b01082..9022e52c 100644 --- a/library/Pokedex/Species.cs +++ b/library/Pokedex/Species.cs @@ -47,6 +47,12 @@ namespace PkmnFoundations.Pokedex { } + internal override void PrefetchRelations() + { + base.PrefetchRelations(); + m_forms = m_pokedex.FormsByValue(NationalDex); + } + // todo: Implement IEquitable and compare against NationalDex // Same goes for all these pokedex classes. @@ -69,5 +75,13 @@ namespace PkmnFoundations.Pokedex { get { return m_family_pair.Value; } } + + private Dictionary m_forms; + public Form Forms(byte value) + { + if (m_forms == null) + m_forms = m_pokedex.FormsByValue(NationalDex); + return m_forms[value]; + } } }