diff --git a/public/assets/cats/bengal/cook.png b/public/assets/cats/bengal/cook.png new file mode 100644 index 0000000..85d3c33 Binary files /dev/null and b/public/assets/cats/bengal/cook.png differ diff --git a/public/assets/cats/bengal/idle.png b/public/assets/cats/bengal/idle.png new file mode 100644 index 0000000..cc6f3db Binary files /dev/null and b/public/assets/cats/bengal/idle.png differ diff --git a/public/assets/cats/bengal/sleep.png b/public/assets/cats/bengal/sleep.png new file mode 100644 index 0000000..ca543b1 Binary files /dev/null and b/public/assets/cats/bengal/sleep.png differ diff --git a/public/assets/cats/bengal/walk1.png b/public/assets/cats/bengal/walk1.png new file mode 100644 index 0000000..b377beb Binary files /dev/null and b/public/assets/cats/bengal/walk1.png differ diff --git a/public/assets/cats/bengal/walk2.png b/public/assets/cats/bengal/walk2.png new file mode 100644 index 0000000..535e2ed Binary files /dev/null and b/public/assets/cats/bengal/walk2.png differ diff --git a/public/assets/cats/bengal/work.png b/public/assets/cats/bengal/work.png new file mode 100644 index 0000000..32d3f7b Binary files /dev/null and b/public/assets/cats/bengal/work.png differ diff --git a/public/assets/cats/korean_shorthair/cook.png b/public/assets/cats/korean_shorthair/cook.png new file mode 100644 index 0000000..297a299 Binary files /dev/null and b/public/assets/cats/korean_shorthair/cook.png differ diff --git a/public/assets/cats/korean_shorthair/idle.png b/public/assets/cats/korean_shorthair/idle.png new file mode 100644 index 0000000..1639a3c Binary files /dev/null and b/public/assets/cats/korean_shorthair/idle.png differ diff --git a/public/assets/cats/korean_shorthair/sleep.png b/public/assets/cats/korean_shorthair/sleep.png new file mode 100644 index 0000000..093c804 Binary files /dev/null and b/public/assets/cats/korean_shorthair/sleep.png differ diff --git a/public/assets/cats/korean_shorthair/walk1.png b/public/assets/cats/korean_shorthair/walk1.png new file mode 100644 index 0000000..ef4e67c Binary files /dev/null and b/public/assets/cats/korean_shorthair/walk1.png differ diff --git a/public/assets/cats/korean_shorthair/walk2.png b/public/assets/cats/korean_shorthair/walk2.png new file mode 100644 index 0000000..d00c8d1 Binary files /dev/null and b/public/assets/cats/korean_shorthair/walk2.png differ diff --git a/public/assets/cats/korean_shorthair/work.png b/public/assets/cats/korean_shorthair/work.png new file mode 100644 index 0000000..e6dc371 Binary files /dev/null and b/public/assets/cats/korean_shorthair/work.png differ diff --git a/public/assets/cats/maine_coon/cook.png b/public/assets/cats/maine_coon/cook.png new file mode 100644 index 0000000..bcfa593 Binary files /dev/null and b/public/assets/cats/maine_coon/cook.png differ diff --git a/public/assets/cats/maine_coon/idle.png b/public/assets/cats/maine_coon/idle.png new file mode 100644 index 0000000..1b79647 Binary files /dev/null and b/public/assets/cats/maine_coon/idle.png differ diff --git a/public/assets/cats/maine_coon/sleep.png b/public/assets/cats/maine_coon/sleep.png new file mode 100644 index 0000000..c34d553 Binary files /dev/null and b/public/assets/cats/maine_coon/sleep.png differ diff --git a/public/assets/cats/maine_coon/walk1.png b/public/assets/cats/maine_coon/walk1.png new file mode 100644 index 0000000..66fdfa8 Binary files /dev/null and b/public/assets/cats/maine_coon/walk1.png differ diff --git a/public/assets/cats/maine_coon/walk2.png b/public/assets/cats/maine_coon/walk2.png new file mode 100644 index 0000000..e129bb4 Binary files /dev/null and b/public/assets/cats/maine_coon/walk2.png differ diff --git a/public/assets/cats/maine_coon/work.png b/public/assets/cats/maine_coon/work.png new file mode 100644 index 0000000..867d70c Binary files /dev/null and b/public/assets/cats/maine_coon/work.png differ diff --git a/public/assets/cats/munchkin/cook.png b/public/assets/cats/munchkin/cook.png new file mode 100644 index 0000000..2366dca Binary files /dev/null and b/public/assets/cats/munchkin/cook.png differ diff --git a/public/assets/cats/munchkin/idle.png b/public/assets/cats/munchkin/idle.png new file mode 100644 index 0000000..4e70f37 Binary files /dev/null and b/public/assets/cats/munchkin/idle.png differ diff --git a/public/assets/cats/munchkin/sleep.png b/public/assets/cats/munchkin/sleep.png new file mode 100644 index 0000000..d2c8b2a Binary files /dev/null and b/public/assets/cats/munchkin/sleep.png differ diff --git a/public/assets/cats/munchkin/walk1.png b/public/assets/cats/munchkin/walk1.png new file mode 100644 index 0000000..7dbf4d8 Binary files /dev/null and b/public/assets/cats/munchkin/walk1.png differ diff --git a/public/assets/cats/munchkin/walk2.png b/public/assets/cats/munchkin/walk2.png new file mode 100644 index 0000000..79a43a5 Binary files /dev/null and b/public/assets/cats/munchkin/walk2.png differ diff --git a/public/assets/cats/munchkin/work.png b/public/assets/cats/munchkin/work.png new file mode 100644 index 0000000..d4e717e Binary files /dev/null and b/public/assets/cats/munchkin/work.png differ diff --git a/public/assets/cats/norwegian_forest/cook.png b/public/assets/cats/norwegian_forest/cook.png new file mode 100644 index 0000000..39bb50f Binary files /dev/null and b/public/assets/cats/norwegian_forest/cook.png differ diff --git a/public/assets/cats/norwegian_forest/idle.png b/public/assets/cats/norwegian_forest/idle.png new file mode 100644 index 0000000..8f7a829 Binary files /dev/null and b/public/assets/cats/norwegian_forest/idle.png differ diff --git a/public/assets/cats/norwegian_forest/sleep.png b/public/assets/cats/norwegian_forest/sleep.png new file mode 100644 index 0000000..80e7106 Binary files /dev/null and b/public/assets/cats/norwegian_forest/sleep.png differ diff --git a/public/assets/cats/norwegian_forest/walk1.png b/public/assets/cats/norwegian_forest/walk1.png new file mode 100644 index 0000000..1ca0c36 Binary files /dev/null and b/public/assets/cats/norwegian_forest/walk1.png differ diff --git a/public/assets/cats/norwegian_forest/walk2.png b/public/assets/cats/norwegian_forest/walk2.png new file mode 100644 index 0000000..4684848 Binary files /dev/null and b/public/assets/cats/norwegian_forest/walk2.png differ diff --git a/public/assets/cats/norwegian_forest/work.png b/public/assets/cats/norwegian_forest/work.png new file mode 100644 index 0000000..e6c058c Binary files /dev/null and b/public/assets/cats/norwegian_forest/work.png differ diff --git a/public/assets/cats/persian/cook.png b/public/assets/cats/persian/cook.png new file mode 100644 index 0000000..87fccef Binary files /dev/null and b/public/assets/cats/persian/cook.png differ diff --git a/public/assets/cats/persian/idle.png b/public/assets/cats/persian/idle.png new file mode 100644 index 0000000..eddd312 Binary files /dev/null and b/public/assets/cats/persian/idle.png differ diff --git a/public/assets/cats/persian/sleep.png b/public/assets/cats/persian/sleep.png new file mode 100644 index 0000000..a32c756 Binary files /dev/null and b/public/assets/cats/persian/sleep.png differ diff --git a/public/assets/cats/persian/walk1.png b/public/assets/cats/persian/walk1.png new file mode 100644 index 0000000..edb2d39 Binary files /dev/null and b/public/assets/cats/persian/walk1.png differ diff --git a/public/assets/cats/persian/walk2.png b/public/assets/cats/persian/walk2.png new file mode 100644 index 0000000..c6d9b3e Binary files /dev/null and b/public/assets/cats/persian/walk2.png differ diff --git a/public/assets/cats/persian/work.png b/public/assets/cats/persian/work.png new file mode 100644 index 0000000..7cca1a6 Binary files /dev/null and b/public/assets/cats/persian/work.png differ diff --git a/public/assets/cats/russian_blue/cook.png b/public/assets/cats/russian_blue/cook.png new file mode 100644 index 0000000..2252c6e Binary files /dev/null and b/public/assets/cats/russian_blue/cook.png differ diff --git a/public/assets/cats/russian_blue/idle.png b/public/assets/cats/russian_blue/idle.png new file mode 100644 index 0000000..0f0cea7 Binary files /dev/null and b/public/assets/cats/russian_blue/idle.png differ diff --git a/public/assets/cats/russian_blue/sleep.png b/public/assets/cats/russian_blue/sleep.png new file mode 100644 index 0000000..094a8a2 Binary files /dev/null and b/public/assets/cats/russian_blue/sleep.png differ diff --git a/public/assets/cats/russian_blue/walk1.png b/public/assets/cats/russian_blue/walk1.png new file mode 100644 index 0000000..cdd493d Binary files /dev/null and b/public/assets/cats/russian_blue/walk1.png differ diff --git a/public/assets/cats/russian_blue/walk2.png b/public/assets/cats/russian_blue/walk2.png new file mode 100644 index 0000000..a3d05c0 Binary files /dev/null and b/public/assets/cats/russian_blue/walk2.png differ diff --git a/public/assets/cats/russian_blue/work.png b/public/assets/cats/russian_blue/work.png new file mode 100644 index 0000000..40e4a24 Binary files /dev/null and b/public/assets/cats/russian_blue/work.png differ diff --git a/public/assets/cats/sphynx/cook.png b/public/assets/cats/sphynx/cook.png new file mode 100644 index 0000000..a821044 Binary files /dev/null and b/public/assets/cats/sphynx/cook.png differ diff --git a/public/assets/cats/sphynx/idle.png b/public/assets/cats/sphynx/idle.png new file mode 100644 index 0000000..74aaf6d Binary files /dev/null and b/public/assets/cats/sphynx/idle.png differ diff --git a/public/assets/cats/sphynx/sleep.png b/public/assets/cats/sphynx/sleep.png new file mode 100644 index 0000000..17dd0dc Binary files /dev/null and b/public/assets/cats/sphynx/sleep.png differ diff --git a/public/assets/cats/sphynx/walk1.png b/public/assets/cats/sphynx/walk1.png new file mode 100644 index 0000000..13f6d15 Binary files /dev/null and b/public/assets/cats/sphynx/walk1.png differ diff --git a/public/assets/cats/sphynx/walk2.png b/public/assets/cats/sphynx/walk2.png new file mode 100644 index 0000000..937f1e3 Binary files /dev/null and b/public/assets/cats/sphynx/walk2.png differ diff --git a/public/assets/cats/sphynx/work.png b/public/assets/cats/sphynx/work.png new file mode 100644 index 0000000..ecaf284 Binary files /dev/null and b/public/assets/cats/sphynx/work.png differ diff --git a/src/components/game/VillageView.tsx b/src/components/game/VillageView.tsx index 2ebf25e..54f7e28 100644 --- a/src/components/game/VillageView.tsx +++ b/src/components/game/VillageView.tsx @@ -2,7 +2,7 @@ import { useEffect, useRef } from "react"; import { engine, catRate } from "@/lib/game/engine"; -import { TOOL_IMG } from "@/lib/game/data"; +import { catSprite, TOOL_IMG, type CatFrame } from "@/lib/game/data"; import type { AptitudeKey } from "@/lib/game/types"; // ---------- 아이소메트릭 그리드 ---------- @@ -93,7 +93,8 @@ export default function VillageView() { const toolImagesRef = useRef>(new Map()); const waterImgRef = useRef(null); const grassImgRef = useRef(null); - const catFramesRef = useRef>(new Map()); + // src 키 기반 이미지 캐시 (품종별 스프라이트 지연 로드) + const imageCacheRef = useRef>(new Map()); const hitRectsRef = useRef< Array<{ id: string; x: number; y: number; w: number; h: number }> >([]); @@ -123,14 +124,20 @@ export default function VillageView() { const grass = new Image(); grass.src = "/assets/grass.jpg"; grass.onload = () => (grassImgRef.current = grass); - // 고양이 스프라이트 4프레임 - for (const frame of ["idle", "walk1", "walk2", "work"]) { - const catImg = new Image(); - catImg.src = `/assets/cats/${frame}.png`; - catImg.onload = () => catFramesRef.current.set(frame, catImg); - } } + // src로 이미지를 지연 로드 (로드 완료 전/실패 시 undefined 취급) + const getImage = (src: string): HTMLImageElement | undefined => { + const cache = imageCacheRef.current; + if (cache.has(src)) return cache.get(src) ?? undefined; + cache.set(src, null); // 로딩 중 표시 + const img = new Image(); + img.src = src; + img.onload = () => cache.set(src, img); + img.onerror = () => cache.set(src, null); + return undefined; + }; + let raf = 0; let last = performance.now(); @@ -439,8 +446,24 @@ export default function VillageView() { shadow(anim.x, anim.y + 2, 11); // 걷기는 프레임 교대 대신 한 프레임 + 총총 바운스 + 미세 기울임 // (두 걷기 프레임의 몸통 각도가 달라 교대 시 도리도리처럼 보이는 문제 회피) - const frameName = working ? "work" : moving ? "walk1" : "idle"; - const sprite = catFramesRef.current.get(frameName); + const atKitchen = + working && + state.buildings.find((b) => b.id === cat.assignedTo)?.type === "kitchen"; + const frameName: CatFrame = working + ? atKitchen + ? "cook" + : "work" + : moving + ? "walk1" + : "idle"; + // 품종 스프라이트 → (cook 없으면 work) → 기본 스프라이트 순 폴백 + let sprite = getImage(catSprite(cat.breed, frameName)); + if (!sprite && frameName === "cook") + sprite = getImage(catSprite(cat.breed, "work")); + if (!sprite) + sprite = getImage( + catSprite("", frameName === "cook" ? "work" : frameName), + ); if (sprite) { const sh = 42; const sw = (sprite.width / sprite.height) * sh; diff --git a/src/lib/game/data.ts b/src/lib/game/data.ts index 13272ce..1833b5f 100644 --- a/src/lib/game/data.ts +++ b/src/lib/game/data.ts @@ -6,10 +6,17 @@ export const BASE_RATE = 0.2; // 품종별 스프라이트 폴더 (public/assets/cats/{폴더}/). 미등록 품종은 기본(오렌지 태비) 사용 export const CAT_SPRITE_DIR: Record = { - // 예: korean_shorthair: "korean_shorthair", ← 품종 시트가 준비되면 등록 + korean_shorthair: "korean_shorthair", + munchkin: "munchkin", + norwegian_forest: "norwegian_forest", + bengal: "bengal", + russian_blue: "russian_blue", + persian: "persian", + sphynx: "sphynx", + maine_coon: "maine_coon", }; -export type CatFrame = "idle" | "walk1" | "walk2" | "work"; +export type CatFrame = "idle" | "walk1" | "walk2" | "work" | "cook" | "sleep"; export function catSprite(breed: string, frame: CatFrame): string { const dir = CAT_SPRITE_DIR[breed];