Skip to content

Commit

Permalink
feat(FE): add custom image to memory options
Browse files Browse the repository at this point in the history
  • Loading branch information
tetogomez committed Mar 25, 2021
1 parent 260c3e4 commit f2b475d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions webapp/src/games/Memory/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Card = ({ image, isCardCompared, selectCard, guessedRight }) => {
>
<div className={classes.cover}></div>
<div className={classes.content}>
<span>{image}</span>
<img src={image} alt="memory-img" />
</div>
</ReactCardFlip>
</div>
Expand All @@ -27,7 +27,7 @@ const Card = ({ image, isCardCompared, selectCard, guessedRight }) => {

Card.propTypes = {
image: PropTypes.any,
isCardCompared: PropTypes.array,
isCardCompared: PropTypes.bool,
selectCard: PropTypes.func,
guessedRight: PropTypes.bool
}
Expand Down
11 changes: 9 additions & 2 deletions webapp/src/games/Memory/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import { makeStyles } from '@material-ui/styles'

import { buildDeck } from '../../utils'
Expand All @@ -9,7 +10,7 @@ import styles from './styles'

const useStyles = makeStyles(styles)

const Memory = () => {
const Memory = ({ customOptions = [] }) => {
const classes = useStyles()
const [deck, setDeck] = useState()
const [pairSelected, setPairSelected] = useState()
Expand Down Expand Up @@ -61,7 +62,7 @@ const Memory = () => {
}

const resetGame = () => {
setDeck(buildDeck())
setDeck(buildDeck(customOptions))
setPairSelected([])
setPairCompared(false)
setAttempts(0)
Expand All @@ -71,6 +72,8 @@ const Memory = () => {
resetGame()
}, [])

// console.log({ deck })

return (
<div className={classes.app}>
<Header attempts={attempts} resetGame={resetGame} />
Expand All @@ -79,4 +82,8 @@ const Memory = () => {
)
}

Memory.propTypes = {
customOptions: PropTypes.array
}

export default Memory
8 changes: 6 additions & 2 deletions webapp/src/games/Memory/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ export default () => ({
cover: {
width: 125,
height: 125,
backgroundColor: '#ffb300'
backgroundColor: '#a5a1a4'
},
content: {
width: 125,
height: 125,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgb(3, 220, 244)'
backgroundColor: 'rgb(3, 220, 244)',
'& img': {
width: 125,
height: 125
}
},
header: {
height: 50,
Expand Down
Binary file modified webapp/src/images/templates/base/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webapp/src/images/templates/bgs/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webapp/src/images/templates/bgs/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webapp/src/images/templates/bgs/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webapp/src/images/templates/bgs/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion webapp/src/images/templates/templatelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import bgs3 from './bgs/3.png'
import bgs4 from './bgs/4.png'
import bgs5 from './bgs/5.png'
import bgs6 from './bgs/6.png'
import bgs7 from './bgs/7.png'
import bgs8 from './bgs/8.png'
import bgs9 from './bgs/9.png'
import bgs10 from './bgs/10.png'

import deco1 from './deco/1.png'
import deco2 from './deco/2.png'
Expand All @@ -25,7 +29,7 @@ import mouth4 from './mouth/4.png'

const baselist = [base1, base2, base3, base4]
const eyeslist = [eyes1, eyes2, eyes3, eyes4]
const bglist = [bgs1, bgs2, bgs3, bgs4, bgs5, bgs6]
const bglist = [bgs1, bgs2, bgs3, bgs4, bgs5, bgs6, bgs7, bgs8, bgs9, bgs10]
const decolist = [deco1, deco2]
const mouthlist = [mouth1, mouth2, mouth3, mouth4]

Expand Down
5 changes: 3 additions & 2 deletions webapp/src/routes/CreateTemplate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CREATE_TEMPLATE_MUTATION } from '../../gql'
import { useSharedState } from '../../context/state.context'
import AvatarMaker from '../../components/AvatarMaker'
import Memory from '../../games/Memory'
import { baselist } from '../../images/templates/templatelist'

import styles from './styles'

Expand Down Expand Up @@ -86,7 +87,7 @@ const CreateTemplate = () => {

const handleSubmit = async () => {
const dataUrl = canvas.toDataURL({ format: 'png' })

try {
const { data } = await createTemplate({
variables: {
Expand Down Expand Up @@ -226,7 +227,7 @@ const CreateTemplate = () => {
</Button>
</Box>
</form>
<Memory />
<Memory customOptions={baselist} />
</>
)
}
Expand Down
23 changes: 10 additions & 13 deletions webapp/src/utils/buildDeck.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import shuffle from 'lodash.shuffle'

import { bglist } from '../images/templates/templatelist'

const MAX_CARDS_NUMBER = 20

export const buildDeck = () => {
const data = [
'Banana',
'Orange',
'Apple',
'Mango',
'Papaya',
'Melon',
'Pepino',
'kiwi',
'platano',
'banano'
]
export const buildDeck = options => {
let data = []
const cards = []

if (options.length && options.length < 10) {
const splitedData = bglist.slice(0, 10 - options.length)

data = [...options, ...splitedData]
}

while (cards.length < MAX_CARDS_NUMBER) {
const index = Math.floor(Math.random() * data.length)
const card = {
Expand Down

0 comments on commit f2b475d

Please sign in to comment.