Skip to content

Commit

Permalink
fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed Jan 23, 2024
1 parent 8848863 commit b679c92
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
27 changes: 24 additions & 3 deletions src/components/combat/stance-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,32 @@ import Typography from "@mui/material/Typography";
import { useHero } from "src/hooks/use-hero";
import { HeroStance } from "src/generated/graphql";

const stanceDescriptions: { [x in HeroStance]?: string } = {
const stanceDescriptions: { [x in HeroStance]: string } = {
[HeroStance.Normal]: "Normal stance with no pros or cons.",

[HeroStance.Combat]: "???",
[HeroStance.Reckless]: "???",
[HeroStance.Aggressive]: "???",
[HeroStance.Defensive]: "???",
[HeroStance.NecroticBeam]: "???",
[HeroStance.CloudofKnives]: "???",
[HeroStance.FrozenOrb]: "???",
[HeroStance.MageArmor]: "???",
[HeroStance.NormalArrow]: "???",
[HeroStance.BarbedArrow]: "???",
[HeroStance.BloodHunter]: "???",
[HeroStance.DarkPresence]: "???",
[HeroStance.AuraoftheLifeless]: "???",
[HeroStance.ShieldSmash]: "???",
[HeroStance.ShieldSlash]: "???",
[HeroStance.HolySmite]: "???",
[HeroStance.VengefulSmite]: "???",
[HeroStance.WarriorsStance]: "???",
[HeroStance.Hexblade]: "???",
[HeroStance.Focus]: "???",
};

export function StanceSelector(): JSX.Element {
export function StanceSelector(): JSX.Element | null {
const hero = useHero();

if (!hero) {
Expand All @@ -23,7 +44,7 @@ export function StanceSelector(): JSX.Element {
tooltip: stanceDescriptions[stance],
}));

function handleChangeStance(stance) {
function handleChangeStance(stance: HeroStance) {
console.log("Setting stance to", stance, hero);
}

Expand Down
20 changes: 13 additions & 7 deletions src/game/crafting/destroy-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Hero,
InventoryItemType,
useDestroyItemMutation,
EnchantmentType,
} from "src/generated/graphql";

import {
Expand Down Expand Up @@ -54,13 +55,18 @@ export function DestroyItems({
)
.sort(itemSorter);

const destroyableEnchantments: EnchantmentType[] = [
...new Set(
destroyableItems
.filter((item) => !isItemEquipped(hero, item))
.map((item) => item.enchantment),
),
];
const destroyableEnchantments: EnchantmentType[] = destroyableItems
.filter((item) => !isItemEquipped(hero, item))
.map((item) => item.enchantment)
.reduce<EnchantmentType[]>((memo, item) => {
if (!item) {
return memo;
}
if (memo.indexOf(item) < 0) {
memo.push(item);
}
return memo;
}, []);

const label = "Select item to destroy";

Expand Down
20 changes: 13 additions & 7 deletions src/game/crafting/disenchant-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Hero,
InventoryItemType,
useDisenchantItemMutation,
EnchantmentType,
} from "src/generated/graphql";

import {
Expand Down Expand Up @@ -54,13 +55,18 @@ export function DisenchantItems({
)
.sort(itemSorter);

const destroyableEnchantments: EnchantmentType[] = [
...new Set(
disenchantableItems
.filter((item) => !isItemEquipped(hero, item))
.map((item) => item.enchantment),
),
];
const destroyableEnchantments: EnchantmentType[] = disenchantableItems
.filter((item) => !isItemEquipped(hero, item))
.map((item) => item.enchantment)
.reduce<EnchantmentType[]>((memo, item) => {
if (!item) {
return memo;
}
if (memo.indexOf(item) < 0) {
memo.push(item);
}
return memo;
}, []);

let selectedItem = filteredItems.find((item) => item.id === value);

Expand Down
10 changes: 5 additions & 5 deletions src/game/crafting/enchant-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export function EnchantItems({
})

.sort(itemSorter);
const enchantmentsFound: { [x in EnchantmentType]?: number } = {};
const enchantmentsFound = {} as { [x in EnchantmentType]: number };
const enchantments: EnchantmentType[] = [...hero.enchantments]
.sort()
.filter((ench) => {
if (enchantmentsFound[ench]) {
enchantmentsFound[ench]++;
enchantmentsFound[ench] = (enchantmentsFound[ench] ?? 0) + 1;
return false;
}
enchantmentsFound[ench] = 1;
Expand Down Expand Up @@ -159,9 +159,9 @@ export function EnchantItems({
return (
<MenuItem key={ench} value={ench}>
{pureEnchantmentDisplayName(ench)}{" "}
{enchantmentsFound[ench] > 1
? `(${enchantmentsFound[ench]})`
: ""}
{enchantmentsFound[ench] &&
enchantmentsFound[ench] > 1 &&
`(${enchantmentsFound[ench]})`}
{getEnchantmentDisplay(ench) !== "???" && (
<Typography
variant="subtitle2"
Expand Down

0 comments on commit b679c92

Please sign in to comment.