Skip to content

Allow usage of localized weapon name in WishCounterAddModal #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/components/WeaponSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { t } from 'svelte-i18n';
import { createEventDispatcher } from 'svelte';
import { t, locale } from 'svelte-i18n';
import { createEventDispatcher, onMount } from 'svelte';
import VirtualList from './VirtualList.svelte';
import { fade } from 'svelte/transition';
import { mdiChevronDown, mdiCloseCircle } from '@mdi/js';
Expand All @@ -20,6 +20,7 @@
let container;
let input;
let search = '';
let weaponListLocalized = {}

function toggleOptions() {
focused = !focused;
Expand Down Expand Up @@ -94,7 +95,9 @@
.filter((e) => e[1].rarity >= 3)
.sort((a, b) => a[1].name.localeCompare(b[1].name));

$: filteredWeapons = weapons.filter((e) => e[1].name.toLowerCase().includes(search.toLowerCase()));
$: filteredWeapons = weapons.filter((e) => {
return e[1].name.toLowerCase().includes(search.toLowerCase()) || (e[1].id in weaponListLocalized && weaponListLocalized[e[1].id].toLowerCase().includes(search.toLowerCase()))
});
$: maxItemRow = Math.min(6, filteredWeapons.length);

$: nothingSelected = selected === null;
Expand All @@ -105,6 +108,16 @@

$: classes = focused ? 'border-primary' : 'border-transparent';
$: iconClasses = focused ? 'transform rotate-180' : '';

onMount(async () => {
locale.subscribe(async (val) => {
const localizedData = await import(`../data/weapons/${val}.json`);
weaponListLocalized = Object.values(localizedData).reduce((acc, { id, name }) => ({
...acc,
[id]: name
}), {})
});
});
</script>

<svelte:window on:click={onWindowClick} on:keydown={onKeyDown} />
Expand Down