feat: 사주 명식 카드 — 오행 세력 막대·가장 센 오행 그림, 신강·신약, 기둥별 십성·일간 '나'·월령, 용어 풀이 (API me.elements·strong·십성 추가, GA saju_view 에 strength·top_element)

This commit is contained in:
minaChoi committed 2026-10-29 13:15:51 +09:00
1 parent 63db0b725b
commit d7f891fddb
14 files changed
+131 -15

No files matched your search

+74 -11
View File
@@ -17,6 +17,21 @@ const SEEN_KEY = 'nalssigak.b.sajuSeen'
const EL_COLOR: Record<string, [string, string]> = { 木: ['#2f8a4c', '#e3f6ea'], 火: ['#d9442f', '#ffe6e0'], 土: ['#a8761a', '#fbf0d6'], 金: ['#6b7486', '#eef0f4'], 水: ['#2d4a8a', '#e3ebfb'] }
const CARD_ICON: Record<string, string> = { when: 'alarm_clock', do: 'check_mark_button', avoid: 'warning', good: 'sparkles', wear: 'tshirt' }
const POS_WORD: Record<string, string> = { hour: '시', day: '일', month: '월', year: '연' }
const EL_WORD: Record<string, string> = { 木: '나무', 火: '불', 土: '흙', 金: '쇠', 水: '물' }
const EL_ART: Record<string, string> = { 木: 'wood', 火: 'fire', 土: 'earth', 金: 'metal', 水: 'water' }
const STRENGTH_WORD: Record<string, string> = { 신강: '나를 돕는 기운이 절반이 넘는 사주', 신약: '나를 돕는 기운이 절반보다 적은 사주' }
const TEN_GOD_WORD: Record<string, string> = {
비견: '나와 같은 기운',
겁재: '나와 같지만 겨루는 기운',
식신: '내가 만들어 내는 기운',
상관: '내가 드러내는 기운',
편재: '내가 크게 굴리는 재물',
정재: '내가 차곡차곡 모으는 재물',
편관: '나를 세게 다잡는 기운',
정관: '나를 바르게 이끄는 기운',
편인: '나를 돕는 남다른 지혜',
정인: '나를 돕는 배움·도움',
}
const HOURS = Array.from({ length: 24 }, (_, i) => i)
const MINUTES = Array.from({ length: 60 }, (_, i) => i)
const dayWord = (iso: string, weekday: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}(${weekday})`
@@ -192,7 +207,7 @@ function Reading({ birth, onEdit }: { birth: Birth; onEdit: () => void }) {
useEffect(() => {
if (!r?.today) return
markSeen()
track('saju_view', { scene: r.me?.scene ?? '', score: r.today.score })
track('saju_view', { scene: r.me?.scene ?? '', score: r.today.score, strength: r.me?.strong == null ? '' : r.me.strong ? '신강' : '신약', top_element: r.me?.top_element ?? '' })
}, [r])
if (q.isPending) return <p className="m-0 px-4 py-16 text-center font-semibold text-(--ink2)">사주를 풀고 있어요…</p>
@@ -292,37 +307,85 @@ function DecisionCard({ c }: { c: SajuCard }) {
function MeCard({ r, onEdit }: { r: ResSaju; onEdit: () => void }) {
const me = r.me!
const cols = [...me.pillars].reverse()
const els = Object.entries(me.elements ?? {})
const total = els.reduce((a, [, v]) => a + v, 0)
const gods = [...new Set(me.pillars.flatMap((p) => [p.stem_ten_god, p.branch_ten_god]).filter((g): g is string => !!g && g in TEN_GOD_WORD))]
const strength = me.strong == null ? null : me.strong ? '신강' : '신약'
return (
<Panel icon={me.scene_icon} title={`내 기운 · ${me.scene.replace(/ 기운$/, '')}`} right={<button type="button" onClick={onEdit} className="cursor-pointer text-xs font-extrabold text-(--orange)">생년월일 바꾸기</button>}>
<p className="m-0 text-[14px] font-semibold text-(--ink2)">{me.scene_desc}</p>
<Panel icon={me.scene_icon} title="사주 명식" right={<button type="button" onClick={onEdit} className="cursor-pointer text-xs font-extrabold text-(--orange)">생년월일 바꾸기</button>}>
{me.top_element && strength && (
<div className="flex items-center gap-3">
<img src={`/saju/${EL_ART[me.top_element]}.webp`} alt="" className="size-16 shrink-0 object-contain" />
<div className="min-w-0">
<p className="m-0 font-jua text-[18px] leading-snug">
{EL_WORD[me.top_element]}({me.top_element}) 기운이 가장 센 {strength} 사주
</p>
<p className="m-0 mt-0.5 text-[13px] font-semibold text-(--ink2)">
나를 돕는 기운 {Math.round((me.support ?? 0) * 100)}% · {me.scene}
</p>
</div>
</div>
)}
{total > 0 && (
<>
<div className="mt-2.5 flex h-2.5 overflow-hidden rounded-full" role="img" aria-label={els.map(([k, v]) => `${k} ${Math.round(v)}`).join(', ')}>
{els.map(([k, v]) => (
<span key={k} style={{ width: `${(v / total) * 100}%`, background: EL_COLOR[k]?.[0] }} />
))}
</div>
<div className="mt-1.5 flex justify-between text-[12px] font-extrabold">
{els.map(([k, v]) => (
<span key={k} className="flex items-center gap-0.5" style={{ color: EL_COLOR[k]?.[0] }}>
<img src={`/saju/${EL_ART[k]}.webp`} alt="" className="size-5 object-contain" />
{k} {Math.round(v)}
</span>
))}
</div>
</>
)}
<div className="mt-3 grid grid-cols-4 gap-1.5 text-center">
{(me.hour_known ? cols : [null, ...cols]).map((p, i) => (
<div key={p?.position ?? `none-${i}`} className="flex flex-col gap-1">
<span className="text-[11px] font-extrabold text-(--ink3)">{p ? POS_WORD[p.position] : '시'}</span>
<span className="text-[11px] font-extrabold text-(--ink3)">{p ? `${POS_WORD[p.position]}주` : '시주'}</span>
{p ? (
<>
<Char c={p.stem} ko={p.stem_ko} el={p.stem_element} />
<span className={cx('text-[11.5px] font-extrabold', p.position === 'day' ? 'text-(--orange)' : 'text-(--ink2)')}>{p.position === 'day' ? '나' : p.stem_ten_god}</span>
<Char c={p.stem} ko={p.stem_ko} el={p.stem_element} me={p.position === 'day'} />
<Char c={p.branch} ko={p.branch_ko} el={p.branch_element} />
<span className="text-[11.5px] font-extrabold text-(--ink2)">{p.branch_ten_god}</span>
{p.position === 'month' && <span className="text-[10.5px] font-extrabold text-(--ink3)">월령</span>}
</>
) : (
<>
<span className="grid flex-1 place-items-center rounded-xl bg-[#f1f3f7] text-[12px] font-extrabold text-[#a0a8ba]">시각 모름</span>
</>
<span className="grid flex-1 place-items-center rounded-xl bg-[#f1f3f7] px-1 text-[12px] font-extrabold text-[#a0a8ba]">시각 모름</span>
)}
</div>
))}
</div>
<p className="m-0 mt-2 text-[11.5px] font-semibold text-(--ink3)">태어난 연·월·일·시의 여덟 글자(사주팔자)예요. 색은 나무·불·흙·쇠·물 다섯 기운이에요.</p>
<ul className="m-0 mt-3 list-none border-t border-(--line) p-0 pt-2.5 text-[12.5px] leading-relaxed font-semibold text-(--ink2)">
{strength && (
<li>
<b className="text-(--ink)">{strength}</b> = {STRENGTH_WORD[strength]}
</li>
)}
{gods.map((g) => (
<li key={g}>
<b className="text-(--ink)">{g}</b> = {TEN_GOD_WORD[g]}
</li>
))}
<li>
<b className="text-(--ink)">월령</b> = 태어난 달의 계절 기운. 명식에서 가장 크게 봐요
</li>
</ul>
{(me.need?.length ?? 0) > 0 && <p className="m-0 mt-2 text-[13px] font-bold">내 기운에 좋은 날씨: {me.need!.join(' · ')}</p>}
{me.jeol_warning && <p className="m-0 mt-1 text-xs font-semibold text-[#c2471b]">태어난 날에 절기가 바뀌어요. 태어난 시각을 넣어야 달 기둥이 정확해요.</p>}
</Panel>
)
}
function Char({ c, ko, el }: { c: string; ko: string; el: string }) {
function Char({ c, ko, el, me }: { c: string; ko: string; el: string; me?: boolean }) {
const [fg, bg] = EL_COLOR[el] ?? ['#28304a', '#f3f6fb']
return (
<span className="rounded-xl py-1.5" style={{ background: bg, color: fg }}>
<span className={cx('rounded-xl py-1.5', me && 'ring-2 ring-(--orange)')} style={{ background: bg, color: fg }}>
<b className="block font-batang text-[22px] leading-tight">{c}</b>
<small className="text-[10.5px] font-extrabold">{ko}</small>
</span>
+1 -1
View File
@@ -32,7 +32,7 @@ type Events = {
day_log: { mood: number; went_out: boolean; card_hit: boolean | null }
today_icon: { icon: string }
saju_input: { with_time: boolean }
saju_view: { scene: string; score: number }
saju_view: { scene: string; score: number; strength: string; top_element: string }
game_start: { again: boolean; logged_in: boolean; wind_ms: number }
game_round: { round: number; score: number; logged_in: boolean }
game_over: { round: number; score: number; best: boolean; drops: number }