Skip to content

Commit

Permalink
Add grouping to skills.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 9f383c71d46962bbbd64444bec1508750d7f1f00
  • Loading branch information
cpojer committed Oct 28, 2024
1 parent 2742812 commit b82232c
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 36 deletions.
156 changes: 123 additions & 33 deletions athena/info/Skill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,76 +96,166 @@ export const Skills = new Set<Skill>([
Skill.NoUnitRestrictions,
]);

export enum SkillGroup {
Attack = 1,
Defense = 2,
Unlock = 3,
Special = 4,
Invasion = 5,
AI = 6,
}

const skillConfig: Record<
Skill,
Readonly<{
activateOnInvasion?: true;
campaignOnly?: true;
charges?: number;
cost: number | null;
group: SkillGroup;
requiresCrystal?: true;
}>
> = {
[Skill.AttackIncreaseMinor]: { charges: 3, cost: 300 },
[Skill.DefenseIncreaseMinor]: { charges: 2, cost: 300 },
[Skill.AttackIncreaseMajorDefenseDecreaseMajor]: { charges: 6, cost: 800 },
[Skill.BuyUnitCannon]: { cost: 1000 },
[Skill.BuyUnitBrute]: { charges: 5, cost: 1000 },
[Skill.AttackIncreaseMinor]: {
charges: 3,
cost: 300,
group: SkillGroup.Attack,
},
[Skill.DefenseIncreaseMinor]: {
charges: 2,
cost: 300,
group: SkillGroup.Defense,
},
[Skill.AttackIncreaseMajorDefenseDecreaseMajor]: {
charges: 6,
cost: 800,
group: SkillGroup.Attack,
},
[Skill.BuyUnitCannon]: { cost: 1000, group: SkillGroup.Unlock },
[Skill.BuyUnitBrute]: { charges: 5, cost: 1000, group: SkillGroup.Unlock },
[Skill.DecreaseUnitCostAttackAndDefenseDecreaseMinor]: {
charges: 3,
cost: 600,
group: SkillGroup.Special,
},
[Skill.UnitAbilitySniperImmediateAction]: {
campaignOnly: true,
charges: 3,
cost: 2000,
group: SkillGroup.Special,
},
[Skill.MovementIncreaseGroundUnitDefenseDecrease]: {
charges: 2,
cost: 2500,
group: SkillGroup.Defense,
},
[Skill.UnitBattleShipMoveAndAct]: {
charges: 5,
cost: 2000,
group: SkillGroup.Special,
},
[Skill.BuyUnitSuperAPU]: { charges: 3, cost: 3000, group: SkillGroup.Unlock },
[Skill.BuyUnitZombieDefenseDecreaseMajor]: {
cost: 1500,
group: SkillGroup.Unlock,
},
[Skill.BuyUnitBazookaBear]: {
charges: 6,
cost: 2000,
group: SkillGroup.Unlock,
},
[Skill.AttackAndDefenseIncreaseHard]: {
cost: null,
group: SkillGroup.AI,
},
[Skill.HealVehiclesAttackDecrease]: {
charges: 3,
cost: 1000,
group: SkillGroup.Special,
},
[Skill.ArtilleryRangeIncrease]: {
charges: 3,
cost: 1500,
group: SkillGroup.Defense,
},
[Skill.HealInfantryMedicPower]: {
charges: 4,
cost: 1000,
group: SkillGroup.Attack,
},
[Skill.NoUnitRestrictions]: { cost: null, group: SkillGroup.AI },
[Skill.CounterAttackPower]: {
charges: 3,
cost: 1500,
group: SkillGroup.Special,
},
[Skill.AttackAndDefenseDecreaseEasy]: {
cost: null,
group: SkillGroup.AI,
},
[Skill.MovementIncreaseGroundUnitDefenseDecrease]: { charges: 2, cost: 2500 },
[Skill.UnitBattleShipMoveAndAct]: { charges: 5, cost: 2000 },
[Skill.BuyUnitSuperAPU]: { charges: 3, cost: 3000 },
[Skill.BuyUnitZombieDefenseDecreaseMajor]: { cost: 1500 },
[Skill.BuyUnitBazookaBear]: { charges: 6, cost: 2000 },
[Skill.AttackAndDefenseIncreaseHard]: { cost: null },
[Skill.HealVehiclesAttackDecrease]: { charges: 3, cost: 1000 },
[Skill.ArtilleryRangeIncrease]: { charges: 3, cost: 1500 },
[Skill.HealInfantryMedicPower]: { charges: 4, cost: 1000 },
[Skill.NoUnitRestrictions]: { cost: null },
[Skill.CounterAttackPower]: { charges: 3, cost: 1500 },
[Skill.AttackAndDefenseDecreaseEasy]: { cost: null },
[Skill.UnitInfantryForestAttackAndDefenseIncrease]: {
charges: 3,
cost: 2000,
group: SkillGroup.Attack,
},
[Skill.UnitRailDefenseIncreasePowerAttackIncrease]: {
charges: 4,
cost: 1500,
group: SkillGroup.Defense,
},
[Skill.BuyUnitAIU]: { cost: 1500, group: SkillGroup.Unlock },
[Skill.BuyUnitCommander]: {
charges: 4,
cost: 1500,
group: SkillGroup.Unlock,
},
[Skill.RecoverAirUnits]: {
charges: 5,
cost: 3000,
group: SkillGroup.Special,
},
[Skill.BuyUnitAlien]: { charges: 4, cost: 1500, group: SkillGroup.Unlock },
[Skill.BuyUnitOctopus]: { charges: 5, cost: 1500, group: SkillGroup.Unlock },
[Skill.BuyUnitSuperTank]: {
charges: 4,
cost: 1500,
group: SkillGroup.Unlock,
},
[Skill.BuyUnitAcidBomber]: {
charges: 3,
cost: 1500,
group: SkillGroup.Unlock,
},
[Skill.BuyUnitAIU]: { cost: 1500 },
[Skill.BuyUnitCommander]: { charges: 4, cost: 1500 },
[Skill.RecoverAirUnits]: { charges: 5, cost: 3000 },
[Skill.BuyUnitAlien]: { charges: 4, cost: 1500 },
[Skill.BuyUnitOctopus]: { charges: 5, cost: 1500 },
[Skill.BuyUnitSuperTank]: { charges: 4, cost: 1500 },
[Skill.BuyUnitAcidBomber]: { charges: 3, cost: 1500 },
[Skill.BuyUnitDinosaur]: { cost: 1500 },
[Skill.Sabotage]: { charges: 5, cost: 1500 },
[Skill.BuyUnitDinosaur]: { cost: 1500, group: SkillGroup.Unlock },
[Skill.Sabotage]: { charges: 5, cost: 1500, group: SkillGroup.Attack },
[Skill.SpawnUnitInfernoJetpack]: {
activateOnInvasion: true,
charges: 5,
cost: null,
group: SkillGroup.Invasion,
requiresCrystal: true,
},
[Skill.UnlockZombie]: { charges: 10, cost: 1500 },
[Skill.UnlockPowerStation]: { charges: 4, cost: 600 },
[Skill.BuyUnitDragon]: { charges: 5, cost: 1500 },
[Skill.BuyUnitOgre]: { charges: 3, cost: 1500 },
[Skill.BuyUnitBear]: { charges: 3, cost: 1500 },
[Skill.VampireHeal]: { charges: 5, cost: 1000 },
[Skill.Shield]: { activateOnInvasion: true, charges: 6, cost: 1500 },
[Skill.UnlockZombie]: { charges: 10, cost: 1500, group: SkillGroup.Special },
[Skill.UnlockPowerStation]: {
charges: 4,
cost: 600,
group: SkillGroup.Unlock,
},
[Skill.BuyUnitDragon]: { charges: 5, cost: 1500, group: SkillGroup.Unlock },
[Skill.BuyUnitOgre]: { charges: 3, cost: 1500, group: SkillGroup.Unlock },
[Skill.BuyUnitBear]: { charges: 3, cost: 1500, group: SkillGroup.Unlock },
[Skill.VampireHeal]: { charges: 5, cost: 1000, group: SkillGroup.Special },
[Skill.Shield]: {
activateOnInvasion: true,
charges: 6,
cost: 1500,
group: SkillGroup.Invasion,
},
[Skill.Charge]: {
activateOnInvasion: true,
charges: 6,
cost: 1500,
group: SkillGroup.Invasion,
requiresCrystal: true,
},
};
Expand Down
91 changes: 88 additions & 3 deletions hera/ui/SkillDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getSkillConfig, Skill } from '@deities/athena/info/Skill.tsx';
import {
getSkillConfig,
Skill,
SkillGroup,
} from '@deities/athena/info/Skill.tsx';
import { TileSize } from '@deities/athena/map/Configuration.tsx';
import groupBy from '@deities/hephaestus/groupBy.tsx';
import AudioPlayer from '@deities/ui/AudioPlayer.tsx';
Expand Down Expand Up @@ -31,7 +35,14 @@ import Stack from '@deities/ui/Stack.tsx';
import { css, cx } from '@emotion/css';
import Coin from '@iconify-icons/pixelarticons/coin.js';
import { Sprites } from 'athena-crisis:images';
import { ReactElement, ReactNode, useCallback, useRef, useState } from 'react';
import {
ReactElement,
ReactNode,
useCallback,
useMemo,
useRef,
useState,
} from 'react';
import getSkillConfigForDisplay from '../lib/getSkillConfigForDisplay.tsx';
import SkillDescription from './SkillDescription.tsx';

