Skip to content

Commit

Permalink
Merge pull request #380 from LordJavi/ar-filter
Browse files Browse the repository at this point in the history
AR quests filter
  • Loading branch information
TurtIeSocks authored Jun 9, 2021
2 parents 6549d29 + 03abeaf commit 83108de
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 12 deletions.
23 changes: 21 additions & 2 deletions src/data/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
let excludedLevels = []; //int
let excludeAllButEx = false;
let excludeAllButBattles = false;
let excludeAllButAr = false;
let excludedTeams = []; //int
let excludedAvailableSlots = []; //int

Expand Down Expand Up @@ -284,6 +285,8 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
excludeAllButBattles = true;
} else if (filter.includes('ex')) {
excludeAllButEx = true;
} else if (filter.includes('ar')) {
excludeAllButAr = true;
} else if (filter.includes('t')) {
const id = parseInt(filter.replace('t', ''));
excludedTeams.push(id);
Expand All @@ -298,6 +301,7 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
let sqlExcludeForms = '';
let excludeLevelSQL = '';
let excludeAllButExSQL = '';
let excludeAllButArSQL = '';
let excludeAllButBattlesSQL = '';
let excludeTeamSQL = '';
let excludeAvailableSlotsSQL = '';
Expand Down Expand Up @@ -380,6 +384,12 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
excludeAllButBattlesSQL = '';
}

if (excludeAllButAr) {
excludeAllButArSQL = 'AND (ar_scan_eligible = 1)';
} else {
excludeAllButArSQL = '';
}

let sql = `
SELECT id, lat, lon, name, url, guarding_pokemon_id, last_modified_timestamp, team_id, raid_end_timestamp,
raid_spawn_timestamp, raid_battle_timestamp, raid_pokemon_id, enabled, availble_slots, updated,
Expand All @@ -392,7 +402,7 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
raid_end_timestamp IS NULL OR raid_end_timestamp < UNIX_TIMESTAMP() OR raid_pokemon_id IS NULL OR
(raid_pokemon_form = 0 ${sqlExcludePokemon}) OR raid_pokemon_form NOT IN (0 ${sqlExcludeForms})
) ${excludeTeamSQL} ${excludeAvailableSlotsSQL}
${excludeAllButExSQL} ${excludeAllButBattlesSQL} ${areaRestrictionsSQL}
${excludeAllButExSQL} ${excludeAllButBattlesSQL} ${excludeAllButArSQL} ${areaRestrictionsSQL}
`;
if (!showGyms) {
sql += ' AND raid_end_timestamp IS NOT NULL AND raid_end_timestamp >= UNIX_TIMESTAMP()';
Expand Down Expand Up @@ -477,6 +487,7 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
let excludedLures = []; //int
let excludedInvasions = [];
let excludeNormal = false;
let excludeAllButAr = false;
let minimumCandyCount = 0;
let minimumStardustCount = 0;

Expand Down Expand Up @@ -516,6 +527,8 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
} else if (filter.includes('l')) {
const id = parseInt(filter.replace('l', ''));
excludedLures.push(id + 500);
} else if (filter.includes('ar')) {
excludeAllButAr = true;
}
}
}
Expand All @@ -537,6 +550,7 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
let excludeItemSQL = '';
let excludeInvasionSQL = '';
let excludePokestopSQL = '';
let excludeAllButArSQL = '';
let areaRestrictionsSQL = getAreaRestrictionSql(areaRestrictions);

