30 lines
918 B
TypeScript
30 lines
918 B
TypeScript
import { isProjectAgentAvatarDataUrl } from '../../shared/project-config';
|
|
|
|
const avatarModules = import.meta.glob('../assets/agent-avatars/avatar-*.png', {
|
|
eager: true,
|
|
import: 'default',
|
|
}) as Record<string, string>;
|
|
|
|
export type AgentAvatarOption = {
|
|
id: string;
|
|
src: string;
|
|
label: string;
|
|
};
|
|
|
|
export const agentAvatarOptions: AgentAvatarOption[] = Array.from({ length: 16 }, (_, index) => {
|
|
const number = String(index + 1).padStart(2, '0');
|
|
return {
|
|
id: `avatar-${number}`,
|
|
src: avatarModules[`../assets/agent-avatars/avatar-${number}.png`],
|
|
label: `像素伙伴 ${index + 1}`,
|
|
};
|
|
});
|
|
|
|
export function getAgentAvatarSrc(
|
|
avatarId: string | null | undefined,
|
|
avatarDataUrl?: string | null,
|
|
): string {
|
|
if (isProjectAgentAvatarDataUrl(avatarDataUrl)) return avatarDataUrl;
|
|
return agentAvatarOptions.find((option) => option.id === avatarId)?.src ?? agentAvatarOptions[0]!.src;
|
|
}
|