Added ribbon support to Pokédex.

This commit is contained in:
Greg Edwards 2015-03-23 14:48:40 -04:00
parent 022ecdd5bd
commit a53e5f2627
11 changed files with 550 additions and 4 deletions

View File

@ -531,10 +531,88 @@ namespace VeekunImport
Console.WriteLine("Inserted {0} {1}", i.ID, i.Name.ToString());
}
// pkmncf_pokedex_ribbons
if (!File.Exists("ribbons.txt"))
Console.WriteLine("ribbons.txt not found. Not inserting any ribbons.");
else
{
Dictionary<int, RibbonLoading> ribbons = new Dictionary<int, RibbonLoading>();
using (FileStream fs = File.Open("ribbons.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 <= 2) continue;
int id = Convert.ToInt32(fields[0]);
ribbons.Add(id, new RibbonLoading(id, fields[1], fields[2]));
}
}
for (int generation = 3; generation <= GENERATIONS; generation++)
{
String filename = String.Format("ribbon_positions{0}.txt", generation);
if (!File.Exists(filename))
{
Console.WriteLine("File {0} not found, skipped.", filename);
continue;
}
using (FileStream fs = File.Open(filename, FileMode.Open))
{
StreamReader sr = new StreamReader(fs, Encoding.UTF8);
String line;
while ((line = sr.ReadLine()) != null)
{
String[] fields = line.Split('\t');
if (fields.Length <= 1) continue;
int id = Convert.ToInt32(fields[0]);
int position = Convert.ToInt32(fields[1]);
if (!ribbons.ContainsKey(id))
{
Console.WriteLine("Error: Ribbon ID {0} contained in {1} but not in ribbons.txt!", id, filename);
continue;
}
RibbonLoading r = ribbons[id];
switch (generation)
{
case 3:
r.Position3 = position;
break;
case 4:
r.Position4 = position;
break;
case 5:
r.Position5 = position;
break;
case 6:
r.Position6 = position;
break;
}
}
}
}
foreach (KeyValuePair<int, RibbonLoading> pair in ribbons)
{
RibbonLoading r = pair.Value;
Console.WriteLine("Inserted {0} {1}", r.ID, r.Name);
db.PokedexInsertRibbon(new Ribbon(null, r.ID,
new LocalizedString() { { "EN", r.Name } },
new LocalizedString() { { "EN", r.Description } },
r.Position3, r.Position4, r.Position5, r.Position6,
null, null, null, null
));
}
}
connVeekun.Close();
}
#if DEBUG
Console.ReadKey();
#endif
}
private static String[] LANGS = { "JA", "EN", "FR", "IT", "DE", "ES", "KO" };
@ -573,4 +651,20 @@ namespace VeekunImport
public int? Value3, Value4, Value5, Value6;
public int Price;
}
internal class RibbonLoading
{
public RibbonLoading(int id, String name, String description)
{
ID = id;
Name = name;
Description = description;
Position3 = Position4 = Position5 = Position6 = null;
}
public int ID;
public String Name;
public String Description;
public int? Position3, Position4, Position5, Position6;
}
}

View File

@ -92,6 +92,18 @@
<Content Include="families.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ribbons.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ribbon_positions3.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ribbon_positions5.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ribbon_positions4.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\library\Library.csproj">

View File

@ -0,0 +1,5 @@
3021 15 ;Champion Ribbon
3022 16 ;Winning Ribbon
3023 17 ;Victory Ribbon
3024 18 ;Artist Ribbon
3025 19 ;Effort Ribbon

View File

