Skip to content

Commit 86ac896

Browse files
authored
Merge pull request #163 from ushkinaz/feat/update-pry-property-handling
feat(types): align terrain and furniture pry handling with BN data
2 parents c8eacf7 + 640ef07 commit 86ac896

File tree

8 files changed

+309
-58
lines changed

8 files changed

+309
-58
lines changed

src/types.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -792,20 +792,38 @@ export type ActivityDataCommon = {
792792
item: string; // item_id
793793
count?: number | [number, number];
794794
}[];
795-
prying_data?: {
796-
prying_nails?: boolean;
797-
difficulty?: integer;
798-
prying_level?: integer;
799-
noisy?: boolean;
800-
alarm?: boolean;
801-
breakable?: boolean;
802-
failure?: Translation;
803-
};
804-
795+
result?: string;
805796
message?: Translation;
806797
sound?: Translation;
807798
};
808799

800+
export type PryDataCommon = {
801+
pry_quality?: integer; // default: -1
802+
pry_bonus_mult?: integer; // default: 1
803+
difficulty?: integer; // default: 1
804+
noise?: integer; // default: 0
805+
break_noise?: integer; // default: noise
806+
alarm?: boolean; // default: false
807+
breakable?: boolean; // default: false
808+
pry_items?: ItemGroupEntry[];
809+
break_items?: ItemGroupEntry[];
810+
sound?: Translation;
811+
break_sound?: Translation;
812+
success_message?: Translation;
813+
fail_message?: Translation;
814+
break_message?: Translation;
815+
};
816+
817+
export type TerrainPryData = PryDataCommon & {
818+
new_ter_type?: string; // terrain_id, default: t_null
819+
break_ter_type?: string; // terrain_id, default: t_null
820+
};
821+
822+
export type FurniturePryData = PryDataCommon & {
823+
new_furn_type?: string; // furniture_id, default: f_null
824+
break_furn_type?: string; // furniture_id, default: f_null
825+
};
826+
809827
export type MapDataCommon = {
810828
color?: string | [string] | [string, string, string, string];
811829
bgcolor?: string | [string] | [string, string, string, string];
@@ -849,10 +867,10 @@ export type Terrain = MapDataCommon & {
849867
| { type: "cardreader" }
850868
| { type: "effect_on_condition" };
851869

852-
oxytorch?: ActivityDataCommon & { result: string };
853-
boltcut?: ActivityDataCommon & { result: string };
854-
hacksaw?: ActivityDataCommon & { result: string };
855-
prying?: ActivityDataCommon & { result: string };
870+
oxytorch?: ActivityDataCommon;
871+
boltcut?: ActivityDataCommon;
872+
hacksaw?: ActivityDataCommon;
873+
pry?: TerrainPryData;
856874
};
857875

858876
export type Furniture = MapDataCommon & {
@@ -880,9 +898,10 @@ export type Furniture = MapDataCommon & {
880898
bash?: MapBashInfo;
881899
deconstruct?: MapDeconstructInfo;
882900

883-
oxytorch?: ActivityDataCommon & { result?: string };
884-
boltcut?: ActivityDataCommon & { result?: string };
885-
hacksaw?: ActivityDataCommon & { result?: string };
901+
oxytorch?: ActivityDataCommon;
902+
boltcut?: ActivityDataCommon;
903+
hacksaw?: ActivityDataCommon;
904+
pry?: FurniturePryData;
886905

887906
// TODO:
888907
// open

src/types/Furniture.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import FurnitureSpawnedIn from "./item/FurnitureSpawnedIn.svelte";
1111
import LimitedList from "../LimitedList.svelte";
1212
import HarvestedTo from "./item/HarvestedTo.svelte";
1313
import { gameSingular } from "../i18n/game-locale";
14+
import TerFurnPry from "./TerFurnPry.svelte";
1415
1516
const data = getContext<CBNData>("data");
1617
const _context = "Terrain / Furniture";
@@ -111,6 +112,12 @@ const pseudo_items: string[] = asArray(item.crafting_pseudo_item);
111112
<TerFurnActivity act={item.oxytorch} resultType="furniture" />
112113
</dd>
113114
{/if}
115+
{#if item.pry}
116+
<dt><ThingLink type="item_action" id="CROWBAR" showIcon={false} /></dt>
117+
<dd>
118+
<TerFurnPry act={item.pry} resultType="furniture" />
119+
</dd>
120+
{/if}
114121
{#if deconstruct.length}
115122
<dt>{t("Deconstruct", { _context })}</dt>
116123
<dd>

src/types/Furniture.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,62 @@ import { makeTestCBNData } from "../data.test-helpers";
88
import Furniture from "./Furniture.svelte";
99

1010
describe("Furniture", () => {
11+
it("shows pry details from the real furniture pry data", () => {
12+
const data = makeTestCBNData([
13+
{
14+
type: "tool_quality",
15+
id: "PRY",
16+
name: "prying",
17+
},
18+
{
19+
type: "furniture",
20+
id: "f_coffin_c",
21+
name: "closed coffin",
22+
description: "A sealed test coffin.",
23+
move_cost_mod: 0,
24+
required_str: 0,
25+
pry: {
26+
pry_quality: 1,
27+
noise: 12,
28+
difficulty: 7,
29+
new_furn_type: "f_coffin_o",
30+
},
31+
},
32+
{
33+
type: "furniture",
34+
id: "f_coffin_o",
35+
name: "open coffin",
36+
description: "The lid has yielded.",
37+
move_cost_mod: 0,
38+
required_str: 0,
39+
},
40+
]);
41+
42+
const { getByText, queryByText } = render(WithData, {
43+
Component: Furniture,
44+
data,
45+
item: data.byId("furniture", "f_coffin_c"),
46+
});
47+
48+
const requiresDefinition = getByText("Requires").nextElementSibling;
49+
const difficultyDefinition = getByText("Difficulty").nextElementSibling;
50+
const becomesDefinition = getByText("Becomes").nextElementSibling;
51+
52+
expect(requiresDefinition).toBeTruthy();
53+
expect(
54+
within(requiresDefinition as HTMLElement).getByText("prying"),
55+
).toBeTruthy();
56+
expect(difficultyDefinition).toBeTruthy();
57+
expect(
58+
within(difficultyDefinition as HTMLElement).getByText("7"),
59+
).toBeTruthy();
60+
expect(becomesDefinition).toBeTruthy();
61+
expect(
62+
within(becomesDefinition as HTMLElement).getByText("open coffin"),
63+
).toBeTruthy();
64+
expect(queryByText("Duration")).toBeNull();
65+
});
66+
1167
it("shows furniture constructions from post_furniture", () => {
1268
const data = makeTestCBNData([
1369
{

src/types/TerFurnActivity.svelte

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,52 @@
11
<script lang="ts">
22
import { t } from "@transifex/native";
3-
import type { CBNData } from "src/data";
43
import type { ActivityDataCommon } from "src/types";
5-
import { getContext } from "svelte";
64
import ThingLink from "./ThingLink.svelte";
5+
import { untrack } from "svelte";
76
87
interface Props {
9-
act: ActivityDataCommon & { result?: string };
8+
act: ActivityDataCommon;
109
resultType: "terrain" | "furniture";
1110
}
1211
1312
let { act, resultType }: Props = $props();
1413
15-
const data = getContext<CBNData>("data");
14+
function visibleResult(
15+
value: ActivityDataCommon,
16+
resultType: "terrain" | "furniture",
17+
): string | undefined {
18+
if (value.result === (resultType === "terrain" ? "t_null" : "f_null")) {
19+
return undefined;
20+
}
21+
return value.result;
22+
}
23+
24+
const activity = untrack(() => act);
25+
const result = untrack(() => visibleResult(act, resultType));
1626
1727
const _context = "Terrain / Furniture";
18-
const _comment = "activity (prying, hacksawing, etc.)";
28+
const _comment = "activity (oxytorch, hacksaw, boltcut, etc.)";
1929
</script>
2030

21-
<ul class="comma-separated">
22-
{#each act.byproducts ?? [] as { item: i, count }}
23-
<li>
24-
<ThingLink
25-
id={i}
26-
type="item"
27-
showIcon={false} />{#if typeof count === "number"}&nbsp;({count}){:else if Array.isArray(count)}&nbsp;({count[0]}–{count[1]}){/if}
28-
</li>
29-
{/each}
30-
</ul>
3131
<dl>
3232
<dt>{t("Duration", { _context, _comment })}</dt>
33-
<dd>{act.duration ?? "1 s"}</dd>
34-
{#if act.prying_data}
35-
<dt>{t("Difficulty", { _context, _comment })}</dt>
36-
<dd>{act.prying_data.difficulty ?? 0}</dd>
37-
<dt>{t("Requires", { _context, _comment })}</dt>
33+
<dd>{activity.duration ?? "1 s"}</dd>
34+
{#if result}
35+
<dt>{t("Becomes", { _context, _comment })}</dt>
3836
<dd>
39-
<ThingLink id="PRY" type="tool_quality" showIcon={false} />
40-
{act.prying_data.prying_level ?? 0}{#if act.prying_data.prying_nails}, <ThingLink
41-
id="PRYING_NAIL"
42-
type="tool_quality"
43-
showIcon={false} />&nbsp;1{/if}
37+
<ThingLink id={result} type={resultType} showIcon={false} />
4438
</dd>
45-
<dt>{t("Noisy", { _context, _comment })}</dt>
46-
<dd>{act.prying_data.noisy ? t("Yes") : t("No")}</dd>
47-
<dt>{t("Alarm", { _context, _comment })}</dt>
48-
<dd>{act.prying_data.alarm ? t("Yes") : t("No")}</dd>
49-
<dt>{t("Breakable", { _context, _comment })}</dt>
50-
<dd>{act.prying_data.breakable ? t("Yes") : t("No")}</dd>
5139
{/if}
52-
{#if act.result && act.result !== "t_null"}
53-
<dt>{t("Result", { _context, _comment })}</dt>
40+
{#if activity.byproducts}
41+
<dt>{t("Byproducts", { _context, _comment })}</dt>
5442
<dd>
55-
<ThingLink id={act.result} type={resultType} />
43+
<ul class="comma-separated">
44+
{#each activity.byproducts ?? [] as { item: i, count }}
45+
<li>
46+
<ThingLink id={i} type="item" showIcon={false} {count} />
47+
</li>
48+
{/each}
49+
</ul>
5650
</dd>
5751
{/if}
5852
</dl>

src/types/TerFurnPry.svelte

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<script lang="ts">
2+
import { t } from "@transifex/native";
3+
import { CBNData } from "../data";
4+
import type { FurniturePryData, TerrainPryData } from "src/types";
5+
import { getContext, untrack } from "svelte";
6+
import ThingLink from "./ThingLink.svelte";
7+
8+
type PryData = TerrainPryData | FurniturePryData;
9+
10+
interface Props {
11+
act: PryData;
12+
resultType: "terrain" | "furniture";
13+
}
14+
15+
let { act, resultType }: Props = $props();
16+
const data = getContext<CBNData>("data");
17+
18+
const pry = untrack(() => act);
19+
const result = untrack(() => visibleResult(act, resultType));
20+
const pryItems = untrack(() =>
21+
data.flattenItemGroup({
22+
subtype: "collection",
23+
entries: act.pry_items ?? [],
24+
}),
25+
);
26+
const breakItems = untrack(() =>
27+
data.flattenItemGroup({
28+
subtype: "collection",
29+
entries: act.break_items ?? [],
30+
}),
31+
);
32+
33+
function visibleResult(
34+
value: PryData,
35+
resultType: "terrain" | "furniture",
36+
): string | undefined {
37+
let result = undefined;
38+
if (resultType === "terrain") {
39+
result = "new_ter_type" in value ? value.new_ter_type : undefined;
40+
} else if (resultType === "furniture") {
41+
result = "new_furn_type" in value ? value.new_furn_type : undefined;
42+
}
43+
if (result === (resultType === "terrain" ? "t_null" : "f_null")) {
44+
return undefined;
45+
}
46+
return result;
47+
}
48+
49+
const _context = "Terrain / Furniture";
50+
const _comment = "prying";
51+
</script>
52+
53+
<dl>
54+
<dt>{t("Difficulty", { _context, _comment })}</dt>
55+
<dd>{pry.difficulty ?? 1}</dd>
56+
<dt>{t("Requires", { _context, _comment })}</dt>
57+
<dd>
58+
<ThingLink id="PRY" type="tool_quality" showIcon={false} />
59+
{pry.pry_quality ?? 0}
60+
</dd>
61+
<dt>{t("Alarm", { _context, _comment })}</dt>
62+
<dd>{pry.alarm ? t("Yes") : t("No")}</dd>
63+
<dt>{t("Noise", { _context, _comment })}</dt>
64+
<dd>{pry.noise ?? 0}</dd>
65+
<dt>{t("Breakable", { _context, _comment })}</dt>
66+
<dd>{pry.breakable ? t("Yes") : t("No")}</dd>
67+
{#if pry.breakable}
68+
<dt>{t("Break noise", { _context, _comment })}</dt>
69+
<dd>{pry.break_noise ?? 0}</dd>
70+
{#if breakItems.length}
71+
<dt>{t("Break Items", { _context, _comment })}</dt>
72+
<dd>
73+
<ul class="comma-separated">
74+
{#each breakItems as entry}
75+
<li>
76+
<ThingLink
77+
id={entry.id}
78+
type="item"
79+
showIcon={false}
80+
count={entry.count} />
81+
</li>
82+
{/each}
83+
</ul>
84+
</dd>
85+
{/if}
86+
{/if}
87+
{#if pryItems.length}
88+
<dt>{t("Pry Items", { _context, _comment })}</dt>
89+
<dd>
90+
<ul class="comma-separated">
91+
{#each pryItems as entry}
92+
<li>
93+
<ThingLink
94+
id={entry.id}
95+
type="item"
96+
showIcon={false}
97+
count={entry.count} />
98+
</li>
99+
{/each}
100+
</ul>
101+
</dd>
102+
{/if}
103+
{#if result}
104+
<dt>{t("Becomes", { _context, _comment })}</dt>
105+
<dd>
106+
<ThingLink id={result} type={resultType} showIcon={false} />
107+
</dd>
108+
{/if}
109+
</dl>

src/types/Terrain.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import TerFurnActivity from "./TerFurnActivity.svelte";
1111
import TerrainSpawnedIn from "./item/TerrainSpawnedIn.svelte";
1212
import HarvestedTo from "./item/HarvestedTo.svelte";
1313
import { gameSingular } from "../i18n/game-locale";
14+
import TerFurnPry from "./TerFurnPry.svelte";
1415
1516
const data = getContext<CBNData>("data");
1617
const _context = "Terrain / Furniture";
@@ -87,10 +88,10 @@ const deconstructions = data
8788
<TerFurnActivity act={item.oxytorch} resultType="terrain" />
8889
</dd>
8990
{/if}
90-
{#if item.prying}
91+
{#if item.pry}
9192
<dt><ThingLink type="item_action" id="CROWBAR" showIcon={false} /></dt>
9293
<dd>
93-
<TerFurnActivity act={item.prying} resultType="terrain" />
94+
<TerFurnPry act={item.pry} resultType="terrain" />
9495
</dd>
9596
{/if}
9697
{#if deconstruct.length || item.deconstruct?.ter_set}

0 commit comments

Comments
 (0)