Skip to content

Commit 6621a36

Browse files
authored
Fix book recipe list (#205)
* fix book recipe list * add read_skill to books * add read_skill to books
1 parent 9cab2aa commit 6621a36

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export type BookSlot = {
310310
time?: number /* mins */ | string /* duration */;
311311

312312
skill?: string; // skill_id
313+
read_skill?: string; // skill_id
313314
martial_art?: string; // matype_id
314315
chapters?: number; // default: 0
315316
proficiencies?: BookProficiencyBonus[];

src/types/Skill.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ const data = getContext<CddaData>("data");
2020
2121
const booksWithSkill = data
2222
.byType("item")
23-
.filter((t) => t.id && isItemSubtype("BOOK", t) && t.skill === item.id)
23+
.filter(
24+
(t) =>
25+
t.id && isItemSubtype("BOOK", t) && (t.read_skill ?? t.skill) === item.id
26+
)
2427
.sort((a, b) =>
2528
singularName(a).localeCompare(singularName(b))
2629
) as SupportedTypesWithMapped["BOOK"][];

src/types/item/BookInfo.svelte

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ function add(recipe_id: string, level: number) {
1919
);
2020
}
2121
for (const recipe of data.byType("recipe")) {
22-
if (recipe.result && Array.isArray(recipe.book_learn))
22+
if (!recipe.result) continue;
23+
if (Array.isArray(recipe.book_learn)) {
2324
for (const [id, level = 0] of recipe.book_learn)
2425
if (id === item.id) add(recipe.result, level);
25-
else if (recipe.book_learn)
26-
for (const [id, obj] of Object.entries(
27-
recipe.book_learn as Record<string, any>
28-
))
29-
if (id === item.id) add(recipe.result, obj.skill_level ?? 0);
26+
} else if (recipe.book_learn) {
27+
for (const [id, obj] of Object.entries(
28+
recipe.book_learn as Record<string, any>
29+
))
30+
if (id === item.id) add(recipe.result, obj.skill_level ?? 0);
31+
}
3032
}
33+
34+
const readSkill = item.read_skill ?? item.skill;
3135
</script>
3236

3337
<section>
3438
<h1>{t("Book", { _context, _comment: "Section heading" })}</h1>
3539
<dl>
36-
{#if item.skill}
40+
{#if readSkill}
3741
<dt>{t("Skill", { _context })}</dt>
38-
<dd><ThingLink id={item.skill} type="skill" /></dd>
42+
<dd><ThingLink id={readSkill} type="skill" /></dd>
3943
<dt>{t("Required Level", { _context })}</dt>
4044
<dd>{item.required_level ?? 0}</dd>
4145
<dt>{t("Maximum Level", { _context })}</dt>

0 commit comments

Comments
 (0)