@ -0,0 +1,80 @@
3001 0 ;Hoenn Cool Ribbon
3002 1 ;Hoenn Cool Ribbon Super
3003 2 ;Hoenn Cool Ribbon Hyper
3004 3 ;Hoenn Cool Ribbon Master
3005 4 ;Hoenn Beauty Ribbon
3006 5 ;Hoenn Beauty Ribbon Super
3007 6 ;Hoenn Beauty Ribbon Hyper
3008 7 ;Hoenn Beauty Ribbon Master
3009 8 ;Hoenn Cute Ribbon
3010 9 ;Hoenn Cute Ribbon Super
3011 10 ;Hoenn Cute Ribbon Hyper
3012 11 ;Hoenn Cute Ribbon Master
3013 12 ;Hoenn Smart Ribbon
3014 13 ;Hoenn Smart Ribbon Super
3015 14 ;Hoenn Smart Ribbon Hyper
3016 15 ;Hoenn Smart Ribbon Master
3017 16 ;Hoenn Tough Ribbon
3018 17 ;Hoenn Tough Ribbon Super
3019 18 ;Hoenn Tough Ribbon Hyper
3020 19 ;Hoenn Tough Ribbon Master
3021 20 ;Champion Ribbon
3022 21 ;Winning Ribbon
3023 22 ;Victory Ribbon
3024 23 ;Artist Ribbon
3025 24 ;Effort Ribbon
3026 25 ;Marine Ribbon
3027 26 ;Land Ribbon
3028 27 ;Sky Ribbon
3029 28 ;Country Ribbon
3030 29 ;National Ribbon
3031 30 ;Earth Ribbon
3032 31 ;World Ribbon
4001 32 ;Sinnoh Champ Ribbon
4002 33 ;Ability Ribbon
4003 34 ;Great Ability Ribbon
4004 35 ;Double Ability Ribbon
4005 36 ;Multi Ability Ribbon
4006 37 ;Pair Ability Ribbon
4007 38 ;World Ability Ribbon
4008 39 ;Alert Ribbon
4009 40 ;Shock Ribbon
4010 41 ;Downcast Ribbon
4011 42 ;Careless Ribbon
4012 43 ;Relax Ribbon
4013 44 ;Snooze Ribbon
4014 45 ;Smile Ribbon
4015 46 ;Gorgeous Ribbon
4016 47 ;Royal Ribbon
4017 48 ;Gorgeous Royal Ribbon
4018 49 ;Footprint Ribbon
4019 50 ;Record Ribbon
4020 51 ;History Ribbon
4021 52 ;Legend Ribbon
4022 53 ;Red Ribbon
4023 54 ;Green Ribbon
4024 55 ;Blue Ribbon
4025 56 ;Festival Ribbon
4026 57 ;Carnival Ribbon
4027 58 ;Classic Ribbon
4028 59 ;Premier Ribbon
4029 64 ;Sinnoh Cool Ribbon
4030 65 ;Sinnoh Cool Ribbon Great
4031 66 ;Sinnoh Cool Ribbon Ultra
4032 67 ;Sinnoh Cool Ribbon Master
4033 68 ;Sinnoh Beauty Ribbon
4034 69 ;Sinnoh Beauty Ribbon Great
4035 70 ;Sinnoh Beauty Ribbon Ultra
4036 71 ;Sinnoh Beauty Ribbon Master
4037 72 ;Sinnoh Cute Ribbon
4038 73 ;Sinnoh Cute Ribbon Great
4039 74 ;Sinnoh Cute Ribbon Ultra
4040 75 ;Sinnoh Cute Ribbon Master
4041 76 ;Sinnoh Smart Ribbon
4042 77 ;Sinnoh Smart Ribbon Great
4043 78 ;Sinnoh Smart Ribbon Ultra
4044 79 ;Sinnoh Smart Ribbon Master
4045 80 ;Sinnoh Tough Ribbon
4046 81 ;Sinnoh Tough Ribbon Great
4047 82 ;Sinnoh Tough Ribbon Ultra
4048 83 ;Sinnoh Tough Ribbon Master

View File