if (showQuests) {
Expand Down Expand Up @@ -650,6 +664,11 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
} else {
excludePokestopSQL = `OR (lure_expire_timestamp IS NULL OR lure_expire_timestamp < UNIX_TIMESTAMP() OR ${excludeLureSQL})`;
}
if (excludeAllButAr) {
excludeAllButArSQL = 'AND (ar_scan_eligible = 1)';
} else {
excludeAllButArSQL = '';
}
} else if (!excludeNormal) {
excludePokestopSQL = 'OR TRUE';
}
Expand Down Expand Up @@ -679,7 +698,7 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
incident_expire_timestamp, grunt_type, sponsor_id${arScanEligible}
FROM pokestop
WHERE lat >= ? AND lat <= ? AND lon >= ? AND lon <= ? AND updated > ? AND deleted = false AND
(false ${excludeTypeSQL} ${excludePokemonSQL} ${excludeEvolutionSQL} ${excludeItemSQL} ${excludePokestopSQL} ${excludeInvasionSQL}) ${areaRestrictionsSQL}
(false ${excludeTypeSQL} ${excludePokemonSQL} ${excludeEvolutionSQL} ${excludeItemSQL} ${excludePokestopSQL} ${excludeInvasionSQL}) ${excludeAllButArSQL} ${areaRestrictionsSQL}
`;
const results = await dbSelection('pokestop').query(sql, args);
let pokestops = [];
Expand Down
36 changes: 34 additions & 2 deletions src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,22 @@ const getData = async (perms, filter) => {
'type': gymOptionsString
});

// AR-scan gyms
gymData.push({
'id': {
'formatted': utils.zeroPad(7, 3),
'sort': 7
},
'name': i18n.__('filter_ar_scan') ,
'image': {
type: 'img',
path: '/misc/ar-gym.png'
},
'filter': generateShowHideButtons('ar', 'gym-ar'),
'size': generateSizeButtons('ar', 'gym-ar'),
'type': gymOptionsString
});

//Available slots
for (let i = 0; i <= 6; i++) {
const availableSlots = i18n.__('filter_gym_available_slots_' + i);
Expand Down Expand Up @@ -807,6 +823,8 @@ const getData = async (perms, filter) => {
}

if (permViewMap && showPokestopFilter) {
const pokestopLuresString = i18n.__('filter_pokestop_lures');
const pokestopPokestopsString = i18n.__('filter_pokestop_pokestops');
const pokestopOptionsString = i18n.__('filter_pokestop_options');
const pokestopNormal = i18n.__('filter_pokestop_normal');
const pokestopData = [];
Expand All @@ -822,7 +840,7 @@ const getData = async (perms, filter) => {
},
'filter': generateShowHideButtons('normal', 'pokestop-normal'),
'size': generateSizeButtons('normal', 'pokestop-normal'),
'type': pokestopOptionsString
'type': pokestopPokestopsString
});

if (permShowLures) {
Expand All @@ -840,10 +858,24 @@ const getData = async (perms, filter) => {
},
'filter': generateShowHideButtons(i, 'pokestop-lure'),
'size': generateSizeButtons(i, 'pokestop-lure'),
'type': pokestopOptionsString
'type': pokestopLuresString
});
}
}
pokestopData.push({
'id': {
'formatted': utils.zeroPad(0, 3),
'sort': 100
},
'name': i18n.__('filter_ar_scan') ,
'image': {
type: 'img',
path: '/misc/ar-pokestop.png'
},
'filter': generateShowHideButtons('ar', 'pokestop-ar'),
'size': generateSizeButtons('ar', 'pokestop-ar'),
'type': pokestopOptionsString
});
data['pokestop_filters'] = pokestopData;
}

Expand Down
Binary file added static/img/misc/ar-gym.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/misc/ar-pokestop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/img/misc/ar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 110 additions & 8 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,9 @@ function loadStorage () {
if (defaultGymFilter.ex === undefined) {
defaultGymFilter.ex = { show: false, size: 'normal' };
}
if (defaultGymFilter.ar === undefined) {
defaultGymFilter.ar = { show: false, size: 'normal' };
}
if (defaultGymFilter.battle === undefined) {
defaultGymFilter.battle = { show: false, size: 'normal' };
}
Expand All @@ -933,6 +936,9 @@ function loadStorage () {
if (gymFilter.ex === undefined) {
gymFilter.ex = { show: false, size: 'normal' };
}
if (gymFilter.ar === undefined) {
gymFilter.ar = { show: false, size: 'normal' };
}
if (gymFilter.battle === undefined) {
gymFilter.battle = { show: false, size: 'normal' };
}
Expand All @@ -955,7 +961,9 @@ function loadStorage () {
defaultPokestopFilter['l' + i] = { show: true, size: 'normal' };
}
}

if (defaultPokestopFilter.ar === undefined) {
defaultPokestopFilter.ar = { show: false, size: 'normal' };
}
store('pokestop_filter', JSON.stringify(defaultPokestopFilter));
pokestopFilter = defaultPokestopFilter;
} else {
Expand All @@ -969,6 +977,9 @@ function loadStorage () {
pokestopFilter['l' + i] = { show: true, size: 'normal' };
}
}
if (pokestopFilter.ar === undefined) {
pokestopFilter.ar = { show: false, size: 'normal' };
}
}

const invasionFilterValue = retrieve('invasion_filter');
Expand Down Expand Up @@ -2085,6 +2096,9 @@ function loadData () {
if (gymFilter.battle.show !== false) {
gymFilterExclude.push('battle');
}
if (gymFilter.ar.show !== false) {
gymFilterExclude.push('ar');
}
for (i = 0; i <= 6; i++) {
if (gymFilter['s' + i].show === false) {
gymFilterExclude.push('s' + i);
Expand All @@ -2102,6 +2116,9 @@ function loadData () {
pokestopFilterExclude.push('l' + i);
}
}
if (pokestopFilter.ar.show !== false) {
pokestopFilterExclude.push('ar');
}
}

const invasionFilterExclude = [];
Expand Down Expand Up @@ -3435,7 +3452,7 @@ function getPokestopPopupContent (pokestop) {
}

if (pokestop.ar_scan_eligible) {
content += '<img src="/img/misc/ar.png" height="26" width="26"><br><br>'
content += '<img src="/img/misc/ar.png" height="42" width="42"><br>'
}

const updatedDate = new Date(pokestop.updated * 1000);
Expand Down Expand Up @@ -3652,6 +3669,9 @@ function getGymPopupContent (gym) {
// content += '<b>Gym is EX-Raid eligible</b>';
content += `<img src="/img/misc/ex.png" height="24" width="32">`;
}
if (gym.ar_scan_eligible) {
content += '<img src="/img/misc/ar.png" height="42" width="42"><br>';
}
content +=
'</div>' + // END 2ND COL
'</div>' + // END 3RD ROW
Expand All @@ -3669,10 +3689,6 @@ function getGymPopupContent (gym) {
content += `<b>${i18n('popup_worst_cp')}:</b> ${getCpAtLevel(gym.raid_pokemon_id, gym.raid_pokemon_form, 20, false)} / ${i18n('filter_weathers')}: ${getCpAtLevel(gym.raid_pokemon_id, gym.raid_pokemon_form, 25, false)}<br><br>`;
}
}

if (gym.ar_scan_eligible) {
content += '<img src="/img/misc/ar.png" height="26" width="26"><br><br>';
}

content += '</div>';

Expand Down Expand Up @@ -4967,6 +4983,27 @@ function manageSelectButton(e, isNew) {
shouldShow = gymFilterNew[id].size === 'huge';
break;
}
} else if (type === 'gym-ar') {
switch (info) {
case 'hide':
shouldShow = gymFilterNew[id].show === false;
break;
case 'show':
shouldShow = gymFilterNew[id].show === true;
break;
case 'small':
shouldShow = gymFilterNew[id].size === 'small';
break;
case 'normal':
shouldShow = gymFilterNew[id].size === 'normal';
break;
case 'large':
shouldShow = gymFilterNew[id].size === 'large';
break;
case 'huge':
shouldShow = gymFilterNew[id].size === 'huge';
break;
}
} else if (type === 'gym-slots') {
switch (info) {
case 'hide':
Expand Down Expand Up @@ -5030,6 +5067,27 @@ function manageSelectButton(e, isNew) {
shouldShow = pokestopFilterNew['l' + id].size === 'huge';
break;
}
} else if (type === 'pokestop-ar') {
switch (info) {
case 'hide':
shouldShow = pokestopFilterNew[id].show === false;
break;
case 'show':
shouldShow = pokestopFilterNew[id].show === true;
break;
case 'small':
shouldShow = pokestopFilterNew[id].size === 'small';
break;
case 'normal':
shouldShow = pokestopFilterNew[id].size === 'normal';
break;
case 'large':
shouldShow = pokestopFilterNew[id].size === 'large';
break;
case 'huge':
shouldShow = pokestopFilterNew[id].size === 'huge';
break;
}
} else if (type === 'invasion-grunt') {
switch (info) {
case 'hide':
Expand Down Expand Up @@ -5499,6 +5557,27 @@ function manageSelectButton(e, isNew) {
gymFilterNew[id].size = 'huge';
break;
}
} else if (type === 'gym-ar') {
switch (info) {
case 'hide':
gymFilterNew[id].show = false;
break;
case 'show':
gymFilterNew[id].show = true;
break;
case 'small':
gymFilterNew[id].size = 'small';
break;
case 'normal':
gymFilterNew[id].size = 'normal';
break;
case 'large':
gymFilterNew[id].size = 'large';
break;
case 'huge':
gymFilterNew[id].size = 'huge';
break;
}
} else if (type === 'gym-slots') {
switch (info) {
case 'hide':
Expand Down Expand Up @@ -5562,6 +5641,27 @@ function manageSelectButton(e, isNew) {
pokestopFilterNew['l' + id].size = 'huge';
break;
}
} else if (type === 'pokestop-ar') {
switch (info) {
case 'hide':
pokestopFilterNew[id].show = false;
break;
case 'show':
pokestopFilterNew[id].show = true;
break;
case 'small':
pokestopFilterNew[id].size = 'small';
break;
case 'normal':
pokestopFilterNew[id].size = 'normal';
break;
case 'large':
pokestopFilterNew[id].size = 'large';
break;
case 'huge':
pokestopFilterNew[id].size = 'huge';
break;
}
} else if (type === 'invasion-grunt') {
switch (info) {
case 'hide':
Expand Down Expand Up @@ -7828,6 +7928,7 @@ function registerFilterButtonCallbacks() {
defaultGymFilter['t' + i] = { show: true, size: 'normal' };
}
defaultGymFilter.ex = { show: false, size: 'normal' };
defaultGymFilter.ar = { show: false, size: 'normal' };
defaultGymFilter.battle = { show: false, size: 'normal' };
for (i = 0; i <= 6; i++) {
defaultGymFilter['s' + i] = { show: true, size: 'normal' };
Expand All @@ -7846,6 +7947,7 @@ function registerFilterButtonCallbacks() {
defaultGymFilter['t' + i] = { show: false, size: gymFilterNew['t' + i].size };
}
defaultGymFilter.ex = { show: false, size: gymFilterNew.ex.size };
defaultGymFilter.ar = { show: false, size: gymFilterNew.ar.size };
defaultGymFilter.battle = { show: false, size: gymFilterNew.ex.size };
for (i = 0; i <= 6; i++) {
defaultGymFilter['s' + i] = { show: false, size: gymFilterNew['s' + i].size };
Expand All @@ -7864,7 +7966,7 @@ function registerFilterButtonCallbacks() {
for (let i = 1; i < 6; i++) {
defaultPokestopFilter['l' + i] = { show: true, size: 'normal' };
}

defaultPokestopFilter.ar = { show: false, size: 'normal' };
store('pokestop_filter', JSON.stringify(defaultPokestopFilter));
pokestopFilterNew = defaultPokestopFilter;

Expand All @@ -7877,7 +7979,7 @@ function registerFilterButtonCallbacks() {
for (let i = 1; i < 6; i++) {
defaultPokestopFilter['l' + i] = { show: false, size: pokestopFilterNew['l' + i].size };
}

defaultPokestopFilter.ar = { show: false, size: 'normal' };
store('pokestop_filter', JSON.stringify(defaultPokestopFilter));
pokestopFilterNew = defaultPokestopFilter;

Expand Down
Loading

0 comments on commit 83108de

Please sign in to comment.