Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/types/Construction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ const _context = "Construction";
interface Props {
construction: Construction;
includeTitle?: boolean;
includeRequires?: boolean;
}

let { construction: sourceConstruction, includeTitle = false }: Props =
$props();
let {
construction: sourceConstruction,
includeTitle = false,
includeRequires = true,
}: Props = $props();
const construction = untrack(() => sourceConstruction);

const using =
Expand Down Expand Up @@ -68,17 +72,21 @@ if (construction.pre_flags)
<dl>
<dt>{t("Required Skills")}</dt>
<dd>
{#each construction.required_skills ?? [] as [id, level], i}
<ItemLink type="skill" {id} showIcon={false} /> ({level}){#if i + 2 === construction.required_skills?.length}{" and "}{:else if i + 1 !== construction.required_skills?.length}{", "}{/if}
{/each}
{#if construction.required_skills?.length}
{#each construction.required_skills ?? [] as [id, level], i}
<ItemLink type="skill" {id} showIcon={false} /> ({level}){#if i + 2 === construction.required_skills?.length}{" and "}{:else if i + 1 !== construction.required_skills?.length}{", "}{/if}
{/each}
{:else}
{t("none")}
{/if}
</dd>
<dt>{t("Time", { _context })}</dt>
<dd>
{typeof construction.time === "number"
? `${construction.time} m`
: (construction.time ?? "0 m")}
</dd>
{#if prerequisites.length}
{#if includeRequires && prerequisites.length}
<dt>{t("Requires", { _context })}</dt>
<dd>
<ul class="comma-separated">
Expand Down
15 changes: 14 additions & 1 deletion src/types/Furniture.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const constructions = data
.byType("construction")
.filter((c) => c.post_furniture === item.id);

const deconstructions = data
.byType("construction")
.filter(
(c) => c.pre_special === "check_deconstruct" && c.pre_furniture === item.id,
);

const bashedFrom = data
.byType("furniture")
.filter((f) => f.id && f.bash?.furn_set === item.id);
Expand Down Expand Up @@ -173,7 +179,14 @@ const pseudo_items: string[] = asArray(item.crafting_pseudo_item);
{#if constructions.length}
<h2>{t("Construction", { _context })}</h2>
{#each constructions as construction}
<Construction {construction} includeTitle />
<Construction {construction} includeTitle={true} includeRequires={false} />
{/each}
{/if}

{#if deconstructions.length}
<h2>{t("Deconstruction", { _context })}</h2>
{#each deconstructions as construction}
<Construction {construction} includeTitle={false} includeRequires={false} />
{/each}
{/if}

Expand Down
72 changes: 72 additions & 0 deletions src/types/Furniture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,76 @@ describe("Furniture", () => {
expect(getByText("Build Sign")).toBeTruthy();
expect(queryByText("Dig Pit")).toBeNull();
});

it("shows deconstruction methods and required tools for advanced furniture removal", () => {
const data = new CBNData([
{
type: "construction_group",
id: "advanced_object_deconstruction",
name: "Advanced Object Deconstruction",
},
{
type: "requirement",
id: "object_deconstruction_advanced",
qualities: [
{ id: "HAMMER", level: 2 },
{ id: "CHISEL", level: 2 },
{ id: "PRY", level: 3 },
{ id: "SCREW", level: 1 },
],
},
{
type: "tool_quality",
id: "HAMMER",
name: "hammering",
},
{
type: "tool_quality",
id: "CHISEL",
name: "chiseling",
},
{
type: "tool_quality",
id: "PRY",
name: "prying",
},
{
type: "tool_quality",
id: "SCREW",
name: "screw driving",
},
{
type: "construction",
id: "constr_remove_object_fireplace",
group: "advanced_object_deconstruction",
category: "OTHER",
time: "90 m",
required_skills: [["fabrication", 2]],
using: "object_deconstruction_advanced",
pre_furniture: "f_fireplace",
pre_special: "check_deconstruct",
},
{
type: "furniture",
id: "f_fireplace",
name: "fireplace",
description: "A warm test fixture.",
move_cost_mod: 0,
required_str: 0,
},
]);

const { getByText } = render(WithData, {
Component: Furniture,
data,
item: data.byId("furniture", "f_fireplace"),
});

expect(getByText("Deconstruction")).toBeTruthy();
expect(getByText("Tools Required")).toBeTruthy();
expect(getByText("hammering")).toBeTruthy();
expect(getByText("chiseling")).toBeTruthy();
expect(getByText("prying")).toBeTruthy();
expect(getByText("screw driving")).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions src/types/Terrain.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const bits = [
const constructions = data
.byType("construction")
.filter((c) => c.post_terrain === item.id);

const deconstructions = data
.byType("construction")
.filter(
(c) => c.pre_special === "check_deconstruct" && c.pre_terrain === item.id,
);
</script>

<h1><ItemLink type="terrain" id={item.id} link={false} /></h1>
Expand Down Expand Up @@ -129,4 +135,11 @@ const constructions = data
{/each}
{/if}

{#if deconstructions.length}
<h2>{t("Deconstruction", { _context })}</h2>
{#each deconstructions as construction}
<Construction {construction} includeTitle={false} includeRequires={false} />
{/each}
{/if}

<TerrainSpawnedIn item_id={item.id} />
52 changes: 52 additions & 0 deletions src/types/Terrain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @vitest-environment happy-dom
*/
import { render } from "@testing-library/svelte";
import { describe, expect, it } from "vitest";
import WithData from "../WithData.svelte";
import { CBNData } from "../data";
import Terrain from "./Terrain.svelte";

describe("Terrain", () => {
it("shows deconstruction methods and required tools for advanced terrain removal", () => {
const data = new CBNData([
{
type: "construction_group",
id: "advanced_object_deconstruction",
name: "Advanced Object Deconstruction",
},
{
type: "tool_quality",
id: "SCREW",
name: "screw driving",
},
{
type: "construction",
id: "constr_remove_t_console",
group: "advanced_object_deconstruction",
category: "OTHER",
time: "20 m",
required_skills: [["electronics", 0]],
qualities: [{ id: "SCREW", level: 1 }],
pre_terrain: "t_console",
pre_special: "check_deconstruct",
},
{
type: "terrain",
id: "t_console",
name: "console",
description: "A test console.",
},
]);

const { getByText } = render(WithData, {
Component: Terrain,
data,
item: data.byId("terrain", "t_console"),
});

expect(getByText("Deconstruction")).toBeTruthy();
expect(getByText("Tools Required")).toBeTruthy();
expect(getByText("screw driving")).toBeTruthy();
});
});
Loading