Skip to content

Commit

Permalink
Merge pull request #892 from WatWowMap/fix-pkmn-filters
Browse files Browse the repository at this point in the history
Fix pkmn filters
  • Loading branch information
TurtIeSocks authored Dec 27, 2023
2 parents 3d9436b + 6927b9c commit 0f2d0eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
22 changes: 4 additions & 18 deletions server/src/models/Pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,10 @@ class Pokemon extends Model {
const [id, form] = key.split('-', 2).map(Number)
return { id, form }
})

if (globalFilter.filterKeys.size) {
filters.push(
...globalFilter.buildApiFilter(
globalFilter.mods.onlyLinkGlobal ? pokemon : undefined,
),
)
}
if (onlyZeroIv)
filters.push({
iv: { min: 0, max: 0 },
pokemon: globalFilter.mods.onlyLinkGlobal ? pokemon : [],
})
if (onlyHundoIv)
filters.push({
iv: { min: 100, max: 100 },
pokemon: globalFilter.mods.onlyLinkGlobal ? pokemon : [],
})
if (!globalFilter.mods.onlyLinkGlobal) pokemon.push({ id: -1 }) // add everything else
filters.push(...globalFilter.buildApiFilter(pokemon))
if (onlyZeroIv) filters.push({ iv: { min: 0, max: 0 }, pokemon })
if (onlyHundoIv) filters.push({ iv: { min: 100, max: 100 }, pokemon })
}
/** @type {import("../types").Pokemon[]} */
const results = await this.evalQuery(
Expand Down
7 changes: 4 additions & 3 deletions server/src/services/filters/pokemon/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ module.exports = class PkmnBackend {

/**
* Build the API filter for Golbat
* @returns {import('../../../types').DnfFilter[]}
* @param {import('@rm/types').FilterId[]} [pokemon]
* @returns {import('@rm/types').DnfFilter[]}
*/
buildApiFilter(pokemon = undefined) {
const {
Expand All @@ -283,8 +284,8 @@ module.exports = class PkmnBackend {
return dnfifyIvFilter(adv, pokemon)
}
if (
(!this.filterKeys.size || (!this.perms.iv && !this.perms.pvp)) &&
this.id !== 'global'
this.id !== 'global' &&
(!this.filterKeys.size || (!this.perms.iv && !this.perms.pvp))
) {
return [{ pokemon, iv: { min: -1, max: 100 } }]
}
Expand Down

0 comments on commit 0f2d0eb

Please sign in to comment.