From c1096e1d1ba20de1cc5868be3e66bd780c9b4316 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Tue, 25 Jul 2023 12:07:57 -0700 Subject: [PATCH] show constructions using an item --- src/data.ts | 12 ++++++++++++ src/types/item/ComponentOf.svelte | 31 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/data.ts b/src/data.ts index 3f0c9cc8..b673ef0f 100644 --- a/src/data.ts +++ b/src/data.ts @@ -1065,6 +1065,7 @@ export class CddaData { _itemComponentCache: { byTool: Map>; byComponent: Map>; + byConstruction: Map>; } | null = null; getItemComponents() { if (this._itemComponentCache) return this._itemComponentCache; @@ -1106,9 +1107,20 @@ export class CddaData { itemsByComponent.get(component.id)!.add(recipe.result); } }); + const itemsByConstruction = new Map>(); + for (const c of this.byType("construction")) { + const { components } = this.normalizeRequirements(c); + for (const componentOptions of components) + for (const [component] of componentOptions) { + if (!itemsByConstruction.has(component)) + itemsByConstruction.set(component, new Set()); + itemsByConstruction.get(component)!.add(c.id); + } + } this._itemComponentCache = { byTool: itemsByTool, byComponent: itemsByComponent, + byConstruction: itemsByConstruction, }; return this._itemComponentCache; } diff --git a/src/types/item/ComponentOf.svelte b/src/types/item/ComponentOf.svelte index c113bccf..85be8ee5 100644 --- a/src/types/item/ComponentOf.svelte +++ b/src/types/item/ComponentOf.svelte @@ -11,7 +11,7 @@ const _context = "Item Basic Info"; const data = getContext("data"); -const { byTool, byComponent } = data.getItemComponents(); +const { byTool, byComponent, byConstruction } = data.getItemComponents(); const recipes: Set = byComponent.get(item_id) ?? new Set(); const toolRecipes: Set = byTool.get(item_id) ?? new Set(); @@ -32,6 +32,14 @@ const toolResults = [...toolRecipes].sort((a, b) => singularName(data.byId("item", b)) ) ); + +const constructions = [...(byConstruction.get(item_id) ?? new Set())] + .map((id) => data.byId("construction", id)) + .sort((a, b) => + singularName(data.byId("construction_group", a.group)).localeCompare( + singularName(data.byId("construction_group", b.group)) + ) + ); {#if providedByVparts.length} @@ -84,3 +92,24 @@ const toolResults = [...toolRecipes].sort((a, b) => {/if} + +{#if constructions.length} +
+

+ {t("Used In Construction", { _context, _comment: "Section heading" })} +

+ + + {#if f.pre_terrain} + on + + {/if} + +
+{/if}