import spec from '../../image-prompts/ootd.json' /** 낮 최고기온 구간 × 스타일 × 사람별 옷. 옷 목록·카드 글자는 image-prompts/ootd.json 한 곳에서 정한다. * 그림은 src/assets/ootd/<구간>-<사람>-<스타일>.webp 가 있으면 자동으로 붙는다 (npm run gen-image -- ootd <구간|스타일>). * 일교차가 크면(OUTER_GAP_C 이상) 겉옷을 5번째 옷으로 그린 <구간>-<사람>-<스타일>-outer.webp 를 쓰고 이름표에도 겉옷을 더한다 */ export type Outfit = { persona: string; label: string; style?: string; labels: string[]; outer: string; imageId: string; image?: string } export type OotdBand = { id: string; from: number } const IMAGES = import.meta.glob('../assets/ootd/*.webp', { eager: true, import: 'default' }) type Persona = keyof typeof spec.personas type StyleId = keyof typeof spec.styles const PERSONAS = Object.keys(spec.personas) as Persona[] export const OOTD_STYLES = (Object.keys(spec.styles) as StyleId[]).map((id) => ({ id, label: spec.styles[id].label })) export const DEFAULT_STYLE: StyleId = 'casual' const styleOf = (id?: string): StyleId => (id && id in spec.styles ? (id as StyleId) : DEFAULT_STYLE) export const styleLabel = (id?: string) => spec.styles[styleOf(id)].label export const OOTD_BANDS: OotdBand[] = spec.bands.map((b) => ({ id: b.id, from: b.from })) /** 아침·낮 기온 차가 이만큼이면 겉옷까지 보여 준다 (카드 날씨 줄의 '일교차 커요'와 같은 기준) */ export const OUTER_GAP_C = 8 export const needsOuter = (maxC: number, morningC: number) => maxC - morningC >= OUTER_GAP_C export function ootdBand(maxC: number) { return OOTD_BANDS.find((b) => maxC >= b.from) ?? OOTD_BANDS[OOTD_BANDS.length - 1] } /** 그날 무신사 스냅에서 뽑은 코디 (scripts/daily-ootd.mjs 가 copy.outfits 에 JSON 문자열로 넣는다). 없으면 undefined */ export function dailyOutfits(copy: Record): Outfit[] | undefined { if (!copy.outfits) return undefined try { const list = JSON.parse(copy.outfits) as { persona: string; label: string; style?: string; labels: string[]; image: string }[] return list.map((o) => ({ persona: o.persona, label: o.label, style: o.style, labels: o.labels, outer: '', imageId: o.image, image: o.image })) } catch { return undefined } } /** 그 구간·스타일의 사람별 옷. bandId 를 주면 기온 대신 그 구간 (예시 카드용). withOuter 면 겉옷 포함 그림·이름표 */ export function ootdOutfits(maxC: number, style?: string, bandId?: string, withOuter = false): Outfit[] { const band = spec.bands.find((b) => b.id === (bandId || ootdBand(maxC).id))! const st = styleOf(style) return PERSONAS.map((p) => { const o = band.outfits[st][p] const imageId = `${band.id}-${p}-${st}${withOuter ? '-outer' : ''}` return { persona: p, label: spec.personas[p].label, // 그림 윗줄 순서(상의 · 겉옷 · 하의)와 같게 겉옷을 두 번째에 labels: withOuter ? [o.labels[0], o.outer, ...o.labels.slice(1)] : o.labels, outer: o.outer, imageId, image: IMAGES[`../assets/ootd/${imageId}.webp`], } }) }