Expand Down Expand Up @@ -228,7 +239,7 @@ export default function SkillDialog({

export function SkillContainer({
actionName,
availableSkills,
availableSkills: initialAvailableSkills,
blocklistedAreDisabled,
blocklistedSkills: initialBlocklistedSkills,
canAction,
Expand Down Expand Up @@ -258,6 +269,24 @@ export function SkillContainer({
toggleBlocklist?: boolean;
}) {
const hasAction = onAction && actionName && currentSkill;
const [group, setGroup] = useState<SkillGroup | 'all'>('all');
const [availableSkills, skillGroups] = useMemo(() => {
const availableSkills =
group === 'all'
? initialAvailableSkills
: new Set(
[...initialAvailableSkills].filter(
(skill) => getSkillConfig(skill).group === group,
),
);
return [
availableSkills,
new Set(
[...initialAvailableSkills].map((skill) => getSkillConfig(skill).group),
),
] as const;
}, [group, initialAvailableSkills]);

const partition = groupBy(availableSkills, (skill) =>
selectedSkills?.has(skill)
? 'selected'
Expand Down Expand Up @@ -335,6 +364,62 @@ export function SkillContainer({
)}
</h1>
)}
<Stack gap={16} nowrap>
<InlineLink
onClick={() => setGroup('all')}
selectedText={group === 'all'}
>
<fbt desc="View all skills">All</fbt>
</InlineLink>
{skillGroups.has(SkillGroup.Attack) && (
<InlineLink
onClick={() => setGroup(SkillGroup.Attack)}
selectedText={group === SkillGroup.Attack}
>
<fbt desc="Filter by attack-based skills">Attack</fbt>
</InlineLink>
)}
{skillGroups.has(SkillGroup.Defense) && (
<InlineLink
onClick={() => setGroup(SkillGroup.Defense)}
selectedText={group === SkillGroup.Defense}
>
<fbt desc="Filter by defense-based skills">Defense</fbt>
</InlineLink>
)}
{skillGroups.has(SkillGroup.Unlock) && (
<InlineLink
onClick={() => setGroup(SkillGroup.Unlock)}
selectedText={group === SkillGroup.Unlock}
>
<fbt desc="Filter by unlock-based skills">Unlock</fbt>
</InlineLink>
)}
{skillGroups.has(SkillGroup.Special) && (
<InlineLink
onClick={() => setGroup(SkillGroup.Special)}
selectedText={group === SkillGroup.Special}
>
<fbt desc="Filter by special-based skills">Special</fbt>
</InlineLink>
)}
{skillGroups.has(SkillGroup.Invasion) && (
<InlineLink
onClick={() => setGroup(SkillGroup.Invasion)}
selectedText={group === SkillGroup.Invasion}
>
<fbt desc="Filter by invasion-based skills">Invasion</fbt>
</InlineLink>
)}
{skillGroups.has(SkillGroup.AI) && (
<InlineLink
onClick={() => setGroup(SkillGroup.AI)}
selectedText={group === SkillGroup.AI}
>
<fbt desc="Filter by AI-based skills">AI</fbt>
</InlineLink>
)}
</Stack>
<Stack gap vertical>
{enabledSkills?.map((skill, index) => (
<SkillListItem
Expand Down

0 comments on commit b82232c

Please sign in to comment.