증강 윷놀이: 증강 칩·증강 쓰기 버튼의 설명을 브라우저 title 대신 팝업 카드로(마우스 올리기·키보드 포커스, 휴대폰은 눌러서)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
* 증강 윷놀이 screen parts (docs/games/yut-augmented.md §화면): augment selection, prompts, popups, the "내 증강" panel,
|
||||
* board objects, fog, special-piece badges and the 알까기 aim / replay. Used by index.tsx only when `view.aug` exists.
|
||||
*/
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type FocusEvent, type PointerEvent as ReactPointerEvent } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import type { AugFx, AugUseOption, PieceKind, YutAugView, YutView } from '@bg/games/yut';
|
||||
import { AUGS, KIND_KO, TIER_KO, type AugId } from '@bg/games/yut/augments';
|
||||
import { NODE_POS } from '@bg/games/yut/board';
|
||||
@@ -63,7 +64,16 @@ export const AUG_CSS = `
|
||||
.aug-board-wrap { position: relative; }
|
||||
.aug-aim { touch-action: none; cursor: crosshair; }
|
||||
.sheet:has(.aug-cards) { width: min(100%, 780px); }
|
||||
@media (prefers-reduced-motion: reduce) { .aug-toast { animation: none; } }
|
||||
.aug-pop { position: fixed; z-index: 1000; width: max-content; max-width: min(300px, calc(100vw - 16px)); pointer-events: none; text-align: left;
|
||||
border: 3px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 10px 12px;
|
||||
display: flex; flex-direction: column; gap: 6px; box-shadow: 0 10px 28px rgba(0, 0, 0, .28); animation: aug-pop .12s ease both; }
|
||||
.aug-pop.win { border-color: #f59e0b; }
|
||||
.aug-pop h3 { margin: 0; font-size: 1.05rem; }
|
||||
.aug-pop p { margin: 0; font-size: .9rem; }
|
||||
.aug-pop .aug-pop-state { font-weight: 800; color: var(--danger); }
|
||||
.aug-chip[tabindex] { cursor: help; }
|
||||
@keyframes aug-pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .aug-toast, .aug-pop { animation: none; } }
|
||||
`;
|
||||
|
||||
// ---------------------------------------------------------------- round bar
|
||||
@@ -82,6 +92,109 @@ export function AugRoundBar({ v }: { v: YutView }) {
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- augment popup (hover / focus / tap)
|
||||
|
||||
type PopInfo = { id: AugId; state: string[] };
|
||||
|
||||
/** Card that explains one augment, placed under (or above) the element it describes. */
|
||||
function AugPopCard({ el, id, state, popId }: PopInfo & { el: HTMLElement; popId: string }) {
|
||||
const m = AUGS[id];
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const [pos, setPos] = useState<{ left: number; top: number } | null>(null);
|
||||
const stateKey = state.join('|');
|
||||
useLayoutEffect(() => {
|
||||
const r = el.getBoundingClientRect();
|
||||
const p = ref.current!.getBoundingClientRect();
|
||||
const gap = 8;
|
||||
let top = r.bottom + gap;
|
||||
if (top + p.height > window.innerHeight - gap && r.top - gap - p.height >= gap) top = r.top - gap - p.height;
|
||||
const left = Math.min(Math.max(gap, r.left + r.width / 2 - p.width / 2), window.innerWidth - gap - p.width);
|
||||
setPos({ left, top });
|
||||
}, [el, id, stateKey]);
|
||||
return (
|
||||
<div ref={ref} id={popId} role="tooltip" className={`aug-pop${m.win ? ' win' : ''}`} style={pos ?? { left: 0, top: 0, visibility: 'hidden' }}>
|
||||
<span className="aug-card-head">
|
||||
<AugIcon id={id} size={44} />
|
||||
<h3>{m.name}</h3>
|
||||
</span>
|
||||
<span className="aug-tags">
|
||||
<span className="aug-tag">{TIER_KO[m.tier]}</span>
|
||||
<span className="aug-tag">{KIND_KO[m.kind]}</span>
|
||||
{m.once && <span className="aug-tag">1회</span>}
|
||||
{m.win && m.kind !== 'win' && <span className="aug-tag win">승리 조건</span>}
|
||||
{m.custom && <span className="aug-tag custom">추가</span>}
|
||||
</span>
|
||||
<p>{m.text}</p>
|
||||
{m.note && <p className="small muted">{m.note}</p>}
|
||||
{state.map((t) => (
|
||||
<p key={t} className="small aug-pop-state">
|
||||
{t}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Explanation popup for augment chips/buttons instead of the browser's title tooltip:
|
||||
* mouse hover and keyboard focus show it, a finger tap toggles it (when `tap` is set), Esc / scroll / tapping elsewhere closes it.
|
||||
* `info(key)` is read on every render so the card follows live state (used, cat …) and disappears with its augment.
|
||||
*/
|
||||
function useAugPop(info: (key: number) => PopInfo | null) {
|
||||
const popId = useId();
|
||||
const [pop, setPop] = useState<{ key: number; el: HTMLElement; pinned: boolean } | null>(null);
|
||||
const lastPointer = useRef('mouse');
|
||||
useEffect(() => {
|
||||
if (!pop) return;
|
||||
const close = () => setPop(null);
|
||||
const down = (e: PointerEvent) => {
|
||||
if (!pop.el.contains(e.target as Node)) close();
|
||||
};
|
||||
const key = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') close();
|
||||
};
|
||||
window.addEventListener('scroll', close, true);
|
||||
window.addEventListener('resize', close);
|
||||
document.addEventListener('pointerdown', down, true);
|
||||
document.addEventListener('keydown', key);
|
||||
return () => {
|
||||
window.removeEventListener('scroll', close, true);
|
||||
window.removeEventListener('resize', close);
|
||||
document.removeEventListener('pointerdown', down, true);
|
||||
document.removeEventListener('keydown', key);
|
||||
};
|
||||
}, [pop]);
|
||||
const hide = (el: HTMLElement) => setPop((p) => (p && p.el === el && !p.pinned ? null : p));
|
||||
const bind = (key: number, tap = false) => ({
|
||||
'aria-describedby': pop?.key === key ? popId : undefined,
|
||||
onPointerDown: (e: ReactPointerEvent<HTMLElement>) => {
|
||||
lastPointer.current = e.pointerType;
|
||||
},
|
||||
onPointerEnter: (e: ReactPointerEvent<HTMLElement>) => {
|
||||
if (e.pointerType === 'mouse') setPop({ key, el: e.currentTarget, pinned: false });
|
||||
},
|
||||
onPointerLeave: (e: ReactPointerEvent<HTMLElement>) => {
|
||||
if (e.pointerType === 'mouse') hide(e.currentTarget);
|
||||
},
|
||||
onFocus: (e: FocusEvent<HTMLElement>) => {
|
||||
if (e.currentTarget.matches(':focus-visible')) setPop({ key, el: e.currentTarget, pinned: false });
|
||||
},
|
||||
onBlur: (e: FocusEvent<HTMLElement>) => hide(e.currentTarget),
|
||||
...(tap
|
||||
? {
|
||||
onClick: (e: { currentTarget: HTMLElement }) => {
|
||||
if (lastPointer.current === 'mouse') return;
|
||||
const el = e.currentTarget;
|
||||
setPop((p) => (p && p.el === el && p.pinned ? null : { key, el, pinned: true }));
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
const shown = pop && pop.el.isConnected ? info(pop.key) : null;
|
||||
const node = pop && shown ? createPortal(<AugPopCard el={pop.el} popId={popId} {...shown} />, document.body) : null;
|
||||
return { bind, node };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- slots in the side card
|
||||
|
||||
export function AugSlots({ v, side }: { v: YutView; side: number }) {
|
||||
@@ -94,6 +207,16 @@ export function AugSlots({ v, side }: { v: YutView; side: number }) {
|
||||
if (s.queenLives !== null) info.push(`👑 목숨 ${s.queenLives}`);
|
||||
if (s.cursed) info.push('🪆 저주: 다음 차례 도만');
|
||||
for (const l of s.links) info.push(`${l.by === 'leech' ? '🩸 거머리' : '💀 네크로'} → ${augSideName(l.to)}${l.on ? '' : ' (멈춤)'}`);
|
||||
const pop = useAugPop((uid) => {
|
||||
const o = s.augs.find((x) => x.uid === uid);
|
||||
if (!o) return null;
|
||||
const state: string[] = [];
|
||||
if (o.used) state.push('✔ 이미 썼어요');
|
||||
if (o.voided) state.push('무효가 됐어요');
|
||||
if (o.catUntil !== null) state.push(`🐱 ${o.catUntil}라운드까지 고양이(효과 멈춤)`);
|
||||
if (o.note) state.push(o.note);
|
||||
return { id: o.id, state };
|
||||
});
|
||||
return (
|
||||
<>
|
||||
{info.length > 0 && <div className="small muted" style={{ marginTop: 6 }}>{info.join(' · ')}</div>}
|
||||
@@ -106,7 +229,8 @@ export function AugSlots({ v, side }: { v: YutView; side: number }) {
|
||||
<span
|
||||
key={o.uid}
|
||||
className={`aug-chip${o.used ? ' used' : ''}${o.voided ? ' voided' : ''}${cat ? ' cat' : ''}${meta.win ? ' win' : ''}`}
|
||||
title={`${meta.name}: ${meta.text}${meta.note ? ` (${meta.note})` : ''}`}
|
||||
tabIndex={0}
|
||||
{...pop.bind(o.uid, true)}
|
||||
aria-label={`${meta.name}${o.used ? ' (사용함)' : ''}${o.voided ? ' (무효)' : ''}${cat ? ` (${o.catUntil}라운드까지 고양이)` : ''}${o.note ? `, ${o.note}` : ''}`}
|
||||
>
|
||||
<AugIcon id={o.id} size={22} cat={cat} />
|
||||
@@ -116,6 +240,7 @@ export function AugSlots({ v, side }: { v: YutView; side: number }) {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{pop.node}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -389,6 +514,10 @@ export function AugUses({
|
||||
for (const u of a.uses) m.set(u.uid, [...(m.get(u.uid) ?? []), u]);
|
||||
return m;
|
||||
}, [a.uses]);
|
||||
const pop = useAugPop((uid) => {
|
||||
const o = byUid.get(uid)?.[0];
|
||||
return o ? { id: o.id, state: AUGS[o.id].wholeTurn ? ['쓰면 이번 차례가 끝나요'] : [] } : null;
|
||||
});
|
||||
const specials = a.specials;
|
||||
if (!byUid.size && !specials.length) return null;
|
||||
const use = (u: AugUseOption) => {
|
||||
@@ -415,7 +544,7 @@ export function AugUses({
|
||||
className={`btn btn-sm ${targetUid === uid ? 'btn-primary' : 'btn-secondary'}`}
|
||||
disabled={pending}
|
||||
aria-pressed={targetUid === uid}
|
||||
title={AUGS[id].text}
|
||||
{...pop.bind(uid)}
|
||||
onClick={() => {
|
||||
setAim(null);
|
||||
if (opts.length === 1 && id !== 'alkkagi' && !['sniper', 'mine'].includes(id)) setTargetUid(uid);
|
||||
@@ -497,6 +626,7 @@ export function AugUses({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{pop.node}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1747,6 +1747,37 @@ const PLANS: Record<string, Plan> = {
|
||||
seen.add('objs');
|
||||
await host.locator('.yut-board').screenshot({ path: join(SHOTS, 'yut-aug-objs-board.png') });
|
||||
}
|
||||
// 증강 칩 설명은 브라우저 title 대신 팝업 카드: PC는 마우스를 올리면, 휴대폰은 칩을 누르면 뜬다(남의 증강도)
|
||||
if (!seen.has('chip-pop') && !(await host.getByRole('dialog').count()) && (await host.locator('.aug-chip').count()) >= 2) {
|
||||
seen.add('chip-pop');
|
||||
const pop = (p: Page) => p.locator('.aug-pop[role="tooltip"]');
|
||||
for (const p of [host, guest]) {
|
||||
const chips = p.locator('.aug-chip');
|
||||
if ((await chips.count()) < 2) throw new Error('augment chips missing');
|
||||
for (const i of [0, 1]) {
|
||||
const chip = chips.nth(i);
|
||||
if (await chip.getAttribute('title')) throw new Error('augment chip still uses a title tooltip');
|
||||
if (p === host) await chip.hover();
|
||||
else await chip.tap();
|
||||
await pop(p).waitFor({ timeout: 3000 });
|
||||
const name = await pop(p).getByRole('heading').innerText();
|
||||
if (!(await chip.getAttribute('aria-label'))?.startsWith(name)) throw new Error(`popup shows ${name}, not the chip's augment`);
|
||||
if ((await pop(p).count()) !== 1) throw new Error('more than one augment popup');
|
||||
if ((await chip.getAttribute('aria-describedby')) !== (await pop(p).getAttribute('id'))) throw new Error('popup not linked to chip');
|
||||
const box = (await pop(p).boundingBox())!;
|
||||
const vp = p.viewportSize()!;
|
||||
if (box.x < 0 || box.y < 0 || box.x + box.width > vp.width || box.y + box.height > vp.height) throw new Error(`augment popup off screen ${JSON.stringify(box)}`);
|
||||
if (i === 0) {
|
||||
await p.waitForTimeout(250);
|
||||
await p.screenshot({ path: join(SHOTS, `yut-aug-chip-pop-${tag(p)}.png`) });
|
||||
}
|
||||
}
|
||||
if (p === host) await p.mouse.move(2, 2);
|
||||
else await p.locator('.aug-bar').first().tap();
|
||||
await pop(p).waitFor({ state: 'detached', timeout: 3000 });
|
||||
}
|
||||
console.log(' yut-aug: chip popups ok (hover on PC, tap on phone)');
|
||||
}
|
||||
if (steps === 30 || steps === 120 || steps === 200) {
|
||||
await host.screenshot({ path: join(SHOTS, `yut-aug-mid${steps}-pc.png`) });
|
||||
await guest.screenshot({ path: join(SHOTS, `yut-aug-mid${steps}-phone.png`), fullPage: true });
|
||||
|
||||
Reference in New Issue
Block a user