Skip to content

Commit

Permalink
Randbats: Support SS Doubles and BDSP (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrianshChari authored Jul 28, 2024
1 parent e90a8e5 commit 60bf5a0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"GEN6RANDOMBATTLE": false,
"GEN7RANDOMBATTLE": false,
"GEN8RANDOMBATTLE": false,
"GEN8BDSPRANDOMBATTLE": false,
"GEN8RANDOMDOUBLESBATTLE": false,
"GEN9RANDOMBATTLE": false,
"GEN9RANDOMDOUBLESBATTLE": false,
"GEN9BABYRANDOMBATTLE": false,
Expand Down
101 changes: 65 additions & 36 deletions src/js/shared_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ $(".set-selector").change(function () {
var itemObj = pokeObj.find(".item");
var randset;
if ($("#randoms").prop("checked")) {
if (gen === 9) {
// The Gen 9 randdex contains information for multiple Random Battles formats for each Pokemon.
if (gen >= 8) {
// The Gens 8 and 9 randdex contains information for multiple Random Battles formats for each Pokemon.
// Duraludon, for example, has data for Randoms, Doubles Randoms, and Baby Randoms.
// Therefore, the information for only the format chosen should be used.
randset = randdex[pokemonName][setName];
Expand Down Expand Up @@ -922,7 +922,7 @@ $(".forme").change(function () {
$(this).parent().siblings().find(".teraToggle").prop("checked", true);
}
var isRandoms = $("#randoms").prop("checked");
var pokemonSets = isRandoms ? gen === 9 ? randdex[pokemonName][setName] :
var pokemonSets = isRandoms ? gen >= 8 ? randdex[pokemonName][setName] :
randdex[pokemonName] : setdex[pokemonName];
var chosenSet = pokemonSets && pokemonSets[setName];
var greninjaSet = $(this).val().indexOf("Greninja") !== -1;
Expand Down Expand Up @@ -1280,39 +1280,68 @@ var SETDEX = [
typeof SETDEX_SV === 'undefined' ? {} : SETDEX_SV,
];

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

// COMBINED_GEN9 will be a dictionary that will have the hierarchy Pokemon -> Format -> Sets
// An example using Duraludon would be:
// {
// ...
// Duraludon: {
// Randoms: {...},
// Doubles Randoms: {...},
// Baby Randoms: {...}
// }
// ...
// }
var COMBINED_GEN9 = {};

// We use a nested loop instead of hardcoding all three formats so that this code
// can be reused for other random battles generations and formats
for (var format in GEN9) {
var formatSets = GEN9[format];
for (var pokemon in formatSets) {
var sets = formatSets[pokemon];
if (!(pokemon in COMBINED_GEN9)) {
COMBINED_GEN9[pokemon] = {};
/*
* 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;
}
COMBINED_GEN9[pokemon][format] = sets;
}

return combined;
}

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

var GEN9RANDSETS = formatRandSets({
"Randoms": typeof GEN9RANDOMBATTLE === 'undefined' ? {} : GEN9RANDOMBATTLE,
"Doubles Randoms": typeof GEN9RANDOMDOUBLESBATTLE === 'undefined' ? {} : GEN9RANDOMDOUBLESBATTLE,
"Baby Randoms": typeof GEN9BABYRANDOMBATTLE === 'undefined' ? {} : GEN9BABYRANDOMBATTLE,
});

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

Expand Down Expand Up @@ -1453,8 +1482,8 @@ function getSetOptions(sets) {
});
if ($("#randoms").prop("checked")) {
if (pokeName in randdex) {
if (gen === 9) {
// The Gen 9 randdex contains information for multiple Random Battles formats for each Pokemon.
if (gen >= 8) {
// The Gen 8 and 9 randdex contains information for multiple Random Battles formats for each Pokemon.
// Duraludon, for example, has data for Randoms, Doubles Randoms, and Baby Randoms.
// Therefore, all of this information has to be populated within the set options.
var randTypes = Object.keys(randdex[pokeName]);
Expand Down
2 changes: 2 additions & 0 deletions src/randoms.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen9randomdoublesbattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen9babyrandombattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen8randombattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen8randomdoublesbattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen8bdsprandombattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen7randombattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen6randombattle.js?"></script>
<script type="text/javascript" src="https://data.pkmn.cc/randbats/js/gen5randombattle.js?"></script>
Expand Down

0 comments on commit 60bf5a0

Please sign in to comment.