-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pokedex.cs
56 lines (49 loc) · 1.46 KB
/
Pokedex.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
namespace PokedexNET
{
public class Pokedex
{
internal Assembly Assembly { get; }
public Pokedex()
{
Assembly = typeof(Pokedex).GetTypeInfo().Assembly;
Load();
}
internal void Load()
{
using (var reader = new StreamReader(Assembly.GetManifestResourceStream("PokedexNET.data.pokemon.json")))
{
Pokemons = JsonConvert.DeserializeObject<List<Pokemon>>(reader.ReadToEnd());
}
}
public List<Pokemon> Pokemons { get; set; }
public Pokemon GetPokemon(int number)
{
return Pokemons.FirstOrDefault(x => x.Number == number.ToString("D3"));
}
public PokemonInfo GetPokemonInfo(Pokemon pokemon)
{
return GetPokemonInfo(pokemon.Slug);
}
public PokemonInfo GetPokemonInfo(string slug)
{
try
{
using (var reader = new StreamReader(Assembly.GetManifestResourceStream($"PokedexNET.data.pokemon.{slug}.json")))
{
return JsonConvert.DeserializeObject<PokemonInfo>(reader.ReadToEnd());
}
}
catch (Exception)
{
return null;
}
}
}
}