Skip to content

Commit

Permalink
feat: add music on start and background positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson-Valentim committed Jun 17, 2022
1 parent 50abc7a commit a54bfa8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
Binary file added public/music.mp3
Binary file not shown.
8 changes: 7 additions & 1 deletion src/pages/GameOver/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const GameOver: React.FC = () => {
const { state } = useLocation() as { state: { winner: boolean } };

return (
<Styled.Container>
<Styled.Container
width="100vw"
backgroundImage="/room.png"
backgroundRepeat="no-repeat"
backgroundSize="cover"
backgroundPosition="center"
>
<Styled.Title>
{state?.winner ? "Você venceu" : "Você Perdeu"}
</Styled.Title>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/GameOver/styled.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Container as CContainer } from "@chakra-ui/react";
import styled from "styled-components";

const Container = styled.div`
background-color: black;
const Container = styled(CContainer)`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
max-width: 100vw !important;
`;

const Title = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Room/components/DoneBoard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMutation } from "@apollo/client";
import { gql } from "apollo-boost";
import React from "react";
import React, { useEffect } from "react";

import Tiles from "../Tiles";

Expand Down
4 changes: 2 additions & 2 deletions src/pages/Room/components/Tiles/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const Tile = styled.div<{
size: number;
disabled?: boolean;
}>`
height: ${({ size }) => size * 30}px;
width: ${({ size }) => size * 30}px;
height: ${({ size }) => size * window.innerHeight * 0.03}px;
width: ${({ size }) => size * window.innerHeight * 0.03}px;
padding: 2px;
margin: 1px;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Room/components/UserInfo/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Container = styled.div`
img {
width: fit-content;
height: 250px;
height: ${window.innerHeight * 0.25}px;
}
`;

Expand Down
26 changes: 19 additions & 7 deletions src/pages/Room/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Room: React.FC = () => {
const navigate = useNavigate();

const skinAudioRef = React.createRef<any>();
const gameMusicRef = React.createRef<any>();

const { socket } = useContext(SocketContext);
const { setLoading: setFullscreenLoading } = useContext(
Expand Down Expand Up @@ -85,6 +86,16 @@ const Room: React.FC = () => {
},
});

useEffect(() => {
if (gameMusicRef.current) {
gameMusicRef.current.play();
}

return () => {
gameMusicRef.current?.stop();
};
}, [gameMusicRef]);

useEffect(() => {
socket.on(
"client:room:update",
Expand Down Expand Up @@ -178,7 +189,13 @@ const Room: React.FC = () => {

return params.roomId ? (
getRoomData && user ? (
<Styled.RoomBox>
<Styled.RoomBox
backgroundImage="/room.png"
backgroundRepeat="no-repeat"
backgroundSize="cover"
backgroundPosition="center"
>
<audio src="/music.mp3" ref={gameMusicRef} loop />
<audio
src={
scored
Expand All @@ -189,12 +206,7 @@ const Room: React.FC = () => {
}
ref={skinAudioRef}
/>
<Styled.Room
height="100%"
backgroundImage="/room.png"
backgroundRepeat="no-repeat"
backgroundSize="cover"
>
<Styled.Room height="100%">
<Styled.FirstColumn>
<UserInfo userId={user.id} />
<UserBoard board={getRoomData.getRoom.board} />
Expand Down

0 comments on commit a54bfa8

Please sign in to comment.