Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
thejetou committed Jul 28, 2024
1 parent 8367e24 commit 901fa9f
Showing 1 changed file with 56 additions and 59 deletions.
115 changes: 56 additions & 59 deletions src/js/shared_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,21 +1280,67 @@ var SETDEX = [
typeof SETDEX_SV === 'undefined' ? {} : SETDEX_SV,
];

// Creates a single dictionary for all Gen 8 Random Battles formats
var GEN8 = {
/*
* Converts an object that has the hierarchy Format -> Pokemon -> Sets
* into one that has the hierarchy Pokemon -> Format -> Sets
* An example for Gen 9 Duraludon would be:
* {
* Randoms: {
* ...
* Duraludon: {...},
* ...
* },
* Doubles Randoms: {
* ...
* Duraludon: {...},
* ...
* },
* Baby Randoms: {
* ...
* Duraludon: {...},
* ...
* }
* }
* getting converted into:
* {
* ...
* Duraludon: {
* Randoms: {...},
* Doubles Randoms: {...},
* Baby Randoms: {...}
* }
* ...
* }
*/
function formatRandSets(gen) {
var combined = {};

for (var format in gen) {
var formatSets = gen[format];
for (var pokemon in formatSets) {
var sets = formatSets[pokemon];
if (!(pokemon in combined)) {
combined[pokemon] = {};
}
combined[pokemon][format] = sets;
}
}

return combined;
}

// Creates a single dictionary for Gen 8 & Gen 9 Random Battles formats
var GEN8 = formatRandSets({
"Randoms": typeof GEN8RANDOMBATTLE === 'undefined' ? {} : GEN8RANDOMBATTLE,
"Doubles Randoms": typeof GEN8RANDOMDOUBLESBATTLE === 'undefined' ? {} : GEN8RANDOMDOUBLESBATTLE,
"BDSP Randoms": typeof GEN8BDSPRANDOMBATTLE === 'undefined' ? {} : GEN8BDSPRANDOMBATTLE,
};
var COMBINED_GEN8 = formatRandSets(GEN8);
});

// Creates a single dictionary for all Gen 9 Random Battles formats
var GEN9 = {
var GEN9 = formatRandSets({
"Randoms": typeof GEN9RANDOMBATTLE === 'undefined' ? {} : GEN9RANDOMBATTLE,
"Doubles Randoms": typeof GEN9RANDOMDOUBLESBATTLE === 'undefined' ? {} : GEN9RANDOMDOUBLESBATTLE,
"Baby Randoms": typeof GEN9BABYRANDOMBATTLE === 'undefined' ? {} : GEN9BABYRANDOMBATTLE,
};
var COMBINED_GEN9 = formatRandSets(GEN9);
});

var RANDDEX = [
{},
Expand All @@ -1305,8 +1351,8 @@ var RANDDEX = [
typeof GEN5RANDOMBATTLE === 'undefined' ? {} : GEN5RANDOMBATTLE,
typeof GEN6RANDOMBATTLE === 'undefined' ? {} : GEN6RANDOMBATTLE,
typeof GEN7RANDOMBATTLE === 'undefined' ? {} : GEN7RANDOMBATTLE,
COMBINED_GEN8,
COMBINED_GEN9,
GEN8,
GEN9,
];
var gen, genWasChanged, notation, pokedex, setdex, randdex, typeChart, moves, abilities, items, calcHP, calcStat, GENERATION;

Expand Down Expand Up @@ -1420,55 +1466,6 @@ function clearField() {
$("input:checkbox[name='terrain']").prop("checked", false);
}

/*
* Converts an object that has the hierarchy Format -> Pokemon -> Sets
* into one that has the hierarchy Pokemon -> Format -> Sets
* An example for Gen 9 Duraludon would be:
* {
* Randoms: {
* ...
* Duraludon: {...},
* ...
* },
* Doubles Randoms: {
* ...
* Duraludon: {...},
* ...
* },
* Baby Randoms: {
* ...
* Duraludon: {...},
* ...
* }
* }
* getting converted into:
* {
* ...
* Duraludon: {
* Randoms: {...},
* Doubles Randoms: {...},
* Baby Randoms: {...}
* }
* ...
* }
*/
function formatRandSets(gen) {
var combined = {};

for (var format in gen) {
var formatSets = gen[format];
for (var pokemon in formatSets) {
var sets = formatSets[pokemon];
if (!(pokemon in combined)) {
combined[pokemon] = {};
}
combined[pokemon][format] = sets;
}
}

return combined;
}

function getSetOptions(sets) {
var setsHolder = sets;
if (setsHolder === undefined) {
Expand Down

0 comments on commit 901fa9f

Please sign in to comment.