Plumbing to lookup the forms of a given species

This commit is contained in:
Greg Edwards
2015-02-09 10:56:25 -05:00
parent 2ea9d7f883
commit 61bda8e871
3 changed files with 29 additions and 0 deletions

View File

@@ -56,6 +56,13 @@ namespace PkmnFoundations.Pokedex
private void BuildAdditionalIndexes()
{
m_forms_by_value = new Dictionary<int, Dictionary<byte, Form>>();
foreach (var pair in m_species)
m_forms_by_value.Add(pair.Key, new Dictionary<byte, Form>());
foreach (var pair in m_forms)
m_forms_by_value[pair.Value.SpeciesID].Add(pair.Value.Value, pair.Value);
Dictionary<int, Item> items3 = new Dictionary<int,Item>();
Dictionary<int, Item> items4 = new Dictionary<int,Item>();
Dictionary<int, Item> items5 = new Dictionary<int,Item>();
@@ -106,6 +113,7 @@ namespace PkmnFoundations.Pokedex
private Dictionary<int, Species> m_species;
private Dictionary<int, Family> m_families;
private Dictionary<int, Form> m_forms;
private Dictionary<int, Dictionary<byte, Form>> m_forms_by_value;
private Dictionary<int, SortedDictionary<Generations, FormStats>> m_form_stats;
//private Dictionary<int, Evolution> m_evolutions;
@@ -116,6 +124,7 @@ namespace PkmnFoundations.Pokedex
private Dictionary<Generations, Dictionary<int, Item>> 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<byte, Form> FormsByValue(int national_dex)
{
return m_forms_by_value[national_dex];
}
public SortedDictionary<Generations, FormStats> FormStats(int form_id)
{
return m_form_stats[form_id];

View File

@@ -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<ILazyKeyValuePair<int, object>>();
}

View File

@@ -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<byte, Form> m_forms;
public Form Forms(byte value)
{
if (m_forms == null)
m_forms = m_pokedex.FormsByValue(NationalDex);
return m_forms[value];
}
}
}