Last active
February 3, 2021 03:14
-
-
Save devxoul/20f0593481484e7469bad9e98d2f3ae0 to your computer and use it in GitHub Desktop.
IV filter for seoulpokemap.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filteredPokemonsByIV(pokemons, iv) { | |
iv = iv || 0.9; | |
return pokemons.filter(function (pokemon) { | |
var currentIV = (pokemon.attack + pokemon.defence + pokemon.stamina) / 45; | |
return currentIV >= iv; | |
}); | |
} | |
function arePokemonsEqual(lhs, rhs) { | |
if (lhs.length != rhs.length) { | |
return false; | |
} | |
for (var i = 0; i < lhs.length; i++) { | |
if (!lhs[i].isEqual(rhs[i])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function removeAllMarkers() { | |
markers.forEach(function (marker) { | |
marker.removeFrom(map); | |
}); | |
markers = []; | |
} | |
function filterByIV(iv) { | |
var filteredPokemons = filteredPokemonsByIV(pokemons, iv); | |
if (arePokemonsEqual(filteredPokemons, pokemons)) { | |
return; | |
} | |
pokemons = []; | |
removeAllMarkers(); | |
refreshPokemons(); | |
refreshMarker(); | |
var newPokemons = filteredPokemons.map(function (pokemon) { | |
pokemon['pokemon_id'] = pokemon.id; | |
pokemon['lat'] = pokemon.center.lat; | |
pokemon['lng'] = pokemon.center.lng; | |
return pokemon; | |
}); | |
timeOffset = 0; | |
processNewPokemons(newPokemons); | |
} | |
var ivFilterIntervalId = null; | |
function turnOnIVFilter(iv) { | |
ivFilterIntervalId = setInterval(function() { | |
filterByIV(iv); | |
}, 100); | |
} | |
function turnOffIVFilter() { | |
clearInterval(ivFilterIntervalId); | |
} | |
// Usage | |
turnOnIVFilter(0.9); | |
// turnOffIVFilter(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment