Skip to content

Commit

Permalink
variants are displayed and searchable
Browse files Browse the repository at this point in the history
ref #89
  • Loading branch information
nornagon committed Aug 5, 2022
1 parent 3594fd5 commit ea14459
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/SearchResults.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { mapType, singularName } from "./data";
import { mapType, singular, singularName } from "./data";
import type { CddaData } from "./data";
import * as fuzzysort from "fuzzysort";
import ItemSymbol from "./types/item/ItemSymbol.svelte";
Expand Down Expand Up @@ -39,25 +39,39 @@ $: targets = [...(data?.all() ?? [])]
}
return true;
})
.map((x) => ({
id: (x as any).id,
name: singularName(x),
type: mapType(x.type),
}));
.flatMap((x) =>
[
{
id: (x as any).id,
name: singularName(x),
type: mapType(x.type),
},
].concat(
"variants" in x
? x.variants.map((v) => ({
id: (x as any).id,
variant_id: v.id,
name: singular(v.name),
type: mapType(x.type),
}))
: []
)
);
export let search: string;
function filter(text: string): Map<string, any[]> {
const results = fuzzysort.go(text, targets, {
limit: 100,
keys: ["id", "name"],
keys: ["id", "name", "variant_id"],
threshold: -10000,
});
const byType = new Map<string, any[]>();
for (const { obj: item } of results) {
const mappedType = item.type;
if (!SEARCHABLE_TYPES.has(mappedType)) continue;
if (!byType.has(mappedType)) byType.set(mappedType, []);
if (byType.get(mappedType).some((x) => x.id === item.id)) continue;
const obj = data.byId(mappedType, item.id);
byType.get(mappedType).push(obj);
}
Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ export type ItemBasicInfo = {
| string
| UseFunction
| (string | UseFunction | [string] | [string, number])[];
variant_type?: "gun" | "generic";
variants?: {
id: string;
name: Translation;
description: Translation;
symbol?: string;
color?: string;
ascii_picture?: string; // id
weight?: integer;
append?: boolean;
}[];
};

export type Item =
Expand Down
13 changes: 13 additions & 0 deletions src/types/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ const ascii_picture =
<div class="side-by-side no-margin">
<div>
<dl>
{#if item.variants?.length}
<dt>AKA</dt>
<dd>
<ul class="comma-separated">
{#each item.variants as va}
{@const name = singular(va.name)}
{#if name !== singularName(item)}
<li>{singular(va.name)}</li>
{/if}
{/each}
</ul>
</dd>
{/if}
{#if materials.length}
<dt>Material</dt>
<dd>
Expand Down

0 comments on commit ea14459

Please sign in to comment.