Skip to content

Commit

Permalink
Added enemies and monsters filters
Browse files Browse the repository at this point in the history
  • Loading branch information
GoneTone committed Jul 30, 2022
1 parent a62b01c commit c158874
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
CharacterFilters, // Character Filters
// WeaponFilters, // Weapons Filters
// ArtifactFilters, // Artifacts Filters
// EnemyFilters, // Enemies and Monsters Filters
// MaterialFilters, // Teyvat's Resources Filters
setLanguage,
Language
Expand Down
1 change: 1 addition & 0 deletions README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
CharacterFilters, // 角色过滤器
// WeaponFilters, // 武器过滤器
// ArtifactFilters, // 圣遗物过滤器
// EnemyFilters, // 敌人与魔物过滤器
// MaterialFilters, // 提瓦特产物过滤器
setLanguage,
Language
Expand Down
1 change: 1 addition & 0 deletions README_ZH-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
CharacterFilters, // 角色過濾器
// WeaponFilters, // 武器過濾器
// ArtifactFilters, // 聖遺物過濾器
// EnemyFilters, // 敵人與魔物過濾器
// MaterialFilters, // 提瓦特產物過濾器
setLanguage,
Language
Expand Down
68 changes: 68 additions & 0 deletions __tests__/filters/EnemyFilters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2020-2022 原神資訊站 Genshin Impact Info
* https://genshininfo.reh.tw/
*
* Developed by 旋風之音 GoneTone
* https://github.com/GoneTone
*
* _oo0oo_
* o8888888o
* 88" . "88
* (| -_- |)
* 0\ = /0
* ___/`---'\___
* .' \\| |# '.
* / \\||| : |||# \
* / _||||| -:- |||||- \
* | | \\\ - #/ | |
* | \_| ''\---/'' |_/ |
* \ .-\__ '-' ___/-. /
* ___'. .' /--.--\ `. .'___
* ."" '< `.___\_<|>_/___.' >' "".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `_. \_ __\ /__ _/ .-` / /
* =====`-.____`.___ \_____/___.-`___.-'=====
* `=---='
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 佛祖保佑 永無 BUG
*
* GitHub: https://github.com/GoneTone/node-hoyowiki-api
*/

import { EnemyFilters, setLanguage, Language } from '../../src'

describe('Material Filters', () => {
describe('Material Filters Default Data', () => {
test('Valid "Type" material filters data', () => {
expect(EnemyFilters.Type).toStrictEqual({
OtherHumanFactions: '1307',
Automatons: '1326',
Fatui: '1329',
EnemiesOfNote: '1345',
Hilichurls: '1359',
ElementalLifeforms: '1368',
TheAbyss: '1381',
MysticalBeasts: '1402'
})
})
})

describe('Material Filters Data, Set Language "ChineseTW"', () => {
test('Set language "ChineseTW"', async () => {
await setLanguage(Language.ChineseTW)
})

test('Valid "Type" material filters data, set language "ChineseTW"', () => {
expect(EnemyFilters.Type).toStrictEqual({
OtherHumanFactions: '1313',
Automatons: '1314',
Fatui: '1328',
EnemiesOfNote: '1344',
Hilichurls: '1354',
ElementalLifeforms: '1367',
TheAbyss: '1388',
MysticalBeasts: '1401'
})
})
})
})
68 changes: 68 additions & 0 deletions src/filters/EnemyFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2020-2022 原神資訊站 Genshin Impact Info
* https://genshininfo.reh.tw/
*
* Developed by 旋風之音 GoneTone
* https://github.com/GoneTone
*
* _oo0oo_
* o8888888o
* 88" . "88
* (| -_- |)
* 0\ = /0
* ___/`---'\___
* .' \\| |# '.
* / \\||| : |||# \
* / _||||| -:- |||||- \
* | | \\\ - #/ | |
* | \_| ''\---/'' |_/ |
* \ .-\__ '-' ___/-. /
* ___'. .' /--.--\ `. .'___
* ."" '< `.___\_<|>_/___.' >' "".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `_. \_ __\ /__ _/ .-` / /
* =====`-.____`.___ \_____/___.-`___.-'=====
* `=---='
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 佛祖保佑 永無 BUG
*
* GitHub: https://github.com/GoneTone/node-hoyowiki-api
*/

import { axiosInstance } from '../utils/api'
import { EntryPageMenu } from '../utils/constants'
import type * as MenuFiltersAPIInterface from '../interfaces/MenuFiltersAPIInterface'

export class EnemyFilters {
public static Type = {
OtherHumanFactions: '1307',
Automatons: '1326',
Fatui: '1329',
EnemiesOfNote: '1345',
Hilichurls: '1359',
ElementalLifeforms: '1368',
TheAbyss: '1381',
MysticalBeasts: '1402'
}

public static async setFilterIds (): Promise<void> {
const response = await axiosInstance.get('/get_menu_filters', {
params: {
menu_id: EntryPageMenu.Enemy
}
})

const filters: MenuFiltersAPIInterface.Filter[] = response.data.data.filters

this.Type = {
OtherHumanFactions: filters[0]?.values[0]?.id ?? '1307',
Automatons: filters[0]?.values[1]?.id ?? '1326',
Fatui: filters[0]?.values[2]?.id ?? '1329',
EnemiesOfNote: filters[0]?.values[3]?.id ?? '1345',
Hilichurls: filters[0]?.values[4]?.id ?? '1359',
ElementalLifeforms: filters[0]?.values[5]?.id ?? '1368',
TheAbyss: filters[0]?.values[6]?.id ?? '1381',
MysticalBeasts: filters[0]?.values[7]?.id ?? '1402'
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export * from './search/Search'
export * from './filters/CharacterFilters'
export * from './filters/WeaponFilters'
export * from './filters/ArtifactFilters'
export * from './filters/EnemyFilters'
export * from './filters/MaterialFilters'

export * from './utils/api'
Expand Down
2 changes: 2 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { DefaultApiOptions, Language } from './constants'
import { CharacterFilters } from '../filters/CharacterFilters'
import { WeaponFilters } from '../filters/WeaponFilters'
import { ArtifactFilters } from '../filters/ArtifactFilters'
import { EnemyFilters } from '../filters/EnemyFilters'
import { MaterialFilters } from '../filters/MaterialFilters'

export const axiosInstance = axios.create({
Expand All @@ -55,6 +56,7 @@ export async function setLanguage (language: Language): Promise<void> {
await CharacterFilters.setFilterIds()
await WeaponFilters.setFilterIds()
await ArtifactFilters.setFilterIds()
await EnemyFilters.setFilterIds()
await MaterialFilters.setFilterIds()
}

Expand Down

0 comments on commit c158874

Please sign in to comment.