Skip to content

Commit

Permalink
Use a consistent sort order for skills.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 0a44628893431e14428ded65bf153e5de7a9c482
  • Loading branch information
cpojer committed Oct 28, 2024
1 parent e0d070a commit 2742812
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
6 changes: 3 additions & 3 deletions athena/info/Skill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export const Skills = new Set<Skill>([
Skill.UnitRailDefenseIncreasePowerAttackIncrease,
Skill.Sabotage,
Skill.VampireHeal,
Skill.Shield,
Skill.Charge,
Skill.RecoverAirUnits,
Skill.BuyUnitBrute,
Skill.BuyUnitSuperAPU,
Expand All @@ -90,10 +88,12 @@ export const Skills = new Set<Skill>([
Skill.BuyUnitAIU,
Skill.UnlockZombie,
Skill.UnlockPowerStation,
Skill.Shield,
Skill.Charge,
Skill.SpawnUnitInfernoJetpack,
Skill.AttackAndDefenseDecreaseEasy,
Skill.AttackAndDefenseIncreaseHard,
Skill.NoUnitRestrictions,
Skill.SpawnUnitInfernoJetpack,
]);

const skillConfig: Record<
Expand Down
12 changes: 12 additions & 0 deletions hera/hooks/useSkills.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Skills } from '@deities/athena/info/Skill.tsx';
import { useMemo } from 'react';

export default function useSkills(
skills: ReadonlyArray<number> | null | undefined,
) {
return useMemo(() => {
const currentSkills = new Set(skills);
// Skills should always be sorted by the internal sort order.
return new Set([...Skills].filter((skill) => currentSkills.has(skill)));
}, [skills]);
}
27 changes: 9 additions & 18 deletions hera/ui/SkillDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {
Skills as AllSkills,
getSkillConfig,
Skill,
} from '@deities/athena/info/Skill.tsx';
import { getSkillConfig, Skill } from '@deities/athena/info/Skill.tsx';
import { TileSize } from '@deities/athena/map/Configuration.tsx';
import groupBy from '@deities/hephaestus/groupBy.tsx';
import sortBy from '@deities/hephaestus/sortBy.tsx';
import AudioPlayer from '@deities/ui/AudioPlayer.tsx';
import Breakpoints from '@deities/ui/Breakpoints.tsx';
import { ButtonStyle, SquareButtonStyle } from '@deities/ui/Button.tsx';
Expand Down Expand Up @@ -263,18 +258,14 @@ export function SkillContainer({
toggleBlocklist?: boolean;
}) {
const hasAction = onAction && actionName && currentSkill;
const partition = groupBy(
availableSkills === AllSkills
? availableSkills
: sortBy([...availableSkills], (skill) => skill),
(skill) =>
selectedSkills?.has(skill)
? 'selected'
: !blocklistedAreDisabled &&
!toggleBlocklist &&
initialBlocklistedSkills?.has(skill)
? 'disabled'
: 'enabled',
const partition = groupBy(availableSkills, (skill) =>
selectedSkills?.has(skill)
? 'selected'
: !blocklistedAreDisabled &&
!toggleBlocklist &&
initialBlocklistedSkills?.has(skill)
? 'disabled'
: 'enabled',
);
const enabledSkills = partition.get('enabled');
const disabledSkills = partition.get('disabled');
Expand Down

0 comments on commit 2742812

Please sign in to comment.