feat: 구름 합치기 라운드를 깰 때마다 2각(하루 20각), 탭바 없는 전체 화면, 1분 제한 없앰 — 판 시작 표(서명)로 남의 판·위조 거절, 레벨업 창은 판이 끝난 뒤
This commit is contained in:
1 parent
7d097a05de
commit
3df3e0113b
12 files changed
+414
-113
No files matched your search
@@ -1,16 +1,34 @@
|
||||
import { useEffect, useRef, useState, type PointerEvent } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { useNavigate } from 'react-router'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { getWeatherTodayOptions, myLevelQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
||||
import { gameRound, gameStart } from '@nalssigak/shared/api/client/sdk.gen'
|
||||
import type { ResLevel } from '@nalssigak/shared/api/client/types.gen'
|
||||
import { kst } from '@nalssigak/shared/lib'
|
||||
import { slotAt } from '@nalssigak/shared/lib/weatherText'
|
||||
import { cx } from '../lib/utils'
|
||||
import { createGame, DROP_Y, H, LEVELS, LINE_Y, loadBest, randomLevel, ROUND_MS, roundTarget, saveBest, W, windDir, type Game } from './cloudMerge'
|
||||
import { useAuth } from './authContext'
|
||||
import { createGame, DROP_Y, H, LEVELS, LINE_Y, loadBest, randomLevel, roundTarget, saveBest, W, windDir, type Game } from './cloudMerge'
|
||||
import { useLevel } from './level'
|
||||
import { iconSrc } from './lib'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { Ic, TAP44 } from './ui'
|
||||
|
||||
const gameEarned = (l: ResLevel | undefined) => l?.today?.find((a) => a.action === 'game')
|
||||
|
||||
/** 라운드를 깨면 서버에 알려 각을 받는다. 내 레벨은 판이 끝날 때 한 번에 바꿔, 게임 중에 레벨업 창이 뜨지 않게 한다 */
|
||||
async function claimRound(play: string, round: number) {
|
||||
try {
|
||||
const { data } = await gameRound({ body: { play, round } })
|
||||
return data.result?.success ? data : undefined
|
||||
} catch (e) {
|
||||
console.warn('[game] 라운드 각을 받지 못함', e)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const images = LEVELS.map((l) => {
|
||||
const img = new Image()
|
||||
img.src = iconSrc(l.icon) ?? ''
|
||||
@@ -67,6 +85,15 @@ export function CloudMergePage() {
|
||||
const navigate = useNavigate()
|
||||
const { region } = useRegion()
|
||||
const { open } = useSheet()
|
||||
const { loggedIn } = useAuth()
|
||||
const queryClient = useQueryClient()
|
||||
const level = useLevel().data
|
||||
const [earned, setEarned] = useState<number | null>(null)
|
||||
const [gain, setGain] = useState(0)
|
||||
const baseRef = useRef<number | undefined>(undefined)
|
||||
useEffect(() => {
|
||||
baseRef.current = gameEarned(level)?.earned
|
||||
}, [level])
|
||||
const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } }))
|
||||
const [now] = useState(() => kst(new Date()))
|
||||
const slots = today.data?.slots ?? []
|
||||
@@ -81,11 +108,10 @@ export function CloudMergePage() {
|
||||
const coolRef = useRef(0)
|
||||
const [score, setScore] = useState(0)
|
||||
const [best, setBest] = useState(loadBest)
|
||||
const [over, setOver] = useState<'full' | 'time' | null>(null)
|
||||
const [over, setOver] = useState(false)
|
||||
const [play, setPlay] = useState(0)
|
||||
const [round, setRound] = useState(1)
|
||||
const [roundGot, setRoundGot] = useState(0)
|
||||
const [leftSec, setLeftSec] = useState(ROUND_MS / 1000)
|
||||
const [flash, setFlash] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -99,20 +125,45 @@ export function CloudMergePage() {
|
||||
ctx.scale(ratio, ratio)
|
||||
let roundNo = 1
|
||||
let base = 0
|
||||
let left = ROUND_MS
|
||||
let flashTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let ticket: Promise<string | undefined> = Promise.resolve(undefined)
|
||||
let lastLevel: ResLevel | undefined
|
||||
let gotSoFar = baseRef.current
|
||||
const settle = () => {
|
||||
if (lastLevel) queryClient.setQueryData(myLevelQueryKey(), lastLevel)
|
||||
lastLevel = undefined
|
||||
}
|
||||
if (loggedIn) {
|
||||
ticket = gameStart()
|
||||
.then(({ data }) => data.play ?? undefined)
|
||||
.catch((e: unknown) => {
|
||||
console.warn('[game] 판을 열지 못함', e)
|
||||
return undefined
|
||||
})
|
||||
}
|
||||
const claim = async (round: number) => {
|
||||
const token = await ticket
|
||||
if (!token) return
|
||||
const res = await claimRound(token, round)
|
||||
const now = gameEarned(res)?.earned
|
||||
if (!res || now == null) return
|
||||
lastLevel = res
|
||||
if (gotSoFar != null && now > gotSoFar) setGain(now - gotSoFar)
|
||||
gotSoFar = now
|
||||
setEarned(now)
|
||||
}
|
||||
const game = createGame(windMs, dir, {
|
||||
onScore: (s) => {
|
||||
setScore(s)
|
||||
if (s - base >= roundTarget(roundNo)) {
|
||||
roundNo += 1
|
||||
base = s
|
||||
left = ROUND_MS
|
||||
setRound(roundNo)
|
||||
setLeftSec(ROUND_MS / 1000)
|
||||
setFlash(true)
|
||||
setGain(0)
|
||||
clearTimeout(flashTimer)
|
||||
flashTimer = setTimeout(() => setFlash(false), 1200)
|
||||
flashTimer = setTimeout(() => setFlash(false), 1400)
|
||||
void claim(roundNo - 1)
|
||||
}
|
||||
setRoundGot(s - base)
|
||||
if (s > loadBest()) {
|
||||
@@ -120,22 +171,16 @@ export function CloudMergePage() {
|
||||
setBest(s)
|
||||
}
|
||||
},
|
||||
onOver: () => setOver('full'),
|
||||
onOver: () => {
|
||||
setOver(true)
|
||||
settle()
|
||||
},
|
||||
})
|
||||
gameRef.current = game
|
||||
let last = performance.now()
|
||||
let raf = 0
|
||||
const loop = (t: number) => {
|
||||
game.step(t - last, t)
|
||||
if (left > 0 && !game.isOver()) {
|
||||
const sec = Math.ceil(left / 1000)
|
||||
left -= t - last
|
||||
if (left <= 0) {
|
||||
game.end()
|
||||
setLeftSec(0)
|
||||
setOver((o) => o ?? 'time')
|
||||
} else if (Math.ceil(left / 1000) !== sec) setLeftSec(Math.ceil(left / 1000))
|
||||
}
|
||||
last = t
|
||||
draw(ctx, game, aimRef.current, nextRef.current, game.danger())
|
||||
raf = requestAnimationFrame(loop)
|
||||
@@ -145,9 +190,10 @@ export function CloudMergePage() {
|
||||
cancelAnimationFrame(raf)
|
||||
clearTimeout(flashTimer)
|
||||
game.destroy()
|
||||
settle()
|
||||
gameRef.current = null
|
||||
}
|
||||
}, [today.isSuccess, windMs, dir, play])
|
||||
}, [today.isSuccess, windMs, dir, play, loggedIn, queryClient])
|
||||
|
||||
const toX = (e: PointerEvent<HTMLCanvasElement>) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect()
|
||||
@@ -167,90 +213,113 @@ export function CloudMergePage() {
|
||||
|
||||
const restart = () => {
|
||||
setScore(0)
|
||||
setOver(null)
|
||||
setOver(false)
|
||||
setRound(1)
|
||||
setRoundGot(0)
|
||||
setLeftSec(ROUND_MS / 1000)
|
||||
setPlay((n) => n + 1)
|
||||
}
|
||||
const cap = gameEarned(level)?.cap ?? 20
|
||||
const todayGak = earned ?? gameEarned(level)?.earned ?? 0
|
||||
const back = () => (window.history.state?.idx > 0 ? navigate(-1) : navigate('/'))
|
||||
const windText = windMs < 0.5 ? '바람 없음' : `${dir > 0 ? '→' : '←'} 초속 ${windMs.toFixed(1)}m`
|
||||
|
||||
return (
|
||||
<div className="pb-6">
|
||||
<div className="flex items-start gap-1 px-3 pt-1">
|
||||
<button type="button" onClick={back} aria-label="뒤로" className={cx('relative mt-0.5 grid size-9 shrink-0 cursor-pointer place-items-center rounded-full bg-white/80 text-[22px] font-bold shadow-[0_4px_10px_rgb(40_48_74/0.08)]', TAP44)}>
|
||||
‹
|
||||
</button>
|
||||
<div className="min-w-0 flex-1 px-1">
|
||||
<p className="m-0 flex items-center gap-1 text-[13px] font-extrabold opacity-75">
|
||||
<Ic name="cloud" className="size-4" />
|
||||
날씨게임 · {region.short_name} {windText}
|
||||
</p>
|
||||
<h2 className="m-0 mt-0.5 font-jua text-[26px] leading-tight font-normal">구름 합치기</h2>
|
||||
</div>
|
||||
<button type="button" onClick={() => open({ type: 'gameHelp' })} aria-label="게임 방법" className={cx('relative mt-0.5 grid size-9 shrink-0 cursor-pointer place-items-center rounded-full bg-white/80 text-[18px] font-extrabold text-(--ink2) shadow-[0_4px_10px_rgb(40_48_74/0.08)]', TAP44)}>
|
||||
?
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mx-3 mt-3 flex items-center justify-between text-[14px] font-extrabold">
|
||||
<span className="rounded-full bg-(--ink) px-3 py-1 text-[13px] text-white">{round}라운드</span>
|
||||
<span className={cx('font-jua text-[26px] leading-none font-normal tabular-nums', leftSec <= 10 ? 'text-[#e5484d]' : 'text-(--ink)')}>
|
||||
{Math.floor(leftSec / 60)}:{String(leftSec % 60).padStart(2, '0')}
|
||||
</span>
|
||||
<span className="flex items-center gap-1 opacity-75">
|
||||
다음 <Ic name={LEVELS[next].icon} className="size-6" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="mx-3 mt-2">
|
||||
<div className="h-2.5 overflow-hidden rounded-full bg-white/80">
|
||||
<i className="block h-full rounded-full bg-(--orange) transition-[width]" style={{ width: `${Math.min(100, (roundGot / roundTarget(round)) * 100)}%` }} />
|
||||
</div>
|
||||
<p className="m-0 mt-1 flex justify-between text-[12px] font-bold opacity-75">
|
||||
<span>
|
||||
목표 {roundGot} / {roundTarget(round)}
|
||||
</span>
|
||||
<span>
|
||||
총점 {score} · 최고 {best}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 하단 탭에 가리지 않게 화면 높이에 맞춰 폭을 줄인다 (위 머리말 약 210px + 아래 순서·탭 약 120px) */}
|
||||
<div className="relative mx-auto mt-2" style={{ width: 'min(100% - 24px, (100dvh - 330px) * 2 / 3)' }}>
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
onPointerMove={onMove}
|
||||
onPointerDown={onMove}
|
||||
onPointerUp={onUp}
|
||||
className="block aspect-[360/540] w-full touch-none rounded-[22px] bg-gradient-to-b from-[#cfe8ff] to-[#f3f9ff] shadow-[0_4px_14px_rgb(40_48_74/0.08)]"
|
||||
/>
|
||||
{!today.isSuccess && <p className="absolute inset-0 m-0 grid place-items-center text-[14px] font-bold opacity-60">{today.isError ? '날씨를 불러오지 못했어요' : '오늘 바람 불러오는 중…'}</p>}
|
||||
{flash && !over && <p className="pointer-events-none absolute inset-x-0 top-[30%] m-0 text-center font-jua text-[34px] text-(--orange) drop-shadow-[0_2px_0_white]">{round}라운드!</p>}
|
||||
{over && (
|
||||
<div className="absolute inset-0 grid place-items-center rounded-[22px] bg-white/75">
|
||||
<div className="text-center">
|
||||
<p className="m-0 font-jua text-[28px]">{over === 'time' ? '시간 끝!' : '넘쳤어요!'}</p>
|
||||
<p className="m-0 mt-1 text-[15px] font-bold">
|
||||
{round}라운드 · 총 {score}점{score >= best && score > 0 ? ' · 최고 기록' : ''}
|
||||
</p>
|
||||
<button type="button" onClick={restart} className="mt-4 cursor-pointer rounded-full bg-(--orange) px-6 py-2.5 text-[15px] font-extrabold text-white">
|
||||
다시 하기
|
||||
</button>
|
||||
</div>
|
||||
// 스택 화면: 머리줄·탭을 덮게 body 로 띄운다(main 이 쌓임 순서를 가둬서). b-app 의 낮 색을 그대로 써 밤에도 밝은 바탕
|
||||
return createPortal(
|
||||
<div className="b-app fixed inset-0 z-[45] touch-none bg-[linear-gradient(#d9edff,#f5faff)]">
|
||||
<div className="mx-auto flex h-full max-w-[440px] flex-col pt-[env(safe-area-inset-top,0px)] pb-[calc(10px+env(safe-area-inset-bottom,0px))] text-(--ink)">
|
||||
<div className="flex items-center gap-1 px-3 pt-2">
|
||||
<button type="button" onClick={back} aria-label="뒤로" className={cx('relative grid size-9 shrink-0 cursor-pointer place-items-center rounded-full bg-white/80 text-[22px] font-bold shadow-[0_4px_10px_rgb(40_48_74/0.08)]', TAP44)}>
|
||||
‹
|
||||
</button>
|
||||
<div className="min-w-0 flex-1 px-1">
|
||||
<h2 className="m-0 font-jua text-[22px] leading-tight font-normal">구름 합치기</h2>
|
||||
<p className="m-0 flex items-center gap-1 text-[12px] font-extrabold opacity-75">
|
||||
<Ic name="cloud" className="size-4" />
|
||||
{region.short_name} {windText}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mx-3 mt-3 flex flex-wrap items-center justify-center gap-x-1 gap-y-1 text-[12px] font-bold opacity-70">
|
||||
{LEVELS.map((l, i) => (
|
||||
<span key={l.icon} className="flex items-center gap-0.5">
|
||||
<Ic name={l.icon} className="size-5" />
|
||||
{i < LEVELS.length - 1 && '›'}
|
||||
<button type="button" onClick={() => open({ type: 'gameHelp' })} aria-label="게임 방법" className={cx('relative grid size-9 shrink-0 cursor-pointer place-items-center rounded-full bg-white/80 text-[18px] font-extrabold text-(--ink2) shadow-[0_4px_10px_rgb(40_48_74/0.08)]', TAP44)}>
|
||||
?
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mx-3 mt-2.5 flex items-center gap-2.5 text-[13px] font-extrabold">
|
||||
<span className="shrink-0 rounded-full bg-(--ink) px-3 py-1 text-white">{round}라운드</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="h-2.5 overflow-hidden rounded-full bg-white/80">
|
||||
<i className="block h-full rounded-full bg-(--orange) transition-[width]" style={{ width: `${Math.min(100, (roundGot / roundTarget(round)) * 100)}%` }} />
|
||||
</div>
|
||||
<p className="m-0 mt-0.5 text-[11px] font-bold opacity-75">
|
||||
다음 라운드까지 {roundGot} / {roundTarget(round)}
|
||||
</p>
|
||||
</div>
|
||||
<span className="flex shrink-0 items-center gap-1 opacity-75">
|
||||
다음 <Ic name={LEVELS[next].icon} className="size-6" />
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<p className="mx-3 mt-1 mb-0 flex justify-between text-[12px] font-bold">
|
||||
<span>
|
||||
점수 <b className="text-[16px] text-(--orange)">{score}</b> <span className="opacity-60">· 최고 {best}</span>
|
||||
</span>
|
||||
{loggedIn ? (
|
||||
<span className="opacity-75">
|
||||
오늘 게임 각 {todayGak} / {cap}
|
||||
</span>
|
||||
) : (
|
||||
<button type="button" onClick={() => open({ type: 'login' })} className="cursor-pointer p-0 text-[12px] font-extrabold text-(--orange-deep) underline underline-offset-2">
|
||||
로그인하면 라운드마다 +2각
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
|
||||
{/* 남은 높이를 다 쓰되 2:3 비율은 지킨다 */}
|
||||
<div className="mt-2 grid min-h-0 flex-1 place-items-center px-3 [container-type:size]">
|
||||
<div className="relative aspect-[2/3]" style={{ width: 'min(100cqw, 100cqh * 2 / 3)' }}>
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
onPointerMove={onMove}
|
||||
onPointerDown={onMove}
|
||||
onPointerUp={onUp}
|
||||
className="block size-full touch-none rounded-[22px] bg-gradient-to-b from-[#cfe8ff] to-[#f3f9ff] shadow-[0_4px_14px_rgb(40_48_74/0.08)]"
|
||||
/>
|
||||
{!today.isSuccess && <p className="absolute inset-0 m-0 grid place-items-center text-[14px] font-bold opacity-60">{today.isError ? '날씨를 불러오지 못했어요' : '오늘 바람 불러오는 중…'}</p>}
|
||||
{flash && !over && (
|
||||
<p className="pointer-events-none absolute inset-x-0 top-[30%] m-0 text-center font-jua text-[34px] leading-tight text-(--orange) drop-shadow-[0_2px_0_white]">
|
||||
{round}라운드!
|
||||
{gain > 0 && <span className="block text-[22px] text-(--ink)">+{gain}각</span>}
|
||||
</p>
|
||||
)}
|
||||
{over && (
|
||||
<div className="absolute inset-0 grid place-items-center rounded-[22px] bg-white/75">
|
||||
<div className="text-center">
|
||||
<p className="m-0 font-jua text-[28px]">넘쳤어요!</p>
|
||||
<p className="m-0 mt-1 text-[15px] font-bold">
|
||||
{round}라운드 · 총 {score}점{score >= best && score > 0 ? ' · 최고 기록' : ''}
|
||||
</p>
|
||||
{loggedIn && (
|
||||
<p className="m-0 mt-1 text-[13px] font-bold opacity-75">
|
||||
오늘 게임 각 {todayGak} / {cap}
|
||||
</p>
|
||||
)}
|
||||
<button type="button" onClick={restart} className="mt-4 cursor-pointer rounded-full bg-(--orange) px-6 py-2.5 text-[15px] font-extrabold text-white">
|
||||
다시 하기
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mx-3 mt-2 flex items-center justify-center gap-x-1 text-[12px] font-bold opacity-70">
|
||||
{LEVELS.map((l, i) => (
|
||||
<span key={l.icon} className="flex items-center gap-0.5">
|
||||
<Ic name={l.icon} className="size-5" />
|
||||
{i < LEVELS.length - 1 && '›'}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
)
|
||||
}
|
||||
@@ -525,12 +525,13 @@ function ArticleSheet({ articleId, onTitle }: { articleId: number; onTitle: (t:
|
||||
|
||||
/* ---------- 이번 주 특집 ---------- */
|
||||
const GAME_STEPS = [
|
||||
'라운드마다 60초 안에 목표 점수를 채우면 다음 라운드로 넘어가요. 라운드가 오를수록 목표가 높아져요.',
|
||||
'목표 점수를 채우면 다음 라운드로 넘어가요. 라운드가 오를수록 목표가 높아져요.',
|
||||
'손가락을 좌우로 움직여 떨어뜨릴 자리를 고르고, 손을 떼면 떨어져요.',
|
||||
'떨어지는 동안 오늘 우리 동네 바람만큼 옆으로 밀려요. 바람 방향을 보고 조금 비켜 떨어뜨리세요.',
|
||||
'같은 그림끼리 닿으면 한 단계 큰 그림으로 합쳐지고 점수가 올라요.',
|
||||
'해 둘이 만나면 사라지면서 보너스 점수!',
|
||||
'시간 안에 목표를 못 채우거나, 쌓인 그림이 위쪽 점선을 넘은 채로 잠깐 있으면 끝나요. 판은 다음 라운드로 그대로 이어져요.',
|
||||
'쌓인 그림이 위쪽 점선을 넘은 채로 잠깐 있으면 끝나요. 판은 다음 라운드로 그대로 이어져요.',
|
||||
'로그인하면 라운드를 깰 때마다 2각을 받아요. 하루 20각까지예요.',
|
||||
]
|
||||
|
||||
function GameHelpSheet() {
|
||||
|
||||
@@ -25,8 +25,7 @@ const MAX_WIND = 12
|
||||
/** 처음 떨어뜨리는 건 작은 4단계 중에서 */
|
||||
const SPAWN_MAX = 3
|
||||
const SUN_BONUS = 66
|
||||
/** 라운드마다 주어지는 시간. 그 안에 목표 점수를 넘기면 다음 라운드, 못 넘기면 끝 */
|
||||
export const ROUND_MS = 60_000
|
||||
/** 라운드마다 이만큼 점수를 더 내면 다음 라운드 */
|
||||
export const roundTarget = (round: number) => 200 + 80 * (round - 1)
|
||||
|
||||
export const pointsFor = (level: number) => ((level + 1) * (level + 2)) / 2
|
||||
@@ -89,7 +88,7 @@ export function createGame(windMs: number, dir: number, ev: GameEvents) {
|
||||
|
||||
const step = (dt: number, now: number) => {
|
||||
if (over) return
|
||||
Matter.Engine.update(engine, Math.min(dt, 1000 / 30))
|
||||
Matter.Engine.update(engine, Math.min(dt, 1000 / 60))
|
||||
for (const p of pieces()) {
|
||||
const above = !p.falling && p.position.y - LEVELS[p.level].r < LINE_Y
|
||||
p.overSince = above ? (p.overSince ?? now) : null
|
||||
@@ -111,11 +110,7 @@ export function createGame(windMs: number, dir: number, ev: GameEvents) {
|
||||
/** 위험선 근처에 있는지: 선을 빨갛게 보여 줄 때 */
|
||||
const danger = () => pieces().some((p) => !p.falling && p.position.y - LEVELS[p.level].r < LINE_Y + 40)
|
||||
|
||||
const end = () => {
|
||||
over = true
|
||||
}
|
||||
|
||||
return { step, drop, end, isOver: () => over, pieces, danger, wind, destroy: () => Matter.Engine.clear(engine) }
|
||||
return { step, drop, pieces, danger, wind, destroy: () => Matter.Engine.clear(engine) }
|
||||
}
|
||||
|
||||
export type Game = ReturnType<typeof createGame>
|
||||
|
||||
Reference in new issue
Block a user