-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Console-buche/fix/responsive-ui
fix: Responsive UI
- Loading branch information
Showing
10 changed files
with
130 additions
and
52 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 +1,62 @@ | ||
import { useSelector } from '@xstate/react'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { useGameMachineProvider } from '../../../hooks/use'; | ||
import { useRef } from 'react'; | ||
import './backgroundMusic.css'; | ||
|
||
export const BackgroundMusic = () => { | ||
const audioRef = useRef<HTMLAudioElement>(null); | ||
const gameService = useGameMachineProvider(); | ||
const state = useSelector(gameService, (state) => state.value); | ||
|
||
if (audioRef.current && audioRef.current.volume !== 0.1) | ||
audioRef.current.volume = 0.1; | ||
const [isPlaying, setIsPlaying] = useState(false); | ||
|
||
if (state === 'playing') audioRef.current?.play(); | ||
if (state === 'paused') audioRef.current?.pause(); | ||
useEffect(() => { | ||
if (audioRef.current && audioRef.current.volume !== 0.1) | ||
audioRef.current.volume = 0.1; | ||
}, []); | ||
|
||
const hiddenClass = | ||
state === 'playing' || state === 'notStarted' || state === 'howToPlay' | ||
? 'audio__hidden' | ||
: ''; | ||
const playMusic = (play: boolean) => { | ||
if (!audioRef.current) return; | ||
|
||
if (play) { | ||
audioRef.current.play(); | ||
setIsPlaying(true); | ||
return; | ||
} | ||
|
||
audioRef.current.pause(); | ||
setIsPlaying(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (state === 'playing') { | ||
playMusic(true); | ||
} else { | ||
playMusic(false); | ||
} | ||
}, [state]); | ||
|
||
const handleOnClick = () => { | ||
if (!audioRef.current) return; | ||
|
||
isPlaying ? audioRef.current.pause() : audioRef.current.play(); | ||
setIsPlaying(!isPlaying); | ||
}; | ||
|
||
return ( | ||
<div className="audio__container"> | ||
<audio | ||
ref={audioRef} | ||
className={`"audio__player" ${hiddenClass}`} | ||
controls | ||
loop | ||
> | ||
<> | ||
<audio ref={audioRef} className="audio__player" controls loop> | ||
<source | ||
src="./assets/sounds/Snifit-or-Whiffit-PaperMario-Color-Splash.mp3" | ||
type="audio/mpeg" | ||
/> | ||
</audio> | ||
</div> | ||
<img | ||
src="./assets/icons/speaker.png" | ||
alt="audio icon" | ||
className={`audio__icon ${isPlaying ? 'audio__icon--playing' : ''}`} | ||
onClick={handleOnClick} | ||
/> | ||
</> | ||
); | ||
}; |
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,18 +1,28 @@ | ||
.audio__container { | ||
position: absolute; | ||
top: 138px; | ||
left: 428px; | ||
transform: rotate(4deg); | ||
display: flex; | ||
justify-content: center; | ||
gap: 20px; | ||
z-index: 2; | ||
.audio__player { | ||
display: none | ||
} | ||
|
||
.audio__player { | ||
position: relative; | ||
|
||
.audio__icon { | ||
position: absolute; | ||
bottom: 0; | ||
left: 10px; | ||
width: 120px; | ||
filter: grayscale(1); | ||
transition: 0.15s filter; | ||
} | ||
|
||
.audio__hidden { | ||
display: none; | ||
|
||
.audio__icon--playing { | ||
filter: grayscale(0); | ||
} | ||
|
||
@media (max-width: 1024px) { | ||
|
||
.audio__icon { | ||
top:0; | ||
left:10px; | ||
transform:rotateX(180deg); | ||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useSelector } from '@xstate/react'; | ||
import { HypeGauge } from './HypeGauge/HypeGauge'; | ||
import './hud.css'; | ||
import { useGameMachineProvider } from '../../hooks/use'; | ||
import { HotSpots } from './Hotspots/HotSpots'; | ||
|
||
export const HudHeader = () => { | ||
const gameService = useGameMachineProvider(); | ||
const hype = useSelector(gameService, (state) => state.context.meters.hype); | ||
|
||
return ( | ||
<div className="header__container"> | ||
<HypeGauge hype={hype} /> | ||
<HotSpots /> | ||
</div> | ||
); | ||
}; |
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
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