zenno/chara/convo: working on using umadump talk gallery
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import * as z from 'zod';
|
||||
|
||||
const Entry = z.strictObject({
|
||||
home_story_trigger_id: z.int32(),
|
||||
new_flag: z.literal(0).or(z.literal(1)),
|
||||
});
|
||||
|
||||
export type Entry = z.infer<typeof Entry>;
|
||||
|
||||
export const Gallery = z.object({
|
||||
talk_gallery_list: z.array(Entry),
|
||||
});
|
||||
|
||||
export type Gallery = z.infer<typeof Gallery>;
|
||||
@@ -9,25 +9,57 @@
|
||||
requiredCharas,
|
||||
convoCharas,
|
||||
} from '$lib/data/convo';
|
||||
import * as talk from '$lib/umadump/talk';
|
||||
import CharaPick from '$lib/CharaPick.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import CharaIcon from '$lib/CharaIcon.svelte';
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
|
||||
let conversations: Conversation[] = $state([]);
|
||||
const convoMap = $derived(byChara(conversations));
|
||||
const popular = $derived(groupPopulars(conversations));
|
||||
let allConvos: Conversation[] = $state([]);
|
||||
const popular = $derived(groupPopulars(allConvos));
|
||||
let characters: Character[] = $state([]);
|
||||
const selCharas = $derived(characters.filter((c) => convoMap.has(c.chara_id)));
|
||||
const names = $derived(charaNames(characters));
|
||||
const minSuggest = 8;
|
||||
|
||||
onMount(async () => {
|
||||
[conversations, characters] = await Promise.all([conversation(), character()]);
|
||||
[allConvos, characters] = await Promise.all([conversation(), character()]);
|
||||
});
|
||||
|
||||
let chara: Character | undefined = $state();
|
||||
let convo = $state(1);
|
||||
|
||||
let talkFiles: FileList | undefined = $state();
|
||||
const talkData = $derived.by(async () => {
|
||||
if (talkFiles == null || talkFiles.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
const t = await talkFiles[0].text();
|
||||
const d = JSON.parse(t);
|
||||
return talk.Gallery.safeDecode(d);
|
||||
});
|
||||
const readIDs = $derived.by(async () => {
|
||||
const d = await talkData;
|
||||
const s = new SvelteSet<number>();
|
||||
if (d == null) {
|
||||
return s;
|
||||
}
|
||||
if (!d.success) {
|
||||
console.warn(d.error);
|
||||
return s;
|
||||
}
|
||||
for (const e of d.data.talk_gallery_list) {
|
||||
s.add(e.home_story_trigger_id);
|
||||
}
|
||||
return s;
|
||||
});
|
||||
const talkFileErrs = $derived((await talkData)?.error?.issues);
|
||||
const conversations = $derived.by(async () => {
|
||||
const s = await readIDs;
|
||||
return allConvos.filter((c) => !s.has(c.id));
|
||||
});
|
||||
const convoMap = $derived(byChara(await conversations));
|
||||
const selCharas = $derived(characters.filter((c) => convoMap.has(c.chara_id)));
|
||||
|
||||
const options = $derived(convoMap.get(chara?.chara_id ?? 0) ?? []);
|
||||
const cur = $derived(options.find((c) => c.number === convo));
|
||||
const charaIDs = $derived(cur != null ? convoCharas(cur) : []);
|
||||
@@ -47,12 +79,12 @@
|
||||
</script>
|
||||
|
||||
<h1 class="text-4xl">Lobby Conversations</h1>
|
||||
<div class="mx-auto mt-8 flex flex-col rounded-md text-center shadow-md ring md:max-w-xl md:flex-row">
|
||||
<div class="m-4 flex-1 md:mt-3">
|
||||
<div class="mx-auto mt-8 grid grid-cols-1 gap-4 rounded-md p-4 text-center shadow-md ring md:max-w-xl md:grid-cols-6">
|
||||
<div class="md:col-span-3">
|
||||
<label for="chara" class="hidden md:inline">Character</label>
|
||||
<CharaPick id="chara" characters={selCharas} class="w-full" bind:value={chara} required />
|
||||
</div>
|
||||
<div class="m-4 flex-1 md:mt-3">
|
||||
<div class="md:col-span-3">
|
||||
<label for="convo" class="hidden md:inline">Conversation</label>
|
||||
<select id="convo" bind:value={convo} class="w-full">
|
||||
{#each options as opt (opt.number)}
|
||||
@@ -60,6 +92,15 @@
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-span-full">
|
||||
<label for="talkgallery" class="block">
|
||||
Select <span class="inline-block font-mono">talk_gallery_data.json</span> to hide read conversations.
|
||||
</label>
|
||||
<input type="file" class="appearance-auto" accept="application/json" id="talkgallery" bind:files={talkFiles} />
|
||||
</div>
|
||||
{#if (talkFileErrs?.length ?? 0) > 0}
|
||||
<div class="col-span-full">Invalid File</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if cur}
|
||||
<div class="shadow-sm transition-shadow hover:shadow-md">
|
||||
|
||||
Reference in New Issue
Block a user