@ -0,0 +1,80 @@
3001 0 ;Hoenn Cool Ribbon
3002 1 ;Hoenn Cool Ribbon Super
3003 2 ;Hoenn Cool Ribbon Hyper
3004 3 ;Hoenn Cool Ribbon Master
3005 4 ;Hoenn Beauty Ribbon
3006 5 ;Hoenn Beauty Ribbon Super
3007 6 ;Hoenn Beauty Ribbon Hyper
3008 7 ;Hoenn Beauty Ribbon Master
3009 8 ;Hoenn Cute Ribbon
3010 9 ;Hoenn Cute Ribbon Super
3011 10 ;Hoenn Cute Ribbon Hyper
3012 11 ;Hoenn Cute Ribbon Master
3013 12 ;Hoenn Smart Ribbon
3014 13 ;Hoenn Smart Ribbon Super
3015 14 ;Hoenn Smart Ribbon Hyper
3016 15 ;Hoenn Smart Ribbon Master
3017 16 ;Hoenn Tough Ribbon
3018 17 ;Hoenn Tough Ribbon Super
3019 18 ;Hoenn Tough Ribbon Hyper
3020 19 ;Hoenn Tough Ribbon Master
3021 20 ;Champion Ribbon
3022 21 ;Winning Ribbon
3023 22 ;Victory Ribbon
3024 23 ;Artist Ribbon
3025 24 ;Effort Ribbon
5001 25 ;Battle Champion Ribbon
5002 26 ;Regional Champion Ribbon
5003 27 ;National Champion Ribbon
3029 28 ;Country Ribbon
3030 29 ;National Ribbon
3031 30 ;Earth Ribbon
3032 31 ;World Ribbon
4001 32 ;Sinnoh Champ Ribbon
4002 33 ;Ability Ribbon
4003 34 ;Great Ability Ribbon
4004 35 ;Double Ability Ribbon
4005 36 ;Multi Ability Ribbon
4006 37 ;Pair Ability Ribbon
4007 38 ;World Ability Ribbon
4008 39 ;Alert Ribbon
4009 40 ;Shock Ribbon
4010 41 ;Downcast Ribbon
4011 42 ;Careless Ribbon
4012 43 ;Relax Ribbon
4013 44 ;Snooze Ribbon
4014 45 ;Smile Ribbon
4015 46 ;Gorgeous Ribbon
4016 47 ;Royal Ribbon
4017 48 ;Gorgeous Royal Ribbon
4018 49 ;Footprint Ribbon
4019 50 ;Record Ribbon
5004 51 ;Event Ribbon
4021 52 ;Legend Ribbon
5005 53 ;World Champion Ribbon
5006 54 ;Birthday Ribbon
5007 55 ;Special Ribbon
5008 56 ;Souvenir Ribbon
5009 57 ;Wishing Ribbon
4027 58 ;Classic Ribbon
4028 59 ;Premier Ribbon
4029 64 ;Sinnoh Cool Ribbon
4030 65 ;Sinnoh Cool Ribbon Great
4031 66 ;Sinnoh Cool Ribbon Ultra
4032 67 ;Sinnoh Cool Ribbon Master
4033 68 ;Sinnoh Beauty Ribbon
4034 69 ;Sinnoh Beauty Ribbon Great
4035 70 ;Sinnoh Beauty Ribbon Ultra
4036 71 ;Sinnoh Beauty Ribbon Master
4037 72 ;Sinnoh Cute Ribbon
4038 73 ;Sinnoh Cute Ribbon Great
4039 74 ;Sinnoh Cute Ribbon Ultra
4040 75 ;Sinnoh Cute Ribbon Master
4041 76 ;Sinnoh Smart Ribbon
4042 77 ;Sinnoh Smart Ribbon Great
4043 78 ;Sinnoh Smart Ribbon Ultra
4044 79 ;Sinnoh Smart Ribbon Master
4045 80 ;Sinnoh Tough Ribbon
4046 81 ;Sinnoh Tough Ribbon Great
4047 82 ;Sinnoh Tough Ribbon Ultra
4048 83 ;Sinnoh Tough Ribbon Master

89
VeekunImport/ribbons.txt Normal file
View File

