From bf5c3a85bfbbe77a0ed89a425b6f8149f70bd492 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Fri, 8 May 2015 20:32:37 -0400 Subject: [PATCH] Hide gen6 pokemon from GTS search. --- library/Pokedex/Pokedex.cs | 21 +++++++++++++++++++++ web/controls/PokemonPicker.ascx.cs | 15 +++++++++++++++ web/controls/PokemonSource.ashx.cs | 8 +++++++- web/gts/Default.aspx | 3 ++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/library/Pokedex/Pokedex.cs b/library/Pokedex/Pokedex.cs index 917805a2..a4ad720f 100644 --- a/library/Pokedex/Pokedex.cs +++ b/library/Pokedex/Pokedex.cs @@ -258,5 +258,26 @@ namespace PkmnFoundations.Pokedex { return m_location_values_generations[generation]; } + + public static int SpeciesAtGeneration(Generations generation) + { + switch (generation) + { + case Generations.Generation1: + return 151; + case Generations.Generation2: + return 251; + case Generations.Generation3: + return 386; + case Generations.Generation4: + return 493; + case Generations.Generation5: + return 649; + case Generations.Generation6: + return 721; + default: + throw new NotSupportedException(); + } + } } } diff --git a/web/controls/PokemonPicker.ascx.cs b/web/controls/PokemonPicker.ascx.cs index 329cd2c8..e27c19a2 100644 --- a/web/controls/PokemonPicker.ascx.cs +++ b/web/controls/PokemonPicker.ascx.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using PkmnFoundations.Structures; namespace PkmnFoundations.Web.controls { @@ -27,5 +28,19 @@ namespace PkmnFoundations.Web.controls theLookup.Value = value.ToString(); } } + + private Generations m_max_generation; + public Generations MaxGeneration + { + get + { + return m_max_generation; + } + set + { + m_max_generation = value; + theLookup.SourceUrl = "~/controls/PokemonSource.ashx?limit=" + Pokedex.Pokedex.SpeciesAtGeneration(value).ToString(); + } + } } } \ No newline at end of file diff --git a/web/controls/PokemonSource.ashx.cs b/web/controls/PokemonSource.ashx.cs index 75e1f646..c550da4d 100644 --- a/web/controls/PokemonSource.ashx.cs +++ b/web/controls/PokemonSource.ashx.cs @@ -20,12 +20,18 @@ namespace PkmnFoundations.Web.controls query = query.ToLowerInvariant(); int natDex = 0; Int32.TryParse(query, out natDex); + int limit = 0; + if (context.Request.QueryString["limit"] != null) + { + limit = Convert.ToInt32(context.Request.QueryString["limit"]); + if (natDex > limit) return null; + } Func, bool> filter; if (natDex > 0) filter = pair => pair.Key == natDex; else - filter = pair => pair.Value.Name[iso].ToLowerInvariant().Contains(query); + filter = pair => pair.Key <= limit && pair.Value.Name[iso].ToLowerInvariant().Contains(query); IEnumerable data; data = pokedex.Species.Where(filter).OrderBy(pair => pair.Key).Take(rows).Select(pair => pair.Value); diff --git a/web/gts/Default.aspx b/web/gts/Default.aspx index 4d1ce6fc..eeed15ba 100644 --- a/web/gts/Default.aspx +++ b/web/gts/Default.aspx @@ -26,7 +26,8 @@ Species - + <%-- todo: limit pokemon to gen4 when gen4 is checked --%> + Version