Skip to content

Commit

Permalink
update brewable
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Aug 11, 2023
1 parent bcf7ac3 commit d91d05b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion _test/all.meta.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildNum":"cdda-experimental-2023-07-27-0014","sha":"eb6f4a7d86c15cce1d23a1763ceb1395e52f34330dc93b2457a2ebff309ef893"}
{"buildNum":"cdda-experimental-2023-08-11-0847","sha":"ef4c302badcfa2ce3a03ca1de4c6c9e61a74b17d2e8caf5a7410425bf6822b7d"}
13 changes: 10 additions & 3 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,16 @@ export class CddaData {
return this.#grownFromIndex.lookup(item_id);
}

#brewedFromIndex = new ReverseIndex(this, "item", (x) =>
x.id ? x.brewable?.results ?? [] : []
);
#brewedFromIndex = new ReverseIndex(this, "item", (x) => {
function normalize(
results: undefined | string[] | Record<string, number>
): string[] {
if (!results) return [];
if (Array.isArray(results)) return results;
return Object.keys(results);
}
return x.id ? normalize(x.brewable?.results) : [];
});
brewedFrom(item_id: string) {
return this.#brewedFromIndex.lookup(item_id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ export type ItemBasicInfo = {
append?: boolean;
}[];
brewable?: {
results: string[]; // item_id
results: string[] | Record<string, number>; // item_id
time?: duration;
};
milling?: {
Expand Down
7 changes: 5 additions & 2 deletions src/types/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,14 @@ function normalizeStackVolume(item: Item): (string | number) | undefined {
{/if}

{#if item.brewable}
{@const results = Array.isArray(item.brewable.results)
? Object.fromEntries(item.brewable.results.map((r) => [r, 1]))
: item.brewable.results}
<dt>{t("Ferments Into", { _context })}</dt>
<dd>
<ul class="comma-separated">
{#each item.brewable.results as result_id}
<li><ThingLink type="item" id={result_id} /></li>
{#each Object.entries(results) as [result_id, count]}
<li><ThingLink type="item" id={result_id} {count} /></li>
{/each}
</ul>
({item.brewable.time ?? "1 turn"})
Expand Down

0 comments on commit d91d05b

Please sign in to comment.