Skip to content

Commit

Permalink
feat: station support
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Sep 4, 2024
1 parent 62cb35c commit 1447196
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"@commitlint/cli": "^19.4.1",
"@commitlint/config-conventional": "^19.4.1",
"@na-ji/pogo-protos": "^2.149.0",
"@na-ji/pogo-protos": "^2.151.0",
"@rollup/plugin-typescript": "^11.1.6",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface UiconsIndex<T extends string[] = string[]> {
}
reward?: { [key in RewardTypeKeys]?: T }
spawnpoint?: T
station?: T
team?: T
type?: T
weather?: T
Expand Down
6 changes: 6 additions & 0 deletions src/uicons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ describe('spawnpoint', () => {
})
})

describe('stations', () => {
test('0.ext', () => {
expect(icons.station()).toBe(`${BASE_ICON_URL}/station/0.webp`)
})
})

describe('team', () => {
test('instinct', () => {
expect(icons.team(3)).toBe(`${BASE_ICON_URL}/team/3.webp`)
Expand Down
56 changes: 42 additions & 14 deletions src/uicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
#raid: { egg: Set<Index['raid']['egg'][number]> }
#reward: { [key in RewardTypeKeys]?: Set<Index['reward'][key][number]> }
#spawnpoint: Set<Index['spawnpoint'][number]>
#station: Set<Index['station'][number]>
#team: Set<Index['team'][number]>
#type: Set<Index['type'][number]>
#weather: Set<Index['weather'][number]>
Expand Down Expand Up @@ -110,8 +111,10 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
)
}

#isReady() {
#isReady(key?: keyof ExtensionMap): boolean {
if (!this.#extensionMap) throw new Error('UICONS not initialized')
if (key && !this.#extensionMap[key]) return false
return true
}

/**
Expand Down Expand Up @@ -148,6 +151,7 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
.map(([k, v]) => [k, new Set(v)])
)
this.#spawnpoint = new Set(data.spawnpoint || [])
this.#station = new Set(data.station || [])
this.#team = new Set(data.team || [])
this.#type = new Set(data.type || [])
this.#weather = new Set(data.weather || [])
Expand Down Expand Up @@ -191,6 +195,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
return this.#spawnpoint.has(
`${fileName}.${this.#extensionMap.spawnpoint}`
)
case 'station':
return this.#station.has(`${fileName}.${this.#extensionMap.station}`)
case 'team':
return this.#team.has(`${fileName}.${this.#extensionMap.team}`)
case 'type':
Expand All @@ -207,7 +213,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
* @returns the src of the device icon
*/
device(online = false): string {
this.#isReady()
if (!this.#isReady('device')) return ''

return online && this.#device.has(`1.${this.#extensionMap.device}`)
? `${this.#path}/device/1.${this.#extensionMap.device}`
: `${this.#path}/device/0.${this.#extensionMap.device}`
Expand Down Expand Up @@ -242,7 +249,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
ex = false,
ar = false
): string {
this.#isReady()
if (!this.#isReady('gym')) return ''

const baseUrl = `${this.#path}/gym`

const trainerSuffixes = trainerCount ? [`_t${trainerCount}`, ''] : ['']
Expand Down Expand Up @@ -277,7 +285,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
): string
invasion(gruntId?: string | number, confirmed?: boolean): string
invasion(gruntId = 0, confirmed = false): string {
this.#isReady()
if (!this.#isReady('invasion')) return ''

const baseUrl = `${this.#path}/invasion`

const confirmedSuffixes = confirmed ? [''] : ['_u', '']
Expand All @@ -297,7 +306,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
* @returns the src of the misc icon
*/
misc(fileName?: string | number): string {
this.#isReady()
if (!this.#isReady('misc')) return ''

const baseUrl = `${this.#path}/misc`

if (this.#misc.has(`${fileName}.${this.#extensionMap.misc}`)) {
Expand All @@ -313,7 +323,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
nest(typeId?: EnumVal<typeof Rpc.HoloPokemonType>): string
nest(typeId?: string | number): string
nest(typeId = 0): string {
this.#isReady()
if (!this.#isReady('nest')) return ''

const baseUrl = `${this.#path}/nest`

const result = `${typeId}.${this.#extensionMap.nest}`
Expand Down Expand Up @@ -360,7 +371,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
alignment = 0,
shiny = false
): string {
this.#isReady()
if (!this.#isReady('pokemon')) return ''

const baseUrl = `${this.#path}/pokemon`

const evolutionSuffixes = evolution ? [`_e${evolution}`, ''] : ['']
Expand Down Expand Up @@ -426,7 +438,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
questActive = false,
ar = false
): string {
this.#isReady()
if (!this.#isReady('pokestop')) return ''

const baseUrl = `${this.#path}/pokestop`

const invasionSuffixes =
Expand Down Expand Up @@ -465,7 +478,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
): string
raidEgg(level?: string | number, hatched?: boolean, ex?: boolean): string
raidEgg(level = 0, hatched = false, ex = false): string {
this.#isReady()
if (!this.#isReady('raid')) return ''

const baseUrl = `${this.#path}/raid/egg`

const hatchedSuffixes = hatched ? ['_h', ''] : ['']
Expand Down Expand Up @@ -503,7 +517,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
rewardId = 0,
amount = 0
): string {
this.#isReady()
if (!this.#isReady('reward')) return ''

const baseUrl = `${this.#path}/reward/${questRewardType}`
const rewardSet = this.#reward[questRewardType]
if (!rewardSet) {
Expand Down Expand Up @@ -534,20 +549,31 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
* @returns the src of the spawnpoint icon
*/
spawnpoint(hasTth = false): string {
this.#isReady()
if (!this.#isReady('spawnpoint')) return ''

return hasTth && this.#spawnpoint.has(`1.${this.#extensionMap.spawnpoint}`)
? `${this.#path}/spawnpoint/1.${this.#extensionMap.spawnpoint}`
: `${this.#path}/spawnpoint/0.${this.#extensionMap.spawnpoint}`
}

/**
* @returns the src of the station icon
*/
station(): string {
if (!this.#isReady('station')) return ''

return `${this.#path}/station/0.${this.#extensionMap.station}`
}

/**
* @param teamId the team ID, @see Rpc.Team
* @returns the src of the team icon
*/
team(teamId?: EnumVal<typeof Rpc.Team>): string
team(teamId?: string | number): string
team(teamId = 0): string {
this.#isReady()
if (!this.#isReady('team')) return ''

const baseUrl = `${this.#path}/team`

const result = `${teamId}.${this.#extensionMap.team}`
Expand All @@ -564,7 +590,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
type(typeId?: EnumVal<typeof Rpc.HoloPokemonType>): string
type(typeId?: string | number): string
type(typeId = 0): string {
this.#isReady()
if (!this.#isReady('type')) return ''

const baseUrl = `${this.#path}/type`

const result = `${typeId}.${this.#extensionMap.type}`
Expand All @@ -585,7 +612,8 @@ export class UICONS<Index extends UiconsIndex = UiconsIndex> {
): string
weather(weatherId?: string | number, timeOfDay?: string): string
weather(weatherId = 0, timeOfDay = 'day'): string {
this.#isReady()
if (!this.#isReady('weather')) return ''

const baseUrl = `${this.#path}/weather`

const timeSuffixes = timeOfDay === 'night' ? ['_n', ''] : ['_d', '']
Expand Down

0 comments on commit 1447196

Please sign in to comment.