@ -0,0 +1,89 @@
3001 Cool Ribbon Hoenn Cool Contest Normal Rank winner!
3002 Cool Ribbon Super Hoenn Cool Contest Super Rank winner!
3003 Cool Ribbon Hyper Hoenn Cool Contest Hyper Rank winner!
3004 Cool Ribbon Master Hoenn Cool Contest Master Rank winner!
3005 Beauty Ribbon Hoenn Beauty Contest Normal Rank winner!
3006 Beauty Ribbon Super Hoenn Beauty Contest Super Rank winner!
3007 Beauty Ribbon Hyper Hoenn Beauty Contest Hyper Rank winner!
3008 Beauty Ribbon Master Hoenn Beauty Contest Master Rank winner!
3009 Cute Ribbon Hoenn Cute Contest Normal Rank winner!
3010 Cute Ribbon Super Hoenn Cute Contest Super Rank winner!
3011 Cute Ribbon Hyper Hoenn Cute Contest Hyper Rank winner!
3012 Cute Ribbon Master Hoenn Cute Contest Master Rank winner!
3013 Smart Ribbon Hoenn Smart Contest Normal Rank winner!
3014 Smart Ribbon Super Hoenn Smart Contest Super Rank winner!
3015 Smart Ribbon Hyper Hoenn Smart Contest Hyper Rank winner!
3016 Smart Ribbon Master Hoenn Smart Contest Master Rank winner!
3017 Tough Ribbon Hoenn Tough Contest Normal Rank winner!
3018 Tough Ribbon Super Hoenn Tough Contest Super Rank winner!
3019 Tough Ribbon Hyper Hoenn Tough Contest Hyper Rank winner!
3020 Tough Ribbon Master Hoenn Tough Contest Master Rank winner!
3021 Champion Ribbon A Ribbon awarded for clearing the Pokémon League and entering the Hall of Fame in another region.
3022 Winning Ribbon Ribbon awarded for clearing Hoenn's Battle Tower's Lv. 50 challenge.
3023 Victory Ribbon Ribbon awarded for clearing Hoenn's Battle Tower's Lv. 100 challenge.
3024 Artist Ribbon A Ribbon awarded for being chosen as a super sketch model in the Hoenn Region.
3025 Effort Ribbon A Ribbon awarded for being an exceptionally hard worker.
3026 Marine Ribbon A commemorative Ribbon obtained in a Mystery Zone.
3027 Land Ribbon A commemorative Ribbon obtained in a Mystery Zone.
3028 Sky Ribbon A commemorative Ribbon obtained in a Mystery Zone.
3029 Country Ribbon A Ribbon awarded to a Pokémon League Champion.
3030 National Ribbon A Ribbon awarded for overcoming all difficult challenges.
3031 Earth Ribbon A Ribbon awarded for winning 100 battles in a row.
3032 World Ribbon A Ribbon awarded to a Pokémon League Champion.
4001 Sinnoh Champ Ribbon A Ribbon awarded for beating the Sinnoh Champion and entering the Sinnoh Hall of Fame.
4002 Ability Ribbon A Ribbon awarded for defeating the Tower Tycoon at the Battle Tower.
4003 Great Ability Ribbon A Ribbon awarded for defeating the Tower Tycoon at the Battle Tower.
4004 Double Ability Ribbon A Ribbon awarded for completing the Battle Tower Double challenge.
4005 Multi Ability Ribbon A Ribbon awarded for completing the Battle Tower Multi challenge.
4006 Pair Ability Ribbon A Ribbon awarded for completing the Battle Tower Link Multi challenge.
4007 World Ability Ribbon A Ribbon awarded for completing the Wi-Fi Battle Tower challenge.
4008 Alert Ribbon A Ribbon for recalling an invigorating event that created life energy.
4009 Shock Ribbon A Ribbon for recalling a thrilling event that made life more exciting.
4010 Downcast Ribbon A Ribbon for recalling feelings of sadness that added spice to life.
4011 Careless Ribbon A Ribbon for recalling a careless error that helped steer life decisions.
4012 Relax Ribbon A Ribbon for recalling a refreshing event that added sparkle to life.
4013 Snooze Ribbon A Ribbon for recalling a deep slumber that made life soothing.
4014 Smile Ribbon A Ribbon for recalling that smiles enrich the quality of life.
4015 Gorgeous Ribbon An extraordinarily gorgeous and extravagant Ribbon.
4016 Royal Ribbon An incredibly regal Ribbon with an air of nobility.
4017 Gorgeous Royal Ribbon A gorgeous and regal Ribbon that is the peak of fabulous.
4018 Footprint Ribbon A Ribbon awarded to a Pokémon deemed to have a top-quality footprint.
4019 Record Ribbon A Ribbon awarded for setting an incredible record.
4020 History Ribbon A Ribbon awarded for setting a historical record.
4021 Legend Ribbon A Ribbon awarded for setting a legendary record.
4022 Red Ribbon A commemorative Ribbon obtained in a Mystery Zone.
4023 Green Ribbon A commemorative Ribbon obtained in a Mystery Zone.
4024 Blue Ribbon A commemorative Ribbon obtained in a Mystery Zone.
4025 Festival Ribbon A commemorative Ribbon obtained in a Mystery Zone.
4026 Carnival Ribbon A commemorative Ribbon obtained in a Mystery Zone.
4027 Classic Ribbon A Ribbon that proclaims love for Pokémon.
4028 Premier Ribbon A Ribbon awarded for a special holdiay.
4029 Cool Ribbon Super Contest Cool Category Normal Rank winner!
4030 Cool Ribbon Great Super Contest Cool Category Great Rank winner!
4031 Cool Ribbon Ultra Super Contest Cool Category Ultra Rank winner!
4032 Cool Ribbon Master Super Contest Cool Category Master Rank winner!
4033 Beauty Ribbon Super Contest Beauty Category Normal Rank winner!
4034 Beauty Ribbon Great Super Contest Beauty Category Great Rank winner!
4035 Beauty Ribbon Ultra Super Contest Beauty Category Ultra Rank winner!
4036 Beauty Ribbon Master Super Contest Beauty Category Master Rank winner!
4037 Cute Ribbon Super Contest Cute Category Normal Rank winner!
4038 Cute Ribbon Great Super Contest Cute Category Great Rank winner!
4039 Cute Ribbon Ultra Super Contest Cute Category Ultra Rank winner!
4040 Cute Ribbon Master Super Contest Cute Category Master Rank winner!
4041 Smart Ribbon Super Contest Smart Category Normal Rank winner!
4042 Smart Ribbon Great Super Contest Smart Category Great Rank winner!
4043 Smart Ribbon Ultra Super Contest Smart Category Ultra Rank winner!
4044 Smart Ribbon Master Super Contest Smart Category Master Rank winner!
4045 Tough Ribbon Super Contest Tough Category Normal Rank winner!
4046 Tough Ribbon Great Super Contest Tough Category Great Rank winner!
4047 Tough Ribbon Ultra Super Contest Tough Category Ultra Rank winner!
4048 Tough Ribbon Master Super Contest Tough Category Master Rank winner!
5001 Battle Champion Ribbon A Ribbon awarded to a Battle Competition Champion.
5002 Regional Champion Ribbon A Ribbon awarded to a Regional Champion in the Pokémon World Championships.
5003 National Champion Ribbon A Ribbon awarded to a National Champion in the Pokémon World Championships.
5004 Event Ribbon A Ribbon awarded for participating in a special Pokémon event.
5005 World Champion Ribbon A Ribbon awarded to a World Champion in the Pokémon World Championships.
5006 Birthday Ribbon A Ribbon that commemorates a birthday.
5007 Special Ribbon A special Ribbon for a special day.
5008 Souvenir Ribbon A Ribbon for cherishing a special memory.
5009 Wishing Ribbon A Ribbon said to make your wish come true.

