Skip to content

Commit

Permalink
feat: wayfarer poi colors & sponsor filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Nov 2, 2023
1 parent 3f99b48 commit c7a6e06
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 64 deletions.
5 changes: 3 additions & 2 deletions packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -671,5 +671,6 @@
"done": "Done",
"fast": "Fast",
"charged": "Charged",
"offline_mode": "Offline Mode"
}
"offline_mode": "Offline Mode",
"include_sponsored": "Include Sponsored"
}
2 changes: 2 additions & 0 deletions packages/types/lib/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface PoI {
id: string
lat: number
lon: number
showcase: boolean
partner: boolean
}

export interface BaseCell {
Expand Down
6 changes: 6 additions & 0 deletions packages/types/lib/scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface Gym {
total_cp: number
first_seen_timestamp: number
sponsor_id: number
partner_id: number
raid_pokemon_costume: number
raid_pokemon_gender: number
raid_pokemon_evolution: number
Expand Down Expand Up @@ -161,13 +162,18 @@ export interface Pokestop {
pokestop_display: number
first_seen_timestamp: number
sponsor_id: number
partner_id: number
ar_scan_eligible: boolean
quests: Quest[]
invasions: Invasion[]
events: Event[]
power_up_level: number
power_up_points: number
power_up_end_timestamp: number
showcase_expiry?: number
showcase_pokemon_id?: number
showcase_ranking_standard?: number
showcase_rankings?: ShowcaseDetails | string
}

export type FullPokestop = FullModel<Pokestop, PokestopModel>
Expand Down
5 changes: 4 additions & 1 deletion server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
"darkMapBorder": "#ff0000",
"cellBlocked": "#000000",
"poiColor": "#03ffff",
"showcaseColor": "#D365F5",
"partnerColor": "#F60042",
"enablePortalPopupCoords": false
},
"s2cells": {
Expand Down Expand Up @@ -554,7 +556,8 @@
"enabled": false,
"rings": true,
"s17Cells": true,
"s14Cells": true
"s14Cells": true,
"includeSponsored": true
},
"s2cells": {
"enabled": false,
Expand Down
2 changes: 2 additions & 0 deletions server/src/graphql/typeDefs/map.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type PoI {
id: ID
lat: Float
lon: Float
showcase: Boolean
partner: Boolean
}

type SubmissionCell {
Expand Down
2 changes: 2 additions & 0 deletions server/src/graphql/typeDefs/scanner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Gym {
total_cp: Int
first_seen_timestamp: Int
sponsor_id: Int
partner_id: Int
raid_pokemon_costume: Int
raid_pokemon_gender: Int
raid_pokemon_evolution: Int
Expand Down Expand Up @@ -140,6 +141,7 @@ type Pokestop {
pokestop_display: Int
first_seen_timestamp: Int
sponsor_id: Int
partner_id: Int
ar_scan_eligible: Boolean
quests: [Quest]
invasions: [Invasion]
Expand Down
27 changes: 16 additions & 11 deletions server/src/models/Gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,36 +567,41 @@ class Gym extends Model {
.first()
}

static getSubmissions(perms, args, { isMad }) {
static async getSubmissions(perms, args, { isMad }) {
const {
filters: { onlyAreas = [] },
filters: { onlyAreas = [], onlyIncludeSponsored = true },
minLat,
minLon,
maxLat,
maxLon,
} = args
const wiggle = 0.025
const query = this.query()
.whereBetween(`lat${isMad ? 'itude' : ''}`, [
minLat - 0.025,
maxLat + 0.025,
minLat - wiggle,
maxLat + wiggle,
])
.andWhereBetween(`lon${isMad ? 'gitude' : ''}`, [
minLon - 0.025,
maxLon + 0.025,
minLon - wiggle,
maxLon + wiggle,
])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query.select(['gym_id AS id', 'latitude AS lat', 'longitude AS lon'])
} else {
query.select(['id', 'lat', 'lon']).andWhere((poi) => {
poi.whereNull('sponsor_id').orWhere('sponsor_id', 0)
})
query.select(['id', 'lat', 'lon', 'partner_id'])

if (!onlyIncludeSponsored) {
query.andWhere((poi) => {
poi.whereNull('partner_id').orWhere('partner_id', 0)
})
}
}
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}

return query
const results = await query
return results
}
}

Expand Down
6 changes: 5 additions & 1 deletion server/src/models/PoI.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ class PoI {
* @param {string} id
* @param {number} lat
* @param {number} lon
* @param {boolean} [partner]
* @param {boolean} [showcase]
*/
constructor(id, lat, lon) {
constructor(id, lat, lon, partner = false, showcase = false) {
this.id = id
this.lat = lat
this.lon = lon
this.partner = partner
this.showcase = showcase
}
}

Expand Down
16 changes: 11 additions & 5 deletions server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1723,9 +1723,9 @@ class Pokestop extends Model {
.first()
}

static getSubmissions(perms, args, { isMad }) {
static getSubmissions(perms, args, { isMad, hasShowcaseData }) {
const {
filters: { onlyAreas = [] },
filters: { onlyAreas = [], onlyIncludeSponsored = true },
minLat,
minLon,
maxLat,
Expand All @@ -1744,9 +1744,15 @@ class Pokestop extends Model {
if (isMad) {
query.select(['pokestop_id AS id', 'latitude AS lat', 'longitude AS lon'])
} else {
query.select(['id', 'lat', 'lon']).andWhere((poi) => {
poi.whereNull('sponsor_id').orWhere('sponsor_id', 0)
})
query.select(['id', 'lat', 'lon', 'partner_id'])
if (!onlyIncludeSponsored) {
query.andWhere((poi) => {
poi.whereNull('partner_id').orWhere('partner_id', 0)
})
}
if (hasShowcaseData) {
query.select('showcase_expiry')
}
}
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
Expand Down
1 change: 1 addition & 0 deletions server/src/services/filters/builder/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function buildDefaultFilters(perms, database) {
rings: defaultFilters.submissionCells.rings,
s17Cells: defaultFilters.submissionCells.s17Cells,
s14Cells: defaultFilters.submissionCells.s14Cells,
includeSponsored: defaultFilters.submissionCells.includeSponsored,
filter: { global: new BaseFilter() },
}
: undefined,
Expand Down
11 changes: 10 additions & 1 deletion server/src/services/functions/getPlacementCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ function getPlacementCells(filters, pokestops, gyms) {
? Object.values(indexedCells)
: [],
pois: filters.filters.onlyRings
? allCoords.map((poi) => new PoI(poi.id, poi.lat, poi.lon))
? allCoords.map(
(poi) =>
new PoI(
poi.id,
poi.lat,
poi.lon,
!!poi.partner_id,
'showcase_expiry' in poi ? !!poi.showcase_expiry : false,
),
)
: [],
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/services/ui/clientOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function clientOptions(perms) {
darkMapBorder: { type: 'color', perm: ['submissionCells'] },
cellBlocked: { type: 'color', perm: ['submissionCells'] },
poiColor: { type: 'color', perm: ['submissionCells'] },
partnerColor: { type: 'color', perm: ['submissionCells'] },
showcaseColor: { type: 'color', perm: ['submissionCells'] },
},
s2cells: {
lightMapBorder: { type: 'color', perm: ['s2cells'] },
Expand Down
15 changes: 9 additions & 6 deletions server/src/services/ui/primary.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ function generateUi(req, perms) {
wayfarer:
perms.portals || perms.submissionCells
? {
portals: (perms.portals && Db.models.Portal) || undefined,
portals: !!(perms.portals && Db.models.Portal) || undefined,
submissionCells:
(perms.submissionCells && Db.models.Pokestop && Db.models.Gym) ||
undefined,
!!(
perms.submissionCells &&
Db.models.Pokestop &&
Db.models.Gym
) || undefined,
}
: undefined,
s2cells: perms.s2cells ? { enabled: true, cells: true } : undefined,
Expand All @@ -164,9 +167,9 @@ function generateUi(req, perms) {
perms.spawnpoints || perms.scanCells || perms.devices
? {
spawnpoints:
(perms.spawnpoints && Db.models.Spawnpoint) || undefined,
scanCells: (perms.scanCells && Db.models.ScanCell) || undefined,
devices: (perms.devices && Db.models.Device) || undefined,
!!(perms.spawnpoints && Db.models.Spawnpoint) || undefined,
scanCells: !!(perms.scanCells && Db.models.ScanCell) || undefined,
devices: !!(perms.devices && Db.models.Device) || undefined,
}
: undefined,
settings: true,
Expand Down
66 changes: 31 additions & 35 deletions src/components/layout/drawer/Extras.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,20 @@ export default function Extras({ category, subItem, data }) {
alignItems="center"
justifyContent="flex-end"
>
<ListItem
secondaryAction={
<Switch
checked={filters[category]?.confirmed || false}
onChange={() => {
setFilters({
...filters,
[category]: {
...filters[category],
confirmed: !filters[category].confirmed,
},
})
}}
/>
}
>
<ListItem>
<ListItemText sx={{ pl: 4 }} primary={t('only_confirmed')} />
<Switch
checked={filters[category]?.confirmed || false}
onChange={() => {
setFilters({
...filters,
[category]: {
...filters[category],
confirmed: !filters[category].confirmed,
},
})
}}
/>
</ListItem>
</CollapsibleItem>
)
Expand Down Expand Up @@ -268,10 +265,21 @@ export default function Extras({ category, subItem, data }) {
) {
return (
<CollapsibleItem open={!!filters[subItem]?.enabled}>
{['rings', 's14Cells', 's17Cells'].map((item, i) => (
<ListItem
key={item}
secondaryAction={
{['rings', 'includeSponsored', 's14Cells', 's17Cells'].map(
(item, i) => (
<ListItem key={item}>
<ListItemText
sx={{ pl: 4 }}
primary={
i > 1 ? (
<Trans i18nKey="s2_cell_level">
{{ level: item.substring(1, 3) }}
</Trans>
) : (
t(i ? 'include_sponsored' : 'poi')
)
}
/>
<Switch
checked={!!filters[subItem]?.[item]}
onChange={() => {
Expand All @@ -285,21 +293,9 @@ export default function Extras({ category, subItem, data }) {
}}
disabled={filters[subItem]?.enabled === false}
/>
}
>
<ListItemText
primary={
i ? (
<Trans i18nKey="s2_cell_level">
{{ level: item.substring(1, 3) }}
</Trans>
) : (
t('poi')
)
}
/>
</ListItem>
))}
</ListItem>
),
)}
</CollapsibleItem>
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/tiles/submissionCells/S14Cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const MemoS14Cell = React.memo(
prev.cellColor === next.cellColor &&
prev.oneStopTillNext === next.oneStopTillNext &&
prev.twoStopsTillNext === next.twoStopsTillNext &&
prev.noMoreGyms === next.noMoreGyms,
prev.noMoreGyms === next.noMoreGyms &&
prev.count_gyms === next.count_gyms &&
prev.count_pokestops === next.count_pokestops,
)

export default MemoS14Cell
14 changes: 13 additions & 1 deletion src/components/tiles/submissionCells/SubmissionCell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import PoITile from './PoI'
*/
const SubmissionCellTile = ({ level14Cells, level17Cells, pois }) => {
const poiColor = useStore((s) => s.userSettings.wayfarer.poiColor)
const showcaseColor = useStore((s) => s.userSettings.wayfarer.showcaseColor)
const partnerColor = useStore((s) => s.userSettings.wayfarer.partnerColor)
const cellBlocked = useStore((s) => s.userSettings.wayfarer.cellBlocked)
const oneStopTillNext = useStore(
(s) => s.userSettings.wayfarer.oneStopTillNext,
Expand All @@ -31,7 +33,17 @@ const SubmissionCellTile = ({ level14Cells, level17Cells, pois }) => {
return (
<>
{pois?.map((ring) => (
<PoITile key={ring.id} {...ring} color={poiColor} />
<PoITile
key={ring.id}
{...ring}
color={
ring.showcase
? showcaseColor
: ring.partner
? partnerColor
: poiColor
}
/>
))}
{level17Cells?.map((cell) => (
<Level17Tile
Expand Down
2 changes: 2 additions & 0 deletions src/services/queries/submissionCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const getAllSubmissionCells = gql`
id
lat
lon
showcase
partner
}
}
}
Expand Down

0 comments on commit c7a6e06

Please sign in to comment.