From c344b9ec6fe901ebd34ffd1f15cab3fcd96b86e4 Mon Sep 17 00:00:00 2001 From: RaenonX Date: Wed, 14 Jul 2021 10:25:35 -0500 Subject: [PATCH] ADD - Options to include/exclude dragon skills (#198) Signed-off-by: RaenonX --- .../elements/gameData/skillAtk/in/filter.tsx | 17 ++++++++++ .../elements/gameData/skillAtk/in/types.ts | 2 ++ .../gameData/skillAtk/in/utils/inputData.ts | 1 + .../skillAtk/out/utils/entries.test.tsx | 33 +++++++++++++++++++ .../gameData/skillAtk/out/utils/entries.ts | 5 +++ src/components/elements/input/entry.tsx | 1 + 6 files changed, 59 insertions(+) diff --git a/src/components/elements/gameData/skillAtk/in/filter.tsx b/src/components/elements/gameData/skillAtk/in/filter.tsx index 196974b5..a1ab942a 100644 --- a/src/components/elements/gameData/skillAtk/in/filter.tsx +++ b/src/components/elements/gameData/skillAtk/in/filter.tsx @@ -1,5 +1,6 @@ import React from 'react'; +import {UnitType} from '../../../../../api-def/api'; import {useI18n} from '../../../../../i18n/hook'; import {InputPanel} from '../../../input/main'; import {SectionProps, SectionPropsCondEnums, SectionPropsElemEnums} from './types'; @@ -51,6 +52,22 @@ export const Filter = ({ getValue: (inputData) => inputData.filter.afflictionCondCode, getUpdatedInputData: (newValue) => overwriteInputData(inputData, {filter: {afflictionCondCode: newValue}}), }, + { + type: 'subTitle', + title: t((t) => t.game.skillAtk.input.filter.unitType.name), + description: t((t) => t.game.skillAtk.input.filter.unitType.desc), + }, + { + type: 'arrayCheckGroup', + options: Object.keys(UnitType).filter((item) => !isNaN(+item)).map((item) => { + const code = +item as UnitType; + + return {text: t((t) => t.enum.unitType[code]), code}; + }), + getValue: (inputData) => inputData.filter.type, + getUpdatedInputData: (newValue) => overwriteInputData(inputData, {filter: {type: newValue}}), + getCheckOptionComparer: (option) => option.code, + }, { type: 'subTitle', title: t((t) => t.game.skillAtk.input.filter.other.name), diff --git a/src/components/elements/gameData/skillAtk/in/types.ts b/src/components/elements/gameData/skillAtk/in/types.ts index bc638e6c..cc6a7a9a 100644 --- a/src/components/elements/gameData/skillAtk/in/types.ts +++ b/src/components/elements/gameData/skillAtk/in/types.ts @@ -1,3 +1,4 @@ +import {UnitType} from '../../../../../api-def/api/other/unit'; import {CategorizedConditionEnums, ElementEnums} from '../../../../../api-def/resources/types/export/enums'; import {ConditionCodes} from '../../../../../const/gameData'; import {InputPanelCommonProps} from '../../../input/types'; @@ -64,6 +65,7 @@ export type InputData = { afflictionCondCode: Array, sharedOnly: boolean, dispelOnly: boolean, + type: Array, }, display: { actualDamage: boolean, diff --git a/src/components/elements/gameData/skillAtk/in/utils/inputData.ts b/src/components/elements/gameData/skillAtk/in/utils/inputData.ts index 9c241f39..39b387f4 100644 --- a/src/components/elements/gameData/skillAtk/in/utils/inputData.ts +++ b/src/components/elements/gameData/skillAtk/in/utils/inputData.ts @@ -124,6 +124,7 @@ export const generateInputData = (overwrite?: DeepPartial): InputData afflictionCondCode: [], sharedOnly: false, dispelOnly: false, + type: [], }, display: { actualDamage: false, diff --git a/src/components/elements/gameData/skillAtk/out/utils/entries.test.tsx b/src/components/elements/gameData/skillAtk/out/utils/entries.test.tsx index aac1c8d1..2f580db1 100644 --- a/src/components/elements/gameData/skillAtk/out/utils/entries.test.tsx +++ b/src/components/elements/gameData/skillAtk/out/utils/entries.test.tsx @@ -1,4 +1,5 @@ import {generateAttackingSkillEntry} from '../../../../../../../test/data/mock/skill'; +import {UnitType} from '../../../../../../api-def/api'; import {AttackingSkillData, ElementBonusData} from '../../../../../../api-def/resources'; import {ResourceLoader} from '../../../../../../utils/services/resources'; import {InputData} from '../../in/types'; @@ -54,6 +55,38 @@ describe('Filter ATK skill entries', () => { expect(dataFiltered.map((entry) => entry.skill.dispelMax)).not.toContain(false); }); + it('returns character skill only', async () => { + const dataFiltered = filterSkillEntries( + { + ...inputDataTemplate, + filter: { + ...inputDataTemplate.filter, + type: [UnitType.CHARACTER], + }, + }, + data, + ); + expect(dataFiltered.length).toBeGreaterThan(0); + expect(dataFiltered.map((entry) => entry.unit.type === UnitType.CHARACTER)).not.toContain(false); + expect(dataFiltered.map((entry) => entry.unit.type === UnitType.DRAGON)).not.toContain(true); + }); + + it('returns all types of skill', async () => { + const dataFiltered = filterSkillEntries( + { + ...inputDataTemplate, + filter: { + ...inputDataTemplate.filter, + type: [], + }, + }, + data, + ); + expect(dataFiltered.length).toBeGreaterThan(0); + expect(dataFiltered.map((entry) => entry.unit.type === UnitType.CHARACTER)).toBeTruthy(); + expect(dataFiltered.map((entry) => entry.unit.type === UnitType.DRAGON)).toBeTruthy(); + }); + it('returns specified element only', async () => { const elemEnums = await ResourceLoader.getEnumElements(); diff --git a/src/components/elements/gameData/skillAtk/out/utils/entries.ts b/src/components/elements/gameData/skillAtk/out/utils/entries.ts index 2b93a261..473c4fe2 100644 --- a/src/components/elements/gameData/skillAtk/out/utils/entries.ts +++ b/src/components/elements/gameData/skillAtk/out/utils/entries.ts @@ -17,6 +17,11 @@ export const filterSkillEntries = (inputData: InputData, atkSkillEntries: Array< atkSkillEntries = atkSkillEntries.filter((entry) => entry.skill.dispelMax); } + // Filter skill by unit type if set + if (inputData.filter.type.length) { + atkSkillEntries = atkSkillEntries.filter((entry) => inputData.filter.type.includes(entry.unit.type)); + } + // Filter element if specified if (inputData.filter.elemCodes.length) { atkSkillEntries = atkSkillEntries diff --git a/src/components/elements/input/entry.tsx b/src/components/elements/input/entry.tsx index 55a22bd0..9f77e052 100644 --- a/src/components/elements/input/entry.tsx +++ b/src/components/elements/input/entry.tsx @@ -3,6 +3,7 @@ import React from 'react'; import {EnumEntry} from '../../../api-def/resources'; import {EnumCheckboxGroup} from '../common/check/enum/checkbox'; import {EnumRadioGroup} from '../common/check/enum/radio'; +import {CheckboxGroup} from '../common/check/group/checkbox'; import {RadioGroup} from '../common/check/group/radio'; import {CheckboxInput} from '../common/check/item/checkbox'; import {CheckOption} from '../common/check/types';