Skip to content

Commit

Permalink
Merge pull request #916 from WatWowMap/showcase-type-id
Browse files Browse the repository at this point in the history
feat: showcase type id support
  • Loading branch information
TurtIeSocks authored Jan 15, 2024
2 parents cbae3c1 + c81340c commit da656ce
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 51 deletions.
1 change: 1 addition & 0 deletions packages/types/lib/scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export interface Event {
event_expire_timestamp: number
showcase_pokemon_id: number
showcase_pokemon_form_id: number
showcase_pokemon_type_id: number
showcase_rankings: ShowcaseDetails
showcase_ranking_standard: number
}
Expand Down
1 change: 1 addition & 0 deletions packages/types/lib/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface DbContext {
hasAlignment: boolean
hasShowcaseData: boolean
hasShowcaseForm: boolean
hasShowcaseTypes: boolean
}

export interface ExpressUser extends User {
Expand Down
8 changes: 4 additions & 4 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,10 +958,10 @@
"xl": 3
},
"event": {
"sm": 20,
"md": 40,
"lg": 60,
"xl": 80
"sm": 15,
"md": 25,
"lg": 35,
"xl": 45
}
}
},
Expand Down
1 change: 1 addition & 0 deletions server/src/graphql/typeDefs/scanner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type Event {
event_expire_timestamp: Int
showcase_pokemon_id: Int
showcase_pokemon_form_id: Int
showcase_pokemon_type_id: Int
showcase_rankings: ShowcaseDetails
showcase_ranking_standard: Int
}
Expand Down
40 changes: 26 additions & 14 deletions server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class Pokestop extends Model {
case 'o':
break
case 'f':
case 'h':
// do nothing
break
case 'd':
Expand Down Expand Up @@ -716,6 +717,10 @@ class Pokestop extends Model {
event.display_type === 9
? pokestop.showcase_pokemon_form_id
: null,
showcase_pokemon_type_id:
event.display_type === 9
? pokestop.showcase_pokemon_type_id
: null,
showcase_rankings: event.display_type === 9 ? showcaseData : null,
showcase_ranking_standard:
event.display_type === 9
Expand All @@ -733,6 +738,8 @@ class Pokestop extends Model {
event.showcase_pokemon_form_id ?? 0
}`
]
: event.showcase_pokemon_type_id
? filters[`h${event.showcase_pokemon_type_id}`]
: true,
)
}
Expand Down Expand Up @@ -999,6 +1006,7 @@ class Pokestop extends Model {
hasConfirmed,
hasShowcaseData,
hasShowcaseForm,
hasShowcaseType,
}) {
const ts = Math.floor(Date.now() / 1000)
const finalList = new Set()
Expand Down Expand Up @@ -1375,17 +1383,17 @@ class Pokestop extends Model {
.orderBy(isMad ? 'active_fort_modifier' : 'lure_id')
// lures

// showcase
if (hasShowcaseData) {
queries.showcase = hasShowcaseForm
? this.query()
.distinct('showcase_pokemon_id', 'showcase_pokemon_form_id')
.where('showcase_expiry', '>=', ts)
.orderBy('showcase_pokemon_id', 'showcase_pokemon_form_id')
: this.query()
.distinct('showcase_pokemon_id')
.where('showcase_expiry', '>=', ts)
.orderBy('showcase_pokemon_id')
const distinct = ['showcase_pokemon_id']
if (hasShowcaseForm) distinct.push('showcase_pokemon_form_id')
if (hasShowcaseType) distinct.push('showcase_pokemon_type_id')
queries.showcase = this.query()
.distinct(...distinct)
.where('showcase_expiry', '>=', ts)
.orderBy(...distinct)
}
// showcase

const resolved = Object.fromEntries(
await Promise.all(
Expand Down Expand Up @@ -1506,11 +1514,15 @@ class Pokestop extends Model {
case 'showcase':
if (hasShowcaseData) {
rewards.forEach((reward) => {
finalList.add(
`f${reward.showcase_pokemon_id}-${
reward.showcase_pokemon_form_id ?? 0
}`,
)
if (reward.showcase_pokemon_id) {
finalList.add(
`f${reward.showcase_pokemon_id}-${
reward.showcase_pokemon_form_id ?? 0
}`,
)
} else if (reward.showcase_pokemon_type_id) {
finalList.add(`h${reward.showcase_pokemon_type_id}`)
}
})
}
break
Expand Down
3 changes: 3 additions & 0 deletions server/src/services/DbCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ module.exports = class DbCheck {
hasAltQuests,
hasShowcaseData,
hasShowcaseForm,
hasShowcaseType,
] = await schema('pokestop')
.columnInfo()
.then((columns) => [
Expand All @@ -149,6 +150,7 @@ module.exports = class DbCheck {
'alternative_quest_type' in columns,
'showcase_pokemon_id' in columns,
'showcase_pokemon_form_id' in columns,
'showcase_pokemon_type_id' in columns,
])
const [hasLayerColumn] = isMad
? await schema('trs_quest')
Expand Down Expand Up @@ -194,6 +196,7 @@ module.exports = class DbCheck {
polygon,
hasShowcaseData,
hasShowcaseForm,
hasShowcaseType,
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/services/filters/builder/pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function buildPokestops(perms, defaults) {
if (perms.eventStops && avail.startsWith('b')) {
quests[avail] = new BaseFilter(defaults.eventStops)
}
if (perms.eventStops && avail.startsWith('f')) {
if (perms.eventStops && (avail.startsWith('f') || avail.startsWith('h'))) {
quests[avail] = new BaseFilter(defaults.showcasePokemon)
}
})
Expand Down
1 change: 0 additions & 1 deletion src/components/layout/dialogs/filters/FilterMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function FilterMenu() {
{
name: 'close',
action: toggleDialog(false, category, 'filters'),
icon: 'Clear',
color: 'secondary',
},
]),
Expand Down
3 changes: 2 additions & 1 deletion src/components/layout/dialogs/filters/SliderTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export default function SliderTile({
React.useCallback(
({ type, target }) => {
const existing = text.slice()
const newValue = +target.value || ''
const num = +target.value
const newValue = Number.isNaN(num) ? '' : num
const targetIndex = target.id === 'min' ? 0 : 1

if (newValue === '') {
Expand Down
11 changes: 7 additions & 4 deletions src/components/layout/drawer/SelectorItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ function SelectorItem({ id, filter, setFilter, onClick, hasAll, easyMode }) {
}, [filter, setFilter, hasAll, easyMode])

/** @type {import('@mui/material').IconButtonProps['onClick']} */
const handleIconClick = React.useCallback((e) => {
e.stopPropagation()
onClick()
}, [])
const handleIconClick = React.useCallback(
(e) => {
e.stopPropagation()
onClick()
},
[id],
)

return (
<Box
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/drawer/SelectorList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function SelectorList({ category, subCategory, label, height = 400 }) {
key.startsWith('p')
)
case 'showcase':
return key.startsWith('f')
return key.startsWith('f') || key.startsWith('h')
case 'rocketPokemon':
return key.startsWith('a')
case 'pokemon':
Expand Down
58 changes: 36 additions & 22 deletions src/components/markers/usePokestopMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function usePokestopMarker({
invasionSizes.unshift(
Icons.getSize('invasion', filters[`i${invasion.grunt_type}`]?.size),
)
popupYOffset += rewardMod.offsetY - 1
popupYOffset += invasionMod.offsetY - 1
popupX += invasionMod.popupX
popupY += invasionMod.popupY
}
Expand Down Expand Up @@ -196,30 +196,44 @@ export default function usePokestopMarker({
url: Icons.getPokemon(352),
})
showcaseSizes.unshift(Icons.getSize('event', filters.b7?.size))
} else if (event.display_type === 9 && event.showcase_pokemon_id) {
showcaseIcons.unshift({
url: Icons.getPokemon(
event.showcase_pokemon_id,
event.showcase_pokemon_form_id,
),
decoration: true,
})
showcaseSizes.unshift(
Icons.getSize(
'event',
filters[
`f${event.showcase_pokemon_id}-${event.showcase_pokemon_form_id}`
]?.size,
),
)
} else if (event.display_type === 9) {
if (event.showcase_pokemon_id) {
showcaseIcons.unshift({
url: Icons.getPokemon(
event.showcase_pokemon_id,
event.showcase_pokemon_form_id,
),
decoration: true,
})
showcaseSizes.unshift(
Icons.getSize(
'event',
filters[
`f${event.showcase_pokemon_id}-${event.showcase_pokemon_form_id}`
]?.size,
),
)
} else if (event.showcase_pokemon_type_id) {
showcaseIcons.unshift({
url: Icons.getTypes(event.showcase_pokemon_type_id),
decoration: true,
})
showcaseSizes.unshift(
Icons.getSize(
'event',
filters[`h${event.showcase_pokemon_type_id}`]?.size,
),
)
}
}
popupYOffset += rewardMod.offsetY - 1
popupX += rewardMod.popupX
popupY += rewardMod.popupY
popupYOffset += eventMod.offsetY - 1
popupX += eventMod.popupX
popupY += eventMod.popupY
})
}
const totalQuestSize = questSizes.reduce((a, b) => a + b, 0)
const totalInvasionSize = invasionSizes.reduce((a, b) => a + b, 0)
const totalShowcaseSize = showcaseSizes.reduce((a, b) => a + b, -3)

const showAr = showArBadge && ar_scan_eligible && !baseIcon.includes('_ar')

Expand All @@ -230,8 +244,8 @@ export default function usePokestopMarker({
? pokestopMod.manualPopup -
totalInvasionSize * 0.25 -
totalQuestSize * 0.1
: -(baseSize + totalInvasionSize + totalQuestSize) / popupYOffset) +
popupY,
: -(baseSize + totalInvasionSize + totalQuestSize + totalShowcaseSize) /
popupYOffset) + popupY,
],
className: 'pokestop-marker',
html: /* html */ `
Expand Down
37 changes: 35 additions & 2 deletions src/components/popups/Pokestop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default function PokestopPopup({
<TimeTile
expireTime={event.event_expire_timestamp}
expandKey={
event.showcase_pokemon_id
event.display_type === 9
? `event_${event.display_type}`
: undefined
}
Expand Down Expand Up @@ -221,6 +221,30 @@ export default function PokestopPopup({
/>
</div>
</NameTT>
) : event.showcase_pokemon_type_id ? (
<NameTT
key={event.showcase_pokemon_type_id}
id={[
`poke_type_${event.showcase_pokemon_type_id}`,
]}
>
<div className="invasion-reward">
<img
className="invasion-reward"
alt="invasion reward"
src={Icons.getTypes(
event.showcase_pokemon_type_id,
)}
/>
<img
className="invasion-reward-shadow"
alt="shadow"
src={Icons.getEventStops(
event.display_type,
)}
/>
</div>
</NameTT>
) : (
Icons.getEventStops(event.display_type)
)
Expand Down Expand Up @@ -869,7 +893,7 @@ const NoBorderCell = styled(TableCell, {
textAlign,
}))

const ShowcaseEntry = ({ rank, score }) => {
const ShowcaseEntry = ({ rank, score, pokemon_id, form, costume, gender }) => {
const Icons = useMemory((s) => s.Icons)
return (
<TableRow>
Expand All @@ -882,6 +906,15 @@ const ShowcaseEntry = ({ rank, score }) => {
>
{score.toFixed(2)}
</NoBorderCell>
{pokemon_id && (
<NoBorderCell>
<img
src={Icons.getPokemon(pokemon_id, form, 0, gender, costume)}
alt="rank"
height={20}
/>
</NoBorderCell>
)}
</TableRow>
)
}
2 changes: 2 additions & 0 deletions src/hooks/useTranslateById.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export function useTranslateById(options = {}) {
// raid eggs
return i18n.t(`egg_${id.slice(1)}${plural ? '_plural' : ''}`)
case 'g':
case 'h':
return i18n.t(`poke_type_${id.slice(1)}`)
case 't':
// gyms
// teams
Expand Down
2 changes: 2 additions & 0 deletions src/services/Icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class UAssets {
case 'g':
// gyms
return this.getGyms(...id.slice(1).split('-'))
case 'h':
return this.getTypes(id.slice(1))
case 'i':
// invasions
return this.getInvasions(id.slice(1), true)
Expand Down
12 changes: 12 additions & 0 deletions src/services/filtering/genPokestops.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export default function genPokestops(pokemon, pokestops, categories) {
).toLowerCase()} ${t(`grunt_${id.slice(1)}`).toLowerCase()}`
}
break
case 'h':
if (tempObj.showcase) {
const name = t(`poke_type_${id.slice(1)}`)
tempObj.showcase[id] = {
name,
perms: ['eventStops'],
}
tempObj.showcase[id].searchMeta = `${t(
'showcase',
).toLowerCase()} ${name.toLowerCase()}`
}
break
case 'f':
if (tempObj.showcase) {
const name = t(`poke_${id.slice(1).split('-')[0]}`)
Expand Down
3 changes: 2 additions & 1 deletion src/services/functions/hasAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function checkIfHasAll(category, id) {
id.startsWith('l') ||
id.startsWith('i') ||
id.startsWith('f') ||
id.startsWith('a')
id.startsWith('a') ||
id.startsWith('h')
)) ||
(id.startsWith('t') && id !== 't0-0')
)
Expand Down
Loading

0 comments on commit da656ce

Please sign in to comment.