From c15887402977dfd6dd9cdae032780563b645a2f3 Mon Sep 17 00:00:00 2001 From: GoneTone Date: Sat, 30 Jul 2022 22:11:20 +0800 Subject: [PATCH] Added enemies and monsters filters --- README.md | 1 + README_ZH-CN.md | 1 + README_ZH-TW.md | 1 + __tests__/filters/EnemyFilters.test.ts | 68 ++++++++++++++++++++++++++ src/filters/EnemyFilters.ts | 68 ++++++++++++++++++++++++++ src/index.ts | 1 + src/utils/api.ts | 2 + 7 files changed, 142 insertions(+) create mode 100644 __tests__/filters/EnemyFilters.test.ts create mode 100644 src/filters/EnemyFilters.ts diff --git a/README.md b/README.md index c56fd32..0436cd8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README_ZH-CN.md b/README_ZH-CN.md index a8b3fb8..b731ea0 100644 --- a/README_ZH-CN.md +++ b/README_ZH-CN.md @@ -30,6 +30,7 @@ const { CharacterFilters, // 角色过滤器 // WeaponFilters, // 武器过滤器 // ArtifactFilters, // 圣遗物过滤器 + // EnemyFilters, // 敌人与魔物过滤器 // MaterialFilters, // 提瓦特产物过滤器 setLanguage, Language diff --git a/README_ZH-TW.md b/README_ZH-TW.md index e0ae504..f669d0f 100644 --- a/README_ZH-TW.md +++ b/README_ZH-TW.md @@ -30,6 +30,7 @@ const { CharacterFilters, // 角色過濾器 // WeaponFilters, // 武器過濾器 // ArtifactFilters, // 聖遺物過濾器 + // EnemyFilters, // 敵人與魔物過濾器 // MaterialFilters, // 提瓦特產物過濾器 setLanguage, Language diff --git a/__tests__/filters/EnemyFilters.test.ts b/__tests__/filters/EnemyFilters.test.ts new file mode 100644 index 0000000..66fb311 --- /dev/null +++ b/__tests__/filters/EnemyFilters.test.ts @@ -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' + }) + }) + }) +}) diff --git a/src/filters/EnemyFilters.ts b/src/filters/EnemyFilters.ts new file mode 100644 index 0000000..498aca5 --- /dev/null +++ b/src/filters/EnemyFilters.ts @@ -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 { + 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' + } + } +} diff --git a/src/index.ts b/src/index.ts index 9a90a8f..02237f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' diff --git a/src/utils/api.ts b/src/utils/api.ts index 84438cb..307ff68 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -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({ @@ -55,6 +56,7 @@ export async function setLanguage (language: Language): Promise { await CharacterFilters.setFilterIds() await WeaponFilters.setFilterIds() await ArtifactFilters.setFilterIds() + await EnemyFilters.setFilterIds() await MaterialFilters.setFilterIds() }