296 lines
8.3 KiB
JavaScript
296 lines
8.3 KiB
JavaScript
$(document).ready(function()
|
|
{
|
|
/****** Generations ******/
|
|
var G1 = [1, 151];
|
|
var G2 = [152, 251];
|
|
var G3 = [252, 386];
|
|
var G4 = [387, 493];
|
|
var G5 = [494, 649];
|
|
var G6 = [650, 721];
|
|
var G7 = [722, 809];
|
|
var G8 = [810, 905];
|
|
var G9 = [906, 1010];
|
|
var MEGA = [1011, 1060];
|
|
var GIGA = [1061, 1092];
|
|
var REG = [1093, 1147];
|
|
|
|
/************ GAME *************/
|
|
/*******************************/
|
|
|
|
// loading json file
|
|
$.getJSON('pokemon.json', function(pk)
|
|
{
|
|
$('article #container #game #loading').hide();
|
|
var pklist = pk;
|
|
|
|
$('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);
|
|
$('input[name="regional"]').prop('checked', true);
|
|
$('input[name="gigantamax"]').prop('checked', true);
|
|
$(this).removeClass("unselected").addClass("selected");
|
|
$(this).text("Unselect all");
|
|
}
|
|
else
|
|
{
|
|
for (i = 1; i < 10; ++i)
|
|
$('input[name="'+i+'g"]').prop('checked', false);
|
|
$('input[name="mega"]').prop('checked', false);
|
|
$('input[name="regional"]').prop('checked', false);
|
|
$('input[name="gigantamax"]').prop('checked', false);
|
|
$(this).removeClass("selected").addClass("unselected");
|
|
$(this).text("Select all");
|
|
}
|
|
})
|
|
|
|
$('article #container .button input.start').click(function()
|
|
{
|
|
var lang = $('article select.lang option:selected').attr('id');
|
|
var gen_list = new Array();
|
|
var pokemon_generation_list = new Array();
|
|
|
|
generations();
|
|
|
|
if (gen_list.length == 0)
|
|
return;
|
|
|
|
$('article #container #game #loading').show();
|
|
$('article #container #game #flashdex').empty().hide();
|
|
|
|
function getFormText(pkmn)
|
|
{
|
|
if (pkmn["origin"] == "Kanto")
|
|
return '<span class="form RB"></span>'
|
|
else if (pkmn["origin"] == "Johto")
|
|
return '<span class="form GS"></span>'
|
|
else if (pkmn["origin"] == "Hoenn")
|
|
return '<span class="form RS"></span>'
|
|
else if (pkmn["origin"] == "Sinnoh")
|
|
return '<span class="form DP"></span>'
|
|
else if (pkmn["origin"] == "Unova")
|
|
return '<span class="form BW"></span>'
|
|
else if (pkmn["origin"] == "Kalos")
|
|
return '<span class="form XY"></span>'
|
|
else if (pkmn["origin"] == "Alola")
|
|
return '<span class="form SM"></span>'
|
|
else if (pkmn["origin"] == "Galar")
|
|
return '<span class="form SWSH"></span>'
|
|
else if (pkmn["origin"] == "Hisui")
|
|
return '<span class="form LA"></span>'
|
|
else if (pkmn["origin"] == "Paldea")
|
|
return '<span class="form SV"></span>'
|
|
else if (pkmn["form"] == "mega")
|
|
return '<span class="form mega"></span>';
|
|
else if (pkmn["form"] == "giga")
|
|
return '<span class="form giga"></span>';
|
|
return '';
|
|
}
|
|
|
|
function getFormattedNumber(num)
|
|
{
|
|
if (num[0] == 'M' || num[0] == 'R' || num[0] == 'G')
|
|
return num.substring(1, num.length);
|
|
return num;
|
|
}
|
|
|
|
function getFormattedTypes(num) {
|
|
str = '<span class="types"><span class="'+num["type"][0]+'">'+num["type"][0]+'</span>';
|
|
if (num["type"][1])
|
|
str += '<span class="'+num["type"][1]+'">'+num["type"][1]+'</span>';
|
|
str += '</span>';
|
|
return str;
|
|
}
|
|
|
|
function getFormattedTypes(num, index)
|
|
{
|
|
str = '<span class="'+num["type"+index][0]+'">'+num["type"+index][0]+'</span>';
|
|
if (num["type"+index][1])
|
|
str += '<span class="'+num["type"+index][1]+'">'+num["type"+index][1]+'</span>';
|
|
return str;
|
|
}
|
|
|
|
function getFormattedSpriteButton(num)
|
|
{
|
|
if (num["sprite"] || num["origin"] == "Kanto")
|
|
return '<span class="button"><span class="left-arrow">◀︎</span><span class="right-arrow">▶︎</span></span>';
|
|
return '';
|
|
}
|
|
|
|
for (i in pokemon_generation_list)
|
|
{
|
|
$('article #container #game #flashdex').append(
|
|
'<div class="pokedex id_'+pklist.mn[pokemon_generation_list[i]]["num"]+'">'
|
|
+ '<span class="types">' + getFormattedTypes(pklist.mn[pokemon_generation_list[i]], '') + '</span>'
|
|
+ getFormattedSpriteButton(pklist.mn[pokemon_generation_list[i]], '')
|
|
+ getFormText(pklist.mn[pokemon_generation_list[i]]) // either gigantamax or mega-evolution
|
|
+ '<img src="pokemon/'+ imageType(pklist.mn[pokemon_generation_list[i]]) +'.png"/>'
|
|
+ '<span class="name">' + '<strong>' + '#' + getFormattedNumber(pklist.mn[[pokemon_generation_list[i]]]["num"]) + '</strong> '
|
|
+ pklist.mn[[pokemon_generation_list[i]]][lang] + '</span>'
|
|
+ '</div>'
|
|
);
|
|
}
|
|
|
|
$('article #container #game #flashdex').waitForImages(function()
|
|
{
|
|
$(this).show();
|
|
$('article #container #game #loading').hide();
|
|
});
|
|
|
|
function handleArtworks(origin, left)
|
|
{
|
|
function handleDefault()
|
|
{
|
|
var form = url.split('-')[1];
|
|
|
|
if (left)
|
|
{
|
|
if (form > 0)
|
|
form--;
|
|
else
|
|
form = pklist.mn[pokemon]["sprite"] - 1;
|
|
}
|
|
else
|
|
{
|
|
if (form < pklist.mn[pokemon]["sprite"] - 1)
|
|
form++;
|
|
else
|
|
form = 0;
|
|
}
|
|
|
|
var newUrl = 'pokemon/' + pokemonUrl + '-' + form + '.png';
|
|
|
|
origin.parent().parent().find("img").attr('src', newUrl);
|
|
handleChangeType(form, pokemon);
|
|
}
|
|
|
|
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";
|
|
}
|
|
|
|
if (KantoForm)
|
|
KantoForm = "-" + KantoForm;
|
|
|
|
var newUrl = 'pokemon/' + pokemonUrl + KantoForm + '.png';
|
|
origin.parent().parent().find("img").attr('src', newUrl);
|
|
}
|
|
|
|
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 = pklist.mn.findIndex(function(item, i)
|
|
{
|
|
return item.num == pokemonUrl;
|
|
});
|
|
|
|
if (pklist.mn[pokemon]["origin"] == "Kanto" && !pklist.mn[pokemon]["sprite"])
|
|
handleKanto();
|
|
else if (pklist.mn[pokemon]["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)
|
|
{
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
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);
|
|
evaluateByGeneration(i, "mega", MEGA); evaluateByGeneration(i, "regional", REG); evaluateByGeneration(i, "gigantamax", GIGA);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < 10; i++)
|
|
createGenerationList((i + "g"));
|
|
createGenerationList("regional");
|
|
createGenerationList("mega");
|
|
createGenerationList("gigantamax");
|
|
|
|
generatePokemonList();
|
|
}
|
|
|
|
// multiple artworks
|
|
function imageType(num)
|
|
{
|
|
if (num["sprite"])
|
|
return num["num"] + "-0";
|
|
return num["num"];
|
|
}
|
|
});
|
|
});
|
|
});
|