From 5fe70f311cde95142d34e24208f1277077d5f32c Mon Sep 17 00:00:00 2001
From: versx
Date: Wed, 1 Nov 2023 20:05:25 -0700
Subject: [PATCH] Update PVP filtering & Add Little Cup filtering support
(#400)
* Update pvp filtering and add little cup filtering support
* Use maxRank value for each league
* fix typos
* update help text
* Enable level 50 cap stats by default for pvp
* update pvp league icons and add little cup icon
* Add missing raid egg icons
* Fix pokemon glow
---
src/configs/default.json | 24 +++++++++---
src/data/map.js | 35 +++++++++--------
src/views/index.mustache | 4 +-
static/img/egg/7.png | Bin 0 -> 20532 bytes
static/img/egg/8.png | Bin 0 -> 19886 bytes
static/img/misc/great.png | Bin 2360 -> 13355 bytes
static/img/misc/little.png | Bin 0 -> 10096 bytes
static/img/misc/master.png | Bin 0 -> 14136 bytes
static/img/misc/ultra.png | Bin 6630 -> 14106 bytes
static/js/index.js | 77 ++++++++++++++++++++-----------------
static/locales/_en.json | 2 +-
static/locales/_pl.json | 2 +-
12 files changed, 82 insertions(+), 62 deletions(-)
create mode 100644 static/img/egg/7.png
create mode 100644 static/img/egg/8.png
create mode 100644 static/img/misc/little.png
create mode 100644 static/img/misc/master.png
diff --git a/src/configs/default.json b/src/configs/default.json
index 711827ed..60a41a0c 100644
--- a/src/configs/default.json
+++ b/src/configs/default.json
@@ -39,16 +39,30 @@
"maxZoom": 18,
"pvp": {
"useName": true,
- "maxRank": 100,
"onlyShopTop5": false,
- "minCpGreat": 1400,
- "minCpUltra": 2400,
"megaStats": true,
"experimentalStats": false,
"l40stats": true,
"l41stats": false,
- "l50stats": false,
- "l51stats": false
+ "l50stats": true,
+ "l51stats": false,
+ "limits": {
+ "little": {
+ "minCp": 400,
+ "maxCp": 500,
+ "maxRank": 100
+ },
+ "great": {
+ "minCp": 1400,
+ "maxCp": 1500,
+ "maxRank": 100
+ },
+ "ultra": {
+ "minCp": 2350,
+ "maxCp": 2500,
+ "maxRank": 100
+ }
+ }
},
"devicePathColor": "red",
"nestPolygons": true,
diff --git a/src/data/map.js b/src/data/map.js
index 5b48180d..3d447a43 100644
--- a/src/data/map.js
+++ b/src/data/map.js
@@ -146,12 +146,9 @@ const getPokemon = async (minLat, maxLat, minLon, maxLon, showPVP, showIV, updat
}
}
if (showPVP && interestedLevelCaps.length > 0) {
- // TODO: Filter pvp rankings
- /*
- const { minCpGreat, minCpUltra } = config.map.pvp;
- const filterLeagueStats = (result, target, minCp) => {
+ const filterLeagueStats = (league, result, target, minCp) => {
let last;
- for (const entry of JSON.parse(result)) {
+ for (const entry of result) {
if (minCp && entry.cp < minCp || entry.cap !== undefined && (entry.capped
? interestedLevelCaps[interestedLevelCaps.length - 1] < entry.cap
: !interestedLevelCaps.includes(entry.cap))) {
@@ -177,18 +174,20 @@ const getPokemon = async (minLat, maxLat, minLon, maxLon, showPVP, showIV, updat
last.capped = true;
}
} else {
- target.push(entry);
+ target[league].push(entry);
last = entry;
}
}
};
- if (result.pvp_rankings_great_league) {
- filterLeagueStats(result.pvp_rankings_great_league, filtered.pvp_rankings_great_league = [], minCpGreat);
- }
- if (result.pvp_rankings_ultra_league) {
- filterLeagueStats(result.pvp_rankings_ultra_league, filtered.pvp_rankings_ultra_league = [], minCpUltra);
+ if (result.pvp && result.atk_iv) {
+ const pvpRankings = JSON.parse(result.pvp);
+ const keys = Object.keys(pvpRankings);
+ for (const league of keys) {
+ const rankings = pvpRankings[league];
+ const limits = config.map.pvp.limits[league];
+ filterLeagueStats(league, rankings, filtered.pvp = { [league]: [] }, limits.minCp);
+ }
}
- */
}
let pokemonFilter = result.form === 0 ? pokemonLookup[result.pokemon_id] : formLookup[result.form];
if (pokemonFilter === undefined) {
@@ -1413,7 +1412,7 @@ const getPolygon = (s2cellId) => {
// need to keep consistency with client-side implementation checkIVFilterValid
const jsifyIvFilter = (filter) => {
const input = filter.toUpperCase();
- let tokenizer = /\s*([()|&!,]|([ADSL]?|CP|[GU]L)\s*([0-9]+(?:\.[0-9]*)?)(?:\s*-\s*([0-9]+(?:\.[0-9]*)?))?)/g;
+ let tokenizer = /\s*([()|&!,]|([ADSL]?|CP|[GU]L|LC)\s*([0-9]+(?:\.[0-9]*)?)(?:\s*-\s*([0-9]+(?:\.[0-9]*)?))?)/g;
let result = '';
let expectClause = true; // expect a clause or '('
let stack = 0;
@@ -1433,15 +1432,17 @@ const jsifyIvFilter = (filter) => {
case 'S': column = 'sta_iv'; break;
case 'L': column = 'level'; break;
case 'CP': column = 'cp'; break;
- case 'GL': column = 'pvp_rankings_great_league'; break;
- case 'UL': column = 'pvp_rankings_ultra_league'; break;
+ case 'LC': column = 'little'; break;
+ case 'GL': column = 'great'; break;
+ case 'UL': column = 'ultra'; break;
}
let upper = lower;
if (match[4] !== undefined) {
upper = parseFloat(match[4]);
}
- if (column.endsWith('_league')) {
- result += `((pokemon['${column}'] || []).some(x => x.rank >= ${lower} && x.rank <= ${upper}))`;
+ const leagues = Object.keys(config.map.pvp.limits);
+ if (leagues.includes(column)) {
+ result += `(pokemon.pvp && pokemon.pvp['${column}'] && (pokemon.pvp['${column}'] || []).some(x => x.rank >= ${lower} && x.rank <= ${upper}))`;
} else {
result += `(pokemon['${column}'] !== null && pokemon['${column}'] >= ${lower} && pokemon['${column}'] <= ${upper})`;
}
diff --git a/src/views/index.mustache b/src/views/index.mustache
index 9ae702cc..050bd8a0 100644
--- a/src/views/index.mustache
+++ b/src/views/index.mustache
@@ -367,7 +367,7 @@
{{stats}}: A0-1 & D14 & S15 - {{stats_result}}
{{popup_cp}}: CP2000-3000 - {{cp_result}}
{{not}}: !0-100 - {{not_result}}
- {{pvp}}: GL1-3 | UL1-3 - {{pvp_result}}
+ {{pvp}}: LC1-3 | GL1-3 | UL1-3 - {{pvp_result}}
@@ -387,7 +387,7 @@
- {{example}}: (A0-1 & D15 & S15 & (CP1400-1500 | CP2400-2500)) | L34-35,90-100 | GL1-3,UL1-3
+ {{example}}: (A0-1 & D15 & S15 & (CP1400-1500 | CP2400-2500)) | L34-35,90-100 | LC1-3,GL1-3,UL1-3
{{advanced_result}}
diff --git a/static/img/egg/7.png b/static/img/egg/7.png
new file mode 100644
index 0000000000000000000000000000000000000000..6bb645ad58039be570f22c3d6b1ed01134d6b432
GIT binary patch
literal 20532
zcmV){Kz+Z7P)