-
Notifications
You must be signed in to change notification settings - Fork 1
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 #125 from nkc-ug/feature/trophy
トロフィーシステム実装/合計5,10回言葉を食べる
- Loading branch information
Showing
10 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import { UpdateUserData } from '../UpdateUserData'; | ||
import { GetUserData } from '../GetUserData'; | ||
import { TrophyType } from '../../../types/UserDataType'; | ||
import { UserDataType } from '../../../types/UserDataType'; | ||
|
||
export const AddTotalEatCount = (email: string, isLogin: boolean) => { | ||
const addCount = async () => { | ||
const response = (await GetUserData(email)).totalEatCount + 1; | ||
UpdateUserData(email, 'totalEatCount', response); | ||
const response = await GetUserData(email); | ||
const count = response.totalEatCount + 1; | ||
!response.trophy.eatCount5 && count > 4 ? totalEatCount5Unlock(email, response) : null; | ||
!response.trophy.eatCount10 && count > 9 ? totalEatCount10Unlock(email, response) : null; | ||
UpdateUserData(email, 'totalEatCount', count); | ||
}; | ||
isLogin ? addCount() : null; | ||
}; | ||
|
||
const totalEatCount5Unlock = (email: string, response: UserDataType) => { | ||
const trophy: TrophyType = { | ||
eatCount5: true, | ||
eatCount10: response.trophy.eatCount10, | ||
battleWinCount3: response.trophy.battleWinCount3, | ||
battleWinCount5: response.trophy.battleWinCount5, | ||
}; | ||
UpdateUserData(email, 'trophy', trophy); | ||
}; | ||
|
||
const totalEatCount10Unlock = (email: string, response: UserDataType) => { | ||
const trophy: TrophyType = { | ||
eatCount5: response.trophy.eatCount5, | ||
eatCount10: true, | ||
battleWinCount3: response.trophy.battleWinCount3, | ||
battleWinCount5: response.trophy.battleWinCount5, | ||
}; | ||
UpdateUserData(email, 'trophy', trophy); | ||
}; |
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,21 @@ | ||
import { useContext } from 'react'; | ||
import { Box } from '@mui/material'; | ||
import { IsLoginContext } from '../../provider/ContextProviders'; | ||
import { LoginButton } from '../auth/LoginButton'; | ||
|
||
export const RequestLogin = () => { | ||
const [isLogin] = useContext(IsLoginContext); | ||
return isLogin ? null : ( | ||
<div> | ||
<Box sx={{ color: 'rgba(225, 225, 225, 1)' }}> | ||
<h2>ログインがひつようです</h2> | ||
<h4> | ||
トロフィーきのうをつかうにはログインがひつようです。 | ||
<br /> | ||
おてすうですがログインしていただくようにおねがいいたします。 | ||
</h4> | ||
</Box> | ||
<LoginButton /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import { Box, Grid, Typography, Paper } from '@mui/material'; | ||
import { IsLoginContext } from '../../provider/ContextProviders'; | ||
import { EmailContext } from '../../provider/ContextProviders'; | ||
|
||
import { TrophyType } from '../../types/UserDataType'; | ||
import { GetUserData } from '../auth/GetUserData'; | ||
import { UserDataType } from '../../types/UserDataType'; | ||
|
||
export const TrophyList = () => { | ||
const [isLogin] = useContext(IsLoginContext); | ||
const [email] = useContext(EmailContext); | ||
const [userData, setUserData] = useState<UserDataType>(); | ||
|
||
useEffect(() => { | ||
// useEffect自体ではasyncの関数を受け取れないので内部で関数を定義して呼び出す。 | ||
const access_db = async () => { | ||
const response = await GetUserData(email); | ||
setUserData(response); | ||
}; | ||
isLogin ? access_db() : null; | ||
}, [isLogin]); | ||
|
||
return isLogin ? ( | ||
<div> | ||
<Box sx={{ color: 'rgba(225, 225, 225, 1)', marginTop: '30px' }}> | ||
<Box> | ||
<Grid container spacing={2}> | ||
<Grid item xs={6}> | ||
<Paper sx={{ backgroundColor: 'rgba(128, 128, 128, 0.75)', height: '150px' }}> | ||
<Typography sx={{ fontSize: '24px' }}> | ||
{userData?.trophy.eatCount5 ? 'おなかいっぱいメェ~' : '???'} | ||
</Typography> | ||
<Typography fontWeight="bold">かくとくほうほう</Typography> | ||
<Typography>ヤギにことばを5かいたべさせる</Typography> | ||
</Paper> | ||
</Grid> | ||
<Grid item xs={6}> | ||
<Paper sx={{ backgroundColor: 'rgba(128, 128, 128, 0.75)', height: '150px' }}> | ||
<Typography sx={{ fontSize: '24px' }}> | ||
{userData?.trophy.eatCount5 ? 'もうたべれないメェー!!!' : '???'} | ||
</Typography> | ||
<Typography fontWeight="bold">かくとくほうほう</Typography> | ||
<Typography>ヤギにことばを10かいたべさせる</Typography> | ||
</Paper> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
</Box> | ||
</div> | ||
) : null; | ||
}; |
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,46 @@ | ||
import { useContext } from 'react'; | ||
import { Typography, Container } from '@mui/material'; | ||
import backgroundgImage from '../assets/night.png'; | ||
import { GetUserData } from '../components/auth/GetUserData'; | ||
import { IsLoginContext } from '../provider/ContextProviders'; | ||
|
||
import { RequestLogin } from '../components/trophy/RequestLogin'; | ||
import { TrophyList } from '../components/trophy/TrophyList'; | ||
|
||
import { CostumeNavBarCon } from '../components/costume/CostumeNavBarcon'; | ||
|
||
export const TrophyPage = () => { | ||
return ( | ||
<div> | ||
<Container | ||
maxWidth="sm" | ||
sx={{ | ||
padding: '0px', | ||
minHeight: '100vh', | ||
height: '100%', | ||
width: '100%', | ||
textAlign: 'center', | ||
backgroundImage: `url(${backgroundgImage})`, | ||
backgroundSize: 'cover', | ||
backgroundRepeat: 'no-repeat', | ||
backgroundPosition: 'center', | ||
}} | ||
> | ||
<Typography | ||
variant="h2" | ||
sx={{ | ||
margin: '0px', | ||
padding: '20px', | ||
backgroundColor: 'rgba(220, 220, 220, 0.6)', | ||
fontSize: '48px', | ||
}} | ||
> | ||
トロフィールーム | ||
</Typography> | ||
<RequestLogin /> | ||
<TrophyList /> | ||
</Container> | ||
<CostumeNavBarCon /> | ||
</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