Skip to content

Commit

Permalink
Fixed not being able to set item quality to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
colecrouter committed Nov 22, 2024
1 parent 1ab3ad5 commit f04bcef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/lib/proxies/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class Item {

set quality(quality) {
if (this.quality === undefined) throw new Error("Item has no quality");
if (!quality) throw new Error("Quality must be a number");
if (quality === undefined) throw new Error("Quality must be a number");

if (quality < 0 || quality > 4)
throw new Error("Quality must be between 0 and 4");
Expand Down
21 changes: 8 additions & 13 deletions src/routes/(edit)/inventory/QualitySelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</script>

<script lang="ts">
import { ItemData } from "$lib/ItemData";
import { CalculateEdibility, CalculatePrice } from "$lib/ItemQuality";
import type { Item } from "$lib/proxies/Item";
Expand All @@ -23,27 +22,23 @@
};
const changePrice = (newQuality: number) => {
const data = ItemData.get(item.name);
if (!data || !("Price" in data) || data.Price === undefined) return;
if (!("Price" in item.info) || item.info.Price === undefined) return;
item.price = CalculatePrice(data.Price, newQuality);
item.price = CalculatePrice(item.info.Price, newQuality);
};
const changeEdibility = (newQuality: number) => {
const data = ItemData.get(item.name);
if (!data || !("Edibility" in data)) return;
if (!("Edibility" in item.info)) return;
item.edibility = CalculateEdibility(data.Edibility, newQuality);
item.edibility = CalculateEdibility(item.info.Edibility, newQuality);
};
</script>

<div class="container">
<!-- Create 4 button containing star emoji-->
{#if "quality" in item}
{#each [0, 1, 2, 4] as i}
<label
data-testid={`quality-${qualityLevels.get(i)?.toLowerCase()}`}
>
<!-- Create 4 buttons containing star emoji-->
{#if item.quality !== undefined}
{#each qualityLevels as [i]}
<label data-testid={`quality-${i}`}>
{#if i === 0}
{:else}
Expand Down
19 changes: 10 additions & 9 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,23 @@ describe("Upload save, edit, export", () => {
});

it("should be able to change item quality", async () => {
// There is a parsnip in slot 4, change the quality from silver to gold
// There is a parsnip in slot 4, change the quality to 0, 1, 2, and 4
const page = render(editorPage);
const slot = page.getByTestId("item-4");
slot.click();

await tick();

// Ensure item is silver quality
expect(saveManager.save.player.inventory.getItem(4).quality).toBe(1);
for (const quality of [0, 1, 2, 4]) {
// Change quality to quality
const button = page.getByTestId(`quality-${quality}`);
button.click();

// Change quality to gold
const goldButton = page.getByTestId("quality-gold");
goldButton.click();

// Ensure item is gold quality
expect(saveManager.save.player.inventory.getItem(4).quality).toBe(2);
// Ensure item is quality
expect(saveManager.save.player.inventory.getItem(4).quality).toBe(
quality,
);
}
});

it("should be able to change item quantity", async () => {
Expand Down

0 comments on commit f04bcef

Please sign in to comment.