Skip to content

Commit

Permalink
show constructions using an item
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jul 25, 2023
1 parent 332e068 commit c1096e1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ export class CddaData {
_itemComponentCache: {
byTool: Map<string, Set<string>>;
byComponent: Map<string, Set<string>>;
byConstruction: Map<string, Set<string>>;
} | null = null;
getItemComponents() {
if (this._itemComponentCache) return this._itemComponentCache;
Expand Down Expand Up @@ -1106,9 +1107,20 @@ export class CddaData {
itemsByComponent.get(component.id)!.add(recipe.result);
}
});
const itemsByConstruction = new Map<string, Set<string>>();
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;
}
Expand Down
31 changes: 30 additions & 1 deletion src/types/item/ComponentOf.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const _context = "Item Basic Info";
const data = getContext<CddaData>("data");
const { byTool, byComponent } = data.getItemComponents();
const { byTool, byComponent, byConstruction } = data.getItemComponents();
const recipes: Set<string> = byComponent.get(item_id) ?? new Set();
const toolRecipes: Set<string> = byTool.get(item_id) ?? new Set();
Expand All @@ -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))
)
);
</script>

{#if providedByVparts.length}
Expand Down Expand Up @@ -84,3 +92,24 @@ const toolResults = [...toolRecipes].sort((a, b) =>
</section>
{/if}
</div>

{#if constructions.length}
<section>
<h1>
{t("Used In Construction", { _context, _comment: "Section heading" })}
</h1>
<LimitedList items={constructions} let:item={f}>
<ThingLink id={f.group} type="construction_group" />
{#if f.pre_terrain}
on <ItemSymbol
item={data.byId(
f.pre_terrain.startsWith("f_") ? "furniture" : "terrain",
f.pre_terrain
)} />
<ThingLink
type={f.pre_terrain.startsWith("f_") ? "furniture" : "terrain"}
id={f.pre_terrain} />
{/if}
</LimitedList>
</section>
{/if}

0 comments on commit c1096e1

Please sign in to comment.