Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

Commit

Permalink
ADD - Options to include/exclude dragon skills (#198)
Browse files Browse the repository at this point in the history
Signed-off-by: RaenonX <[email protected]>
  • Loading branch information
RaenonX committed Jul 14, 2021
1 parent 2e5fb28 commit c344b9e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/elements/gameData/skillAtk/in/filter.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/components/elements/gameData/skillAtk/in/types.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,6 +65,7 @@ export type InputData = {
afflictionCondCode: Array<number>,
sharedOnly: boolean,
dispelOnly: boolean,
type: Array<UnitType>,
},
display: {
actualDamage: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const generateInputData = (overwrite?: DeepPartial<InputData>): InputData
afflictionCondCode: [],
sharedOnly: false,
dispelOnly: false,
type: [],
},
display: {
actualDamage: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/components/elements/input/entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit c344b9e

Please sign in to comment.