View File

@ -2627,17 +2627,28 @@ namespace PkmnFoundations.Data
#region Pokedex creation
private const String INSERT_COLUMNS = "Name_JA, Name_EN, Name_FR, Name_IT, Name_DE, Name_ES, Name_KO";
private const String INSERT_VALUES = "@name_ja, @name_en, @name_fr, @name_it, @name_de, @name_es, @name_ko";
private static String[] m_query_langs = new String[] { "JA", "EN", "FR", "IT", "DE", "ES", "KO" };
private void CreateLocalizedStringQueryPieces(LocalizedString s, List<MySqlParameter> insertParams)
private static void CreateLocalizedStringQueryPieces(LocalizedString s,
List<MySqlParameter> insertParams, String prefix = "@name_")
{
String[] langs = new String[] { "JA", "EN", "FR", "IT", "DE", "ES", "KO" };
foreach (String lang in langs)
foreach (String lang in m_query_langs)
{
MySqlParameter param = new MySqlParameter("@name_" + lang.ToLowerInvariant(), s.ContainsKey(lang) ? s[lang] : (object)DBNull.Value);
MySqlParameter param = new MySqlParameter(prefix + lang.ToLowerInvariant(), s.ContainsKey(lang) ? s[lang] : (object)DBNull.Value);
insertParams.Add(param);
}
}
private static String CreateLocalizedInsertColumns(String prefix)
{
return String.Join(", ", m_query_langs.Select(lang => prefix + lang).ToArray());
}
private static String CreateLocalizedInsertValues(String prefix)
{
return String.Join(", ", m_query_langs.Select(lang => prefix + lang.ToLowerInvariant()).ToArray());
}
public override void PokedexInsertSpecies(Species s)
{
using (MySqlConnection db = CreateConnection())
@ -2844,6 +2855,35 @@ namespace PkmnFoundations.Data
}
}
public void PokedexInsertRibbon(MySqlTransaction tran, Ribbon r)
{
List<MySqlParameter> insertParams = new List<MySqlParameter>();
insertParams.Add(new MySqlParameter("@id", r.ID));
insertParams.Add(new MySqlParameter("@position3", r.Position3));
insertParams.Add(new MySqlParameter("@position4", r.Position4));
insertParams.Add(new MySqlParameter("@position5", r.Position5));
insertParams.Add(new MySqlParameter("@position6", r.Position6));
insertParams.Add(new MySqlParameter("@value3", r.Value3));
insertParams.Add(new MySqlParameter("@value4", r.Value4));
insertParams.Add(new MySqlParameter("@value5", r.Value5));
insertParams.Add(new MySqlParameter("@value6", r.Value6));
CreateLocalizedStringQueryPieces(r.Name, insertParams);
CreateLocalizedStringQueryPieces(r.Name, insertParams, "@description_");
tran.ExecuteNonQuery("INSERT INTO pkmncf_pokedex_ribbons (ID, " +
"Position3, Position4, Position5, Position6, Value3, Value4, " +
"Value5, Value6, " + INSERT_COLUMNS + ", " +
CreateLocalizedInsertColumns("Description_") + ") VALUES (@id, " +
"@position3, @position4, @position5, @position6, @value3, " +
"@value4, @value5, @value6, " + INSERT_VALUES + ", " +
CreateLocalizedInsertValues("@description_") + ")", insertParams.ToArray());
}
public override void PokedexInsertRibbon(Ribbon r)
{
WithTransaction(tran => PokedexInsertRibbon(tran, r));
}
#endregion
#region Pokedex retrieval
@ -2999,6 +3039,23 @@ namespace PkmnFoundations.Data
}
}
}
public List<Ribbon> PokedexGetAllRibbons(MySqlTransaction tran, Pokedex.Pokedex pokedex)
{
using (MySqlDataReader reader = (MySqlDataReader)tran.ExecuteReader("SELECT " +
"ID, Position3, Position4, Position5, Position6, Value3, " +
"Value4, Value5, Value6, " + INSERT_COLUMNS + ", " +
CreateLocalizedInsertColumns("Description_") + " FROM pkmncf_pokedex_ribbons"))
{
return ReaderToList(reader, pokedex, () => new Ribbon(pokedex, reader));
}
}
public override List<Ribbon> PokedexGetAllRibbons(Pokedex.Pokedex pokedex)
{
return WithTransaction(tran => PokedexGetAllRibbons(tran, pokedex));
}
#endregion
}

View File

@ -171,6 +171,7 @@ namespace PkmnFoundations.Data
public abstract void PokedexInsertItem(Item i);
public abstract void PokedexInsertMove(Move m);
public abstract void PokedexInsertAbility(Ability a);
public abstract void PokedexInsertRibbon(Ribbon r);
#endregion
@ -185,6 +186,7 @@ namespace PkmnFoundations.Data
public abstract List<Item> PokedexGetAllItems(Pokedex.Pokedex pokedex);
public abstract List<Move> PokedexGetAllMoves(Pokedex.Pokedex pokedex);
public abstract List<Ability> PokedexGetAllAbilities(Pokedex.Pokedex pokedex);
public abstract List<Ribbon> PokedexGetAllRibbons(Pokedex.Pokedex pokedex);
#endregion
}
}

View File

@ -65,6 +65,7 @@
<Compile Include="Pokedex\Move.cs" />
<Compile Include="Pokedex\Pokedex.cs" />
<Compile Include="Pokedex\PokedexRecordBase.cs" />
<Compile Include="Pokedex\Ribbon.cs" />
<Compile Include="Pokedex\Species.cs" />
<Compile Include="Pokedex\Family.cs" />
<Compile Include="Pokedex\Form.cs" />

View File

@ -28,6 +28,7 @@ namespace PkmnFoundations.Pokedex
m_moves = db.PokedexGetAllMoves(this).ToDictionary(m => m.ID, m => m);
m_types = db.PokedexGetAllTypes(this).ToDictionary(t => t.ID, t => t);
m_abilities = db.PokedexGetAllAbilities(this).ToDictionary(a => a.Value, a => a);
m_ribbons = db.PokedexGetAllRibbons(this).ToDictionary(r => r.ID, r => r);
List<FormStats> form_stats = db.PokedexGetAllFormStats(this);
form_stats.Sort(delegate(FormStats f, FormStats other)
@ -86,6 +87,26 @@ namespace PkmnFoundations.Pokedex
if (i.Value5 != null) items5.Add((int)i.Value5, i);
if (i.Value6 != null) items6.Add((int)i.Value6, i);
}
m_ribbon_positions_generations = new Dictionary<Generations, Dictionary<int, Ribbon>>();
AddGeneration(m_ribbon_positions_generations, m_ribbons, Generations.Generation3, r => r.Position3);
AddGeneration(m_ribbon_positions_generations, m_ribbons, Generations.Generation4, r => r.Position4);
AddGeneration(m_ribbon_positions_generations, m_ribbons, Generations.Generation5, r => r.Position5);
AddGeneration(m_ribbon_positions_generations, m_ribbons, Generations.Generation6, r => r.Position6);
m_ribbon_values_generations = new Dictionary<Generations, Dictionary<int, Ribbon>>();
AddGeneration(m_ribbon_values_generations, m_ribbons, Generations.Generation3, r => r.Value3);
AddGeneration(m_ribbon_values_generations, m_ribbons, Generations.Generation4, r => r.Value4);
AddGeneration(m_ribbon_values_generations, m_ribbons, Generations.Generation5, r => r.Value5);
AddGeneration(m_ribbon_values_generations, m_ribbons, Generations.Generation6, r => r.Value6);
}
private void AddGeneration<TKey, TValue>(Dictionary<Generations, Dictionary<TKey, TValue>> dest, Dictionary<TKey, TValue> src, Generations generation, Func<TValue, TKey ?> keyGetter)
where TKey : struct
{
dest.Add(generation,
src.Where(pair => keyGetter(pair.Value) != null)
.ToDictionary(pair => (TKey)keyGetter(pair.Value), pair => pair.Value));
}
private void PrefetchRelations()
@ -107,6 +128,8 @@ namespace PkmnFoundations.Pokedex
k.Value.PrefetchRelations();
foreach (var k in m_abilities)
k.Value.PrefetchRelations();
foreach (var k in m_ribbons)
k.Value.PrefetchRelations();
foreach (var k in m_form_stats)
{
@ -126,8 +149,11 @@ namespace PkmnFoundations.Pokedex
private Dictionary<int, Move> m_moves;
private Dictionary<int, PkmnFoundations.Pokedex.Type> m_types;
private Dictionary<int, Ability> m_abilities;
private Dictionary<int, Ribbon> m_ribbons;
private Dictionary<Generations, Dictionary<int, Item>> m_items_generations;
private Dictionary<Generations, Dictionary<int, Ribbon>> m_ribbon_positions_generations;
private Dictionary<Generations, Dictionary<int, Ribbon>> m_ribbon_values_generations;
// todo: add ReadOnlyIndexer1d class, replace these methods with them
public Species Species(int national_dex)

100
library/Pokedex/Ribbon.cs Normal file
View File

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PkmnFoundations.Structures;
using PkmnFoundations.Support;
namespace PkmnFoundations.Pokedex
{
public class Ribbon : PokedexRecordBase
{
public Ribbon(Pokedex pokedex, int id, LocalizedString name,
LocalizedString description,
int ? position3, int ? position4, int ? position5, int ? position6,
int ? value3, int ? value4, int ? value5, int ? value6)
: base(pokedex)
{
ID = id;
Name = name;
Description = description;
Position3 = position3;
Position4 = position4;
Position5 = position5;
Position6 = position6;
Value3 = value3;
Value4 = value4;
Value5 = value5;
Value6 = value6;
}
public Ribbon(Pokedex pokedex, IDataReader reader) :
this(pokedex, Convert.ToInt32(reader["id"]),
LocalizedStringFromReader(reader, "Name_"),
LocalizedStringFromReader(reader, "Description_"),
reader["Position3"] is DBNull ? null : (int?)Convert.ToInt32(reader["Position3"]),
reader["Position4"] is DBNull ? null : (int?)Convert.ToInt32(reader["Position4"]),
reader["Position5"] is DBNull ? null : (int?)Convert.ToInt32(reader["Position5"]),
reader["Position6"] is DBNull ? null : (int?)Convert.ToInt32(reader["Position6"]),
reader["Value3"] is DBNull ? null : (int?)Convert.ToInt32(reader["Value3"]),
reader["Value4"] is DBNull ? null : (int?)Convert.ToInt32(reader["Value4"]),
reader["Value5"] is DBNull ? null : (int?)Convert.ToInt32(reader["Value5"]),
reader["Value6"] is DBNull ? null : (int?)Convert.ToInt32(reader["Value6"])
)
{
}
public int ID { get; private set; }
public LocalizedString Name { get; private set; }
public LocalizedString Description { get; private set; }
public int? Position3 { get; private set; }
public int? Position4 { get; private set; }
public int? Position5 { get; private set; }
public int? Position6 { get; private set; }
public int? Value3 { get; private set; }
public int? Value4 { get; private set; }
public int? Value5 { get; private set; }
public int? Value6 { get; private set; }
public int? Position(Generations generation)
{
switch (generation)
{
case Generations.Generation1:
case Generations.Generation2:
throw new NotSupportedException();
case Generations.Generation3:
return Position3;
case Generations.Generation4:
return Position4;
case Generations.Generation5:
return Position5;
case Generations.Generation6:
default:
return Position6;
}
}
public int? Value(Generations generation)
{
switch (generation)
{
case Generations.Generation1:
case Generations.Generation2:
throw new NotSupportedException();
case Generations.Generation3:
return Value3;
case Generations.Generation4:
return Value4;
case Generations.Generation5:
return Value5;
case Generations.Generation6:
default:
return Value6;
}
}
}
}