Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
fix: result_imageの判定の変更、zstandのuseScoreStoreの変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Sea10wood committed Aug 18, 2024
1 parent e4c0fdf commit 6d35c4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/pages/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ type ResultProps = {
};

const Result = ({ score }: ResultProps) => {
const images = [
"/drink/bottle0.webp",
"/drink/bottle1.webp",
"/drink/bottle2.webp",
"/drink/bottle3.webp",
];

const image = images[score] || images[0];
const image =
score >= 0 && score <= 3
? `/drink/bottle${score}.webp`
: "/drink/bottle0.webp";

return (
<div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/shooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Shooter = () => {
const uuid = useUUIDStore((state) => state.uuid);
const navigate = useNavigate();
const score = useScoreStore((state) => state.score);
const setScore = useScoreStore((state) => state.setScore);
const addOneScore = useScoreStore((state) => state.addOneScore);

const initialImages = [
"/2D_material/cork.webp",
Expand All @@ -42,10 +42,10 @@ const Shooter = () => {
useEffect(() => {
onMessage((data) => {
if (data.message_type === MessageType.Hit && data.id === uuid) {
setScore((prevScore: number) => prevScore + 1);
addOneScore();
}
});
}, [onMessage, uuid, setScore]);
}, [onMessage, uuid, addOneScore]);

useEffect(() => {
if (images.length === 0) {
Expand Down
11 changes: 8 additions & 3 deletions src/store/useScoreStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import create from "zustand";

type Store = {
score: number;
setScore: (updater: (prevScore: number) => number) => void;
};

export const useScoreStore = create<Store>((set) => ({
type Action = {
setScore: (score: number) => void;
addOneScore: () => void;
};

export const useScoreStore = create<Store & Action>((set) => ({
score: 0,
setScore: (updater) => set((state) => ({ score: updater(state.score) })),
setScore: (score) => set(() => ({ score: score })),
addOneScore: () => set((state) => ({ score: state.score + 1 })),
}));

0 comments on commit 6d35c4c

Please sign in to comment.