From 8eeb0dee35acba42383c951c8b6288a76829dae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Thu, 3 Mar 2022 13:30:59 +0100 Subject: [PATCH] Forms visible in Flashdex --- README.md | 3 +- about.html | 2 +- flashdex.html | 2 +- flashdex.js | 236 +++++++++++++++++++++++++++++++++++++------------- index.html | 2 +- pokemon | 2 +- pokemon.json | 134 ++++++++++++++-------------- style.css | 23 ++++- 8 files changed, 269 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index 84dd9d4..56f98ab 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,8 @@ Now that there are now more than 900 of them, and it's as useful as ever! The we ### Planned updates -- Multiple forms visible in Flashdex +- Make answer choices closer by type - Custom input answers for harder difficulty -- Pokémon type support - Type weakness calculator ### Scripts diff --git a/about.html b/about.html index 7beb28d..b8f4c3c 100644 --- a/about.html +++ b/about.html @@ -79,7 +79,7 @@ \ No newline at end of file diff --git a/flashdex.html b/flashdex.html index bb8a9f8..6672d95 100644 --- a/flashdex.html +++ b/flashdex.html @@ -85,7 +85,7 @@ diff --git a/flashdex.js b/flashdex.js index 838127d..9135bbe 100644 --- a/flashdex.js +++ b/flashdex.js @@ -1,5 +1,5 @@ -$(document).ready(function() { - +$(document).ready(function() +{ /****** Generations ******/ var G1 = [1, 151]; var G2 = [152, 251]; @@ -14,19 +14,23 @@ $(document).ready(function() { var GIGA = [959, 990]; var REG = [991, 1043]; + var EXCEPTION = 990; // urshifu g-max + + /************ GAME *************/ /*******************************/ // loading json file - var json = $.getJSON('pokemon.json', function(pk) { + $.getJSON('pokemon.json', function(pk) + { $('article #container #game #loading').hide(); var pklist = pk; - $('article #container #flashdex_config .all').click(function() { - - if ($(this).hasClass("unselected")) { - + $('article #container #flashdex_config .all').click(function() + { + if ($(this).hasClass("unselected")) + { for (i = 1; i < 10; ++i) $('input[name="'+i+'g"]').prop('checked', true); $('input[name="mega"]').prop('checked', true); @@ -34,7 +38,9 @@ $(document).ready(function() { $('input[name="gigantamax"]').prop('checked', true); $(this).removeClass("unselected").addClass("selected"); $(this).text("Unselect all"); - } else { + } + else + { for (i = 1; i < 10; ++i) $('input[name="'+i+'g"]').prop('checked', false); $('input[name="mega"]').prop('checked', false); @@ -46,8 +52,8 @@ $(document).ready(function() { }) // start the game when clicking on start game - $('article #container .button input.start').click(function() { - + $('article #container .button input.start').click(function() + { $('article #container #game #loading').show(); $('article #container #game #flashdex').empty(); @@ -59,7 +65,8 @@ $(document).ready(function() { $('article #container #game #flashdex').hide(); - function getFormText(pkmn) { + function getFormText(pkmn) + { if (pkmn["origin"] == "Kanto") return '' else if (pkmn["origin"] == "Johto") @@ -87,7 +94,10 @@ $(document).ready(function() { return ''; } - function getFormattedNumber(num) { + function getFormattedNumber(num) + { + if (num > 905 && num < 909) + return "???"; if (num[0] == 'M' || num[0] == 'R' || num[0] == 'G') return num.substring(1, num.length); return num; @@ -101,44 +111,179 @@ $(document).ready(function() { return str; } - for (i in pokemon_generation_list) { + function getFormattedTypes(num, index) + { + str = ''+num["type"+index][0]+''; + if (num["type"+index][1]) + str += ''+num["type"+index][1]+''; + return str; + } + function getFormattedSpriteButton(num) + { + if (num["sprite"] || num["origin"] == "Kanto") + return ''; + return ''; + } + + for (i in pokemon_generation_list) + { $('article #container #game #flashdex').append( '
' - + getFormattedTypes(pklist.mn[pokemon_generation_list[i]]) + + '' + getFormattedTypes(pklist.mn[pokemon_generation_list[i]], '') + '' + + getFormattedSpriteButton(pklist.mn[pokemon_generation_list[i]], '') + getFormText(pklist.mn[pokemon_generation_list[i]]) // either gigantamax or mega-evolution - + '' + + '' + '' + '' + '#' + getFormattedNumber(pklist.mn[[pokemon_generation_list[i]]]["num"]) + ' ' + pklist.mn[[pokemon_generation_list[i]]][lang] + '' + '
' ); } - $('article #container #game #flashdex').waitForImages(function() { + $('article #container #game #flashdex').waitForImages(function() + { $(this).show(); $('article #container #game #loading').hide(); }); - function generations() { + function handleArtworks(origin, left) + { + function handleDefault() + { + var form = url.split('-')[1]; + if (left) + { + if (form > 0) + form--; + else + form = pklist.mn[pokemon-1]["sprite"] - 1; + } + else + { + if (form < pklist.mn[pokemon-1]["sprite"] - 1) + form++; + else + form = 0; + } + + var newUrl = 'pokemon/' + pokemon + '-' + form + '.png'; + origin.parent().parent().find("img").attr('src', newUrl); + handleChangeType(form, pokemon-1) + } + + function handleKanto() + { + var KantoForm = ''; + for (var i = 0; i < originalUrl.length; i++) + { + if (originalUrl[i].match(/[A-Z]/)) + KantoForm += originalUrl[i]; + } + + if (left) + { + if (KantoForm == "RG") + KantoForm = "RB" + else if (KantoForm == "RB") + KantoForm = ""; + else + KantoForm = "RG"; + } + else + { + if (KantoForm == "RB") + KantoForm = "RG" + else if (KantoForm == "RG") + KantoForm = ""; + else + KantoForm = "RB"; + } + + var newUrl = 'pokemon/' + pokemon + KantoForm + '.png'; + origin.parent().parent().find("img").attr('src', newUrl); + } + + function handleException() + { + var form = url.split('-')[1]; + if (form == 0) + form = 1; + else + form = 0; + + var newUrl = 'pokemon/' + pokemonUrl + '-' + form + '.png'; + origin.parent().parent().find("img").attr('src', newUrl); + handleChangeType(form, EXCEPTION-1) + } + + function handleChangeType(form, num) + { + if (form != 0) + { + if (pklist.mn[num]["type"+form]) + origin.parent().parent().find(".types").empty().append(getFormattedTypes(pklist.mn[num], form)); + } + else + origin.parent().parent().find(".types").empty().append(getFormattedTypes(pklist.mn[num], '')); + } + + var url = origin.parent().parent().find("img").attr('src'); + var originalUrl = url; + url = url.split('/')[1]; + url = url.split('.')[0]; + + var pokemonUrl = url.split('-')[0]; + var pokemon = ''; + for (var i = 0; i < pokemonUrl.length; i++) + { + if (pokemonUrl[i].match(/[0-9]/)) + pokemon += pokemonUrl[i]; + } + + if (pokemonUrl == "G892") + handleException(); + else if (pklist.mn[pokemon-1]["origin"] == "Kanto" && !pklist.mn[pokemon-1]["sprite"]) + handleKanto(); + else if (pklist.mn[pokemon-1]["sprite"]) + handleDefault(); + } + + $('.left-arrow').click(function(e) + { + handleArtworks($(this), true); + }); + + $('.right-arrow').click(function(e) + { + handleArtworks($(this), false); + }); + + function generations() + { // create the list of the different generations - function createGenerationList(name) { + function createGenerationList(name) + { if ( $('article input[name="'+name+'"]').is(':checked') ) gen_list[gen_list.length] = name; } // create the list of all possible pokemons for selected options - function generatePokemonList() { - - function evaluateByGeneration(index, name, variable) { - if (gen_list[index] == name) { + function generatePokemonList() + { + function evaluateByGeneration(index, name, variable) + { + if (gen_list[index] == name) + { for (j = (variable[0] - 1); j <= (variable[1] - 1); j++) pokemon_generation_list[pokemon_generation_list.length] = j; } } - if (gen_list.length > 0) { - for (i in gen_list) { + if (gen_list.length > 0) + { + for (i in gen_list) + { evaluateByGeneration(i, "1g", G1); evaluateByGeneration(i, "2g", G2); evaluateByGeneration(i, "3g", G3); evaluateByGeneration(i, "4g", G4); evaluateByGeneration(i, "5g", G5); evaluateByGeneration(i, "6g", G6); evaluateByGeneration(i, "7g", G7); evaluateByGeneration(i, "8g", G8); evaluateByGeneration(i, "9g", G9); @@ -156,44 +301,15 @@ $(document).ready(function() { generatePokemonList(); } - - // multiple artworks - function imageType(result) { - var four_types = [351, 386, 585, 586, 676, 741, 800]; - var three_types = [249, 250, 384, 412, 413, 718, 745, 898]; - var two_types = [251, 252, 255, 258, 374, 387, 390, 393, 421, 422, 423, 487, 492, 495, 498, 501, 521, 550, 555, - 592, 593, 641, 642, 643, 644, 645, 647, 648, 668, 678, 681, 720, 746, 774, 791, 792, 802, 849, - 876, 877, 888, 889, 892, 905, "G892"]; - - function no_randomizer() { - if (result === 25) - return (result+'-9'); - if (result === 666) - return (result+'-0'); - if (result === 646) - return (result+'-0'); - if (result === 479) - return (result+'-0'); - for (a in four_types) { - if (four_types[a] == result) - return (result+'-0'); - } - for (a in three_types) { - if (three_types[a] == result) - return (result+'-0'); - } - for (a in two_types) { - if (two_types[a] == result) - return (result+'-0'); - } - return result; - } - - return no_randomizer(result); + function imageType(num) + { + //if (num["origin"] == "Kanto") + // return num["num"] + "RB"; + if (num["sprite"]) + return num["num"] + "-0"; + return num["num"]; } - }); - }); }); diff --git a/index.html b/index.html index 2cf4e1e..2fd84b5 100644 --- a/index.html +++ b/index.html @@ -141,7 +141,7 @@