zenno: use data from api

This commit is contained in:
2026-06-05 14:31:10 -04:00
parent 871fd5fdcc
commit a848c8eb72
15 changed files with 369 additions and 322 deletions
+18 -22
View File
@@ -1,5 +1,4 @@
import type { RegionalName } from '$lib/regional-name';
import globalJSON from '../../../../global/conversation.json';
/**
* Lobby conversation data.
@@ -17,10 +16,6 @@ export interface Conversation {
* Location ID of the conversation.
*/
location: 110 | 120 | 130 | 210 | 220 | 310 | 410 | 420 | 430 | 510 | 520 | 530;
/**
* English name of the location, for convenience.
*/
location_name: string;
/**
* First character in the conversation.
* Not necessarily equal to chara_id.
@@ -40,16 +35,17 @@ export interface Conversation {
condition_type: 0 | 1 | 2 | 3 | 4;
}
export const conversation = {
global: globalJSON as Conversation[],
};
export async function conversation(): Promise<Conversation[]> {
const resp = await fetch('/api/global/conversation');
return resp.json();
}
export const byChara = {
global: globalJSON.reduce(
export function byChara(convos: Conversation[]) {
return convos.reduce(
(m, c) => m.set(c.chara_id, (m.get(c.chara_id) ?? []).concat(c as Conversation)),
new Map<Conversation['chara_id'], Conversation[]>(),
),
};
new Map<number, Conversation[]>(),
);
}
export const locations: Record<Conversation['location'], { name: RegionalName; group: 1 | 2 | 3 | 4 | 5 }> = {
110: { name: { en: 'right side front' }, group: 1 },
@@ -74,12 +70,12 @@ function locCharas(convos: Conversation[], locGroup: 1 | 2 | 3 | 4 | 5) {
return [...m].toSorted((a, b) => b[1] - a[1]); // descending
}
export const groupPopulars = {
global: {
1: locCharas(conversation.global, 1),
2: locCharas(conversation.global, 2),
3: locCharas(conversation.global, 3),
4: locCharas(conversation.global, 4),
5: locCharas(conversation.global, 5),
},
};
export function groupPopulars(convos: Conversation[]) {
return {
1: locCharas(convos, 1),
2: locCharas(convos, 2),
3: locCharas(convos, 3),
4: locCharas(convos, 4),
5: locCharas(convos, 5),
};
}