Skip to content

Commit

Permalink
improvements and effects in crafting menu
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed Jan 23, 2024
1 parent 57fae48 commit 8848863
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
18 changes: 16 additions & 2 deletions src/game/crafting/destroy-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
isItemEquipped,
itemSorter,
itemImprovesCrafting,
EnchantmentNames,
pureEnchantmentDisplayName,
getEnchantmentDisplay,
} from "src/helpers";

export function DestroyItems({
Expand Down Expand Up @@ -118,6 +119,11 @@ export function DestroyItems({
>
{itemDisplayName(item)}{" "}
{isItemEquipped(hero, item) && "*EQUIPPED*"}
{item.enchantment && (
<Typography variant="subtitle2" sx={{ color: "info.main" }}>
&nbsp;{getEnchantmentDisplay(item.enchantment)}
</Typography>
)}
</MenuItem>
);
})}
Expand Down Expand Up @@ -162,7 +168,15 @@ export function DestroyItems({
{destroyableEnchantments.map((enchantment) => {
return (
<MenuItem key={enchantment} value={enchantment}>
{EnchantmentNames[enchantment]}
{pureEnchantmentDisplayName(enchantment)}
{getEnchantmentDisplay(enchantment) !== "???" && (
<Typography
variant="subtitle2"
sx={{ color: "primary.main" }}
>
&nbsp;{getEnchantmentDisplay(enchantment)}
</Typography>
)}
</MenuItem>
);
})}
Expand Down
18 changes: 16 additions & 2 deletions src/game/crafting/disenchant-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
isItemEquipped,
itemSorter,
itemImprovesCrafting,
EnchantmentNames,
pureEnchantmentDisplayName,
getEnchantmentDisplay,
} from "src/helpers";

export function DisenchantItems({
Expand Down Expand Up @@ -119,6 +120,11 @@ export function DisenchantItems({
>
{itemDisplayName(item)}{" "}
{isItemEquipped(hero, item) && "*EQUIPPED*"}
{item.enchantment && (
<Typography variant="subtitle2" sx={{ color: "info.main" }}>
&nbsp;{getEnchantmentDisplay(item.enchantment)}
</Typography>
)}
</MenuItem>
);
})}
Expand Down Expand Up @@ -173,7 +179,15 @@ export function DisenchantItems({
{destroyableEnchantments.map((enchantment) => {
return (
<MenuItem key={enchantment} value={enchantment}>
{EnchantmentNames[enchantment]}
{pureEnchantmentDisplayName(enchantment)}
{getEnchantmentDisplay(enchantment) !== "???" && (
<Typography
variant="subtitle2"
sx={{ color: "primary.main" }}
>
&nbsp;{getEnchantmentDisplay(enchantment)}
</Typography>
)}
</MenuItem>
);
})}
Expand Down
25 changes: 19 additions & 6 deletions src/game/crafting/enchant-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
addSpaces,
isItemEquipped,
itemSorter,
getEnchantmentDisplay,
} from "src/helpers";

export function EnchantItems({
Expand All @@ -44,14 +45,15 @@ export function EnchantItems({
})

.sort(itemSorter);
const enchantmentsFound: { [x in EnchantmentType]?: true } = {};
const enchantmentsFound: { [x in EnchantmentType]?: number } = {};
const enchantments: EnchantmentType[] = [...hero.enchantments]
.sort()
.filter((ench) => {
if (enchantmentsFound[ench]) {
enchantmentsFound[ench]++;
return false;
}
enchantmentsFound[ench] = true;
enchantmentsFound[ench] = 1;
return true;
});

Expand Down Expand Up @@ -116,7 +118,7 @@ export function EnchantItems({
onChange={(e) => {
const itemId = e.target.value;
const inventoryItem = hero.inventory.find(
(item) => item.id === itemId
(item) => item.id === itemId,
);
if (!inventoryItem) {
return;
Expand All @@ -127,7 +129,7 @@ export function EnchantItems({
{enchantableItems.map((item) => {
return (
<MenuItem key={item.id} value={item.id}>
{itemDisplayName(item)}{" "}
{itemDisplayName(item)}
{isItemEquipped(hero, item) && "*EQUIPPED*"}
</MenuItem>
);
Expand All @@ -146,7 +148,7 @@ export function EnchantItems({
onChange={(e) => {
const ench = e.target.value;
const existingEnchantment = enchantments.find(
(existing) => ench === existing
(existing) => ench === existing,
);
if (existingEnchantment) {
setEnchantment(existingEnchantment);
Expand All @@ -156,7 +158,18 @@ export function EnchantItems({
{enchantments.map((ench) => {
return (
<MenuItem key={ench} value={ench}>
{pureEnchantmentDisplayName(ench)}
{pureEnchantmentDisplayName(ench)}{" "}
{enchantmentsFound[ench] > 1
? `(${enchantmentsFound[ench]})`
: ""}
{getEnchantmentDisplay(ench) !== "???" && (
<Typography
variant="subtitle2"
sx={{ color: "primary.main" }}
>
&nbsp;{getEnchantmentDisplay(ench)}
</Typography>
)}
</MenuItem>
);
})}
Expand Down

0 comments on commit 8848863

Please sign in to comment.