Files
o2o-weather/frontend/src/b/holiday.ts
T
minaChoi 4fec164364 feat: 기념일 꾸밈 — 할로윈·빼빼로데이·크리스마스·추석 기간에만 이야기 주제와 구름 합치기 그림이 바뀜
frontend/src/b/holiday.ts 한 곳에 기간·주제·배경·게임 그림. ?holiday=<key> 로 미리 보기.
GA: game_start theme 추가, talk_post topic 6~9.
2026-10-30 09:15:53 +09:00

116 lines
3.8 KiB
TypeScript

import { TalkTopic } from '@nalssigak/shared/api/client/types.gen'
import { kst } from '@nalssigak/shared/lib'
/** 게임 8단계 그림을 바꾼다. 작은 것부터 큰 것 순서, 크기·색은 원래 단계 그대로 */
type GamePiece = { icon: string; name: string }
/**
* 기념일 꾸밈. 기간(KST, 양 끝 포함) 안에만 켜진다. 'MM-DD' 는 해마다, 'YYYY-MM-DD' 는 그해만(음력 기념일).
* 새 기념일: 여기에 한 줄 + TalkTopic(backend/common/enums.py) + 그림(public/b/icons, lib.ts OWN)
*/
export type Holiday = {
key: 'halloween' | 'pepero' | 'christmas' | 'chuseok'
name: string
ranges: readonly (readonly [string, string])[]
topic: TalkTopic
/** 글만 있는 사람 글 배경 (b.css b-bg-*) */
bg: string
game: readonly GamePiece[]
}
export const HOLIDAYS: readonly Holiday[] = [
{
key: 'halloween',
name: '할로윈',
ranges: [['10-31', '11-01']],
topic: TalkTopic.HALLOWEEN,
bg: 'night',
game: [
{ icon: 'candy', name: '사탕' },
{ icon: 'lollipop', name: '막대사탕' },
{ icon: 'spider', name: '거미' },
{ icon: 'spider_web', name: '거미줄' },
{ icon: 'bat', name: '박쥐' },
{ icon: 'ghost', name: '유령' },
{ icon: 'skull', name: '해골' },
{ icon: 'jack_o_lantern', name: '호박등' },
],
},
{
key: 'pepero',
name: '빼빼로데이',
ranges: [['11-11', '11-11']],
topic: TalkTopic.PEPERO,
bg: 'peach',
game: [
{ icon: 'candy', name: '사탕' },
{ icon: 'cookie', name: '쿠키' },
{ icon: 'chocolate_bar', name: '초콜릿' },
{ icon: 'ribbon', name: '리본' },
{ icon: 'love_letter', name: '편지' },
{ icon: 'red_heart', name: '하트' },
{ icon: 'heart_with_ribbon', name: '리본 하트' },
{ icon: 'wrapped_gift', name: '선물' },
],
},
{
key: 'christmas',
name: '크리스마스',
ranges: [['12-24', '12-25']],
topic: TalkTopic.CHRISTMAS,
bg: 'mint',
game: [
{ icon: 'snowflake', name: '눈송이' },
{ icon: 'star', name: '별' },
{ icon: 'bell', name: '종' },
{ icon: 'socks', name: '양말' },
{ icon: 'cookie', name: '쿠키' },
{ icon: 'wrapped_gift', name: '선물' },
{ icon: 'snowman', name: '눈사람' },
{ icon: 'christmas_tree', name: '트리' },
],
},
{
key: 'chuseok',
name: '추석',
ranges: [['2027-09-14', '2027-09-16']],
topic: TalkTopic.CHUSEOK,
bg: 'butter',
game: [
{ icon: 'chestnut', name: '밤' },
{ icon: 'pear', name: '배' },
{ icon: 'apple', name: '사과' },
{ icon: 'dango', name: '떡' },
{ icon: 'rabbit', name: '토끼' },
{ icon: 'maple', name: '단풍' },
{ icon: 'moon_viewing', name: '달맞이' },
{ icon: 'full_moon', name: '보름달' },
],
},
]
const pad = (n: number) => String(n).padStart(2, '0')
function inRange([from, to]: readonly [string, string], y: number, md: string) {
const day = from.length === 10 ? `${y}-${md}` : md
return from <= day && day <= to
}
/** 미리 보기 기념일: 주소의 ?holiday= 를 탭이 닫힐 때까지 기억 */
function previewKey() {
const q = new URLSearchParams(location.search).get('holiday')
if (q) sessionStorage.setItem('holiday', q)
return q ?? sessionStorage.getItem('holiday')
}
/** 오늘(KST) 켜진 기념일. ?holiday=christmas 로 미리 보기 */
export function currentHoliday(now = new Date()): Holiday | undefined {
const preview = previewKey()
if (preview) return HOLIDAYS.find((h) => h.key === preview)
const { y, mo, d } = kst(now)
const md = `${pad(mo)}-${pad(d)}`
return HOLIDAYS.find((h) => h.ranges.some((r) => inRange(r, y, md)))
}
export const holidayByTopic = (t?: number) => HOLIDAYS.find((h) => h.topic === t)