This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add: shooter_scoreを元にresultへの遷移 #46
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ebd3a1
Add: shooter_scoreを元にresultへの遷移
Sea10wood 467603d
Add: shooter_scoreを元にresultへの遷移
Sea10wood 8b586b5
Merge branch 'result_view' of github.com:claustra01/virtual-natsumats…
Sea10wood e0cfad4
fix: pnpm checkでの変更
Sea10wood 7214e84
Add: スコアを表示して、resultに遷移するまでの機能
Sea10wood e7ebf3e
fix: Localでの変数名の削除
Sea10wood e4c0fdf
fix: zstandの処理の追加
Sea10wood 6d35c4c
fix: result_imageの判定の変更、zstandのuseScoreStoreの変更
Sea10wood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,29 @@ import GetImage from "../../components/GetImage"; | |
import { DefaultButton } from "../../components/ui/Button"; | ||
import styles from "./index.module.css"; | ||
|
||
function Result() { | ||
type ResultProps = { | ||
score: number; | ||
}; | ||
|
||
const Result = ({ score }: ResultProps) => { | ||
const images = [ | ||
"/drink/bottle0.webp", | ||
"/drink/bottle1.webp", | ||
"/drink/bottle2.webp", | ||
"/drink/bottle3.webp", | ||
]; | ||
|
||
const image = images[score] || images[0]; | ||
K-Kizuku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<div> | ||
<div className={styles["result-text"]}> | ||
<p>結果発表!</p> | ||
</div> | ||
<div className={styles["get-image-container"]}> | ||
<GetImage | ||
images={images} | ||
alt="ランダムに表示されるボトル画像" | ||
images={[image]} | ||
alt={`スコア ${score} に対応するボトル画像`} | ||
width={160} | ||
height={160} | ||
/> | ||
|
@@ -32,11 +38,11 @@ function Result() { | |
/> | ||
</div> | ||
<div className={styles["get-text"]}> | ||
<p>Bottle Get!</p> | ||
<p>{score}本倒した!</p> | ||
</div> | ||
<div className={styles["share-btn"]}> | ||
<a | ||
href="https://twitter.com/intent/tweet?text=Webの射的で遊んだよ.%20%23virtualnatsumatsuri%20%23炎上開発%20%23鹿児島ハッカソン" | ||
href={`https://twitter.com/intent/tweet?text=Webの射的で遊んだよ。${score}本倒した!%20%23virtualnatsumatsuri`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ハックツの夏祭りように改修してるので、 |
||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
|
@@ -50,6 +56,6 @@ function Result() { | |
</div> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||
import { type KeyboardEventHandler, useEffect, useState } from "react"; | ||||||
import { useNavigate } from "react-router-dom"; | ||||||
import { DefaultButton } from "../../components/ui/Button"; | ||||||
import { Modal } from "../../components/ui/Modal"; | ||||||
import { ShooterButton } from "../../components/ui/ShooterButton"; | ||||||
|
@@ -10,21 +11,25 @@ import { message_type } from "../../type/schema"; | |||||
import { MessageType } from "../../type/shooting"; | ||||||
import style from "./index.module.css"; | ||||||
|
||||||
const Shooter = () => { | ||||||
type ShooterProps = { | ||||||
setScore: (score: number) => void; | ||||||
}; | ||||||
|
||||||
const Shooter = ({ setScore }: ShooterProps) => { | ||||||
const [isOpen, setIsOpen] = useState(true); | ||||||
const [score, setScore] = useState<number>(0); | ||||||
const [score, setScoreState] = useState<number>(0); | ||||||
const { orientationDiff } = useOrientation(); | ||||||
const { sendData } = useSocketSender(); | ||||||
const { onMessage } = useSocketReceiver(); | ||||||
const uuid = useUUIDStore((state) => state.uuid); | ||||||
const navigate = useNavigate(); | ||||||
|
||||||
const initialImages = [ | ||||||
"/2D_material/cork.webp", | ||||||
"/2D_material/cork.webp", | ||||||
"/2D_material/cork.webp", | ||||||
]; | ||||||
|
||||||
const [images, setImages] = useState(initialImages); | ||||||
const uuid = useUUIDStore((state) => state.uuid); | ||||||
|
||||||
useEffect(() => { | ||||||
let intervalId: number | null = null; | ||||||
|
@@ -43,20 +48,24 @@ const Shooter = () => { | |||||
useEffect(() => { | ||||||
onMessage((data) => { | ||||||
if (data.message_type === MessageType.Hit && data.id === uuid) { | ||||||
setScore((prevScore) => prevScore + 1); | ||||||
console.log(score); | ||||||
const newScore = score + 1; | ||||||
setScoreState(newScore); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
こんな感じで値の更新をしないと正しくstateが更新されない場合があるので、変更お願いします |
||||||
} | ||||||
}); | ||||||
}, [onMessage, uuid, score]); | ||||||
|
||||||
useEffect(() => { | ||||||
if (images.length === 0) { | ||||||
setScore(score); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この処理の意味を教えてください There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これは、images(コルクの残量)が0になったときにresultに遷移する処理です! |
||||||
navigate("/result", { state: { score } }); | ||||||
} | ||||||
}, [images, navigate, score, setScore]); | ||||||
|
||||||
const handleClick = () => { | ||||||
const audio = new Audio("/sound/cork_sound.mp3"); | ||||||
audio | ||||||
.play() | ||||||
.then(() => {}) | ||||||
.catch((error) => { | ||||||
console.error("オーディオの音が出なかった", error); | ||||||
}); | ||||||
audio.play().catch((error) => { | ||||||
console.error("オーディオの音が出なかった", error); | ||||||
}); | ||||||
sendData(message_type.action, uuid, orientationDiff); | ||||||
setImages((prevImages) => prevImages.slice(1)); | ||||||
}; | ||||||
|
@@ -76,10 +85,14 @@ const Shooter = () => { | |||||
<ShooterButton onClick={handleClick} onKeyUp={handleKeyUp} /> | ||||||
</div> | ||||||
<div className={style.cork}> | ||||||
{images.map((src, i) => ( | ||||||
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation> | ||||||
<img key={i} src={src} alt="コルクの残量を表示しています" /> | ||||||
))} | ||||||
{images.length > 0 ? ( | ||||||
images.map((src, i) => ( | ||||||
// biome-ignore lint/suspicious/noArrayIndexKey: <explanation> | ||||||
<img key={i} src={src} alt="コルクの残量を表示しています" /> | ||||||
)) | ||||||
) : ( | ||||||
<p>コルクがなくなりました!</p> | ||||||
)} | ||||||
</div> | ||||||
</div> | ||||||
); | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zustundの方で値を管理するようにしてもらえると
(これだとscoreの値が変わるたびに全体が再レンダリングされてしまうので)