diff --git a/hapi/yarn.lock b/hapi/yarn.lock index 617bbd30..2b3cb09d 100644 --- a/hapi/yarn.lock +++ b/hapi/yarn.lock @@ -1499,39 +1499,6 @@ __metadata: languageName: node linkType: hard -"eosioboilerplate@workspace:.": - version: 0.0.0-use.local - resolution: "eosioboilerplate@workspace:." - dependencies: - "@hapi/boom": ^9.0.0 - "@hapi/hapi": ^19.1.1 - axios: ^0.19.2 - env-cmd: ^10.1.0 - eosjs: ^20.0.3 - eosjs-api: ^7.0.4 - eslint: ^7.6.0 - eslint-config-prettier: ^8.1.0 - eslint-config-standard: ^16.0.2 - eslint-plugin-import: ^2.22.1 - eslint-plugin-node: ^11.1.0 - eslint-plugin-prettier: ^3.3.1 - eslint-plugin-promise: ^4.3.1 - fsevents: 2.1.3 - graphql-request: ^1.8.2 - http-status-codes: ^1.4.0 - husky: 4.3.8 - joi: ^17.4.0 - lint-staged: ^10.5.4 - node-fetch: ^2.6.1 - nodemon: ^2.0.4 - prettier: ^2.2.1 - standard: ^16.0.3 - dependenciesMeta: - fsevents: - optional: true - languageName: unknown - linkType: soft - "eosjs-api@npm:^7.0.4": version: 7.0.4 resolution: "eosjs-api@npm:7.0.4" @@ -2315,6 +2282,39 @@ fsevents@~2.3.1: languageName: node linkType: hard +"ggoods@workspace:.": + version: 0.0.0-use.local + resolution: "ggoods@workspace:." + dependencies: + "@hapi/boom": ^9.0.0 + "@hapi/hapi": ^19.1.1 + axios: ^0.19.2 + env-cmd: ^10.1.0 + eosjs: ^20.0.3 + eosjs-api: ^7.0.4 + eslint: ^7.6.0 + eslint-config-prettier: ^8.1.0 + eslint-config-standard: ^16.0.2 + eslint-plugin-import: ^2.22.1 + eslint-plugin-node: ^11.1.0 + eslint-plugin-prettier: ^3.3.1 + eslint-plugin-promise: ^4.3.1 + fsevents: 2.1.3 + graphql-request: ^1.8.2 + http-status-codes: ^1.4.0 + husky: 4.3.8 + joi: ^17.4.0 + lint-staged: ^10.5.4 + node-fetch: ^2.6.1 + nodemon: ^2.0.4 + prettier: ^2.2.1 + standard: ^16.0.3 + dependenciesMeta: + fsevents: + optional: true + languageName: unknown + linkType: soft + "glob-parent@npm:^5.0.0, glob-parent@npm:~5.1.0": version: 5.1.2 resolution: "glob-parent@npm:5.1.2" diff --git a/webapp/package.json b/webapp/package.json index a34990db..e8ec553b 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -45,10 +45,12 @@ "history": "^5.0.0", "i18next": "^19.9.1", "i18next-browser-languagedetector": "^6.0.1", + "lodash.shuffle": "^4.2.0", "material-ui-dropzone": "^3.5.0", "polished": "^4.1.1", "prop-types": "^15.7.2", "react": "~17.0.1", + "react-card-flip": "^1.1.0", "react-color": "^2.19.3", "react-dom": "~17.0.1", "react-feather": "^2.0.9", diff --git a/webapp/src/components/AvatarMaker/FabricCanvas.js b/webapp/src/components/AvatarMaker/FabricCanvas.js index e213353f..a48707ba 100644 --- a/webapp/src/components/AvatarMaker/FabricCanvas.js +++ b/webapp/src/components/AvatarMaker/FabricCanvas.js @@ -32,17 +32,16 @@ const FabricCanvas = ({ activeProperty, onGetDataUrl }) => { if (next.the_type === 'bg') { canvas.setBackgroundImage(next) canvas.renderAll() + onGetDataUrl(canvas) + return } canvas.add(next) canvas.moveTo(next, next.zIndex) - } - } - const getDataUrlCanvas = () => { - // TODO: move all this component logic and return dataUrl - // const dataUrl = canvas.toDataURL({ format: 'png' }) + onGetDataUrl(canvas) + } } const initCanvas = isMobile => @@ -71,9 +70,7 @@ const FabricCanvas = ({ activeProperty, onGetDataUrl }) => { placeholder="Name your animal" className={classes.textField} /> - + diff --git a/webapp/src/games/Memory/Board.js b/webapp/src/games/Memory/Board.js new file mode 100644 index 00000000..6920fa3e --- /dev/null +++ b/webapp/src/games/Memory/Board.js @@ -0,0 +1,39 @@ +import React from 'react' +import { makeStyles } from '@material-ui/styles' +import PropTypes from 'prop-types' + +import Card from './Card' + +import styles from './styles' + +const useStyles = makeStyles(styles) + +const Board = ({ deck, pairSelected, selectCard }) => { + const classes = useStyles() + + return ( +
+ {(deck || []).map((card, index) => { + const isCardCompared = pairSelected.indexOf(card) > -1 + + return ( + selectCard(card)} + guessedRight={card.guessedRight} + /> + ) + })} +
+ ) +} + +Board.propTypes = { + deck: PropTypes.array, + pairSelected: PropTypes.array, + selectCard: PropTypes.func +} + +export default Board diff --git a/webapp/src/games/Memory/Card.js b/webapp/src/games/Memory/Card.js new file mode 100644 index 00000000..8368e836 --- /dev/null +++ b/webapp/src/games/Memory/Card.js @@ -0,0 +1,35 @@ +import React from 'react' +import { makeStyles } from '@material-ui/styles' +import PropTypes from 'prop-types' +import ReactCardFlip from 'react-card-flip' + +import styles from './styles' + +const useStyles = makeStyles(styles) + +const Card = ({ image, isCardCompared, selectCard, guessedRight }) => { + const classes = useStyles() + + return ( +
+ +
+
+ {image} +
+
+
+ ) +} + +Card.propTypes = { + image: PropTypes.any, + isCardCompared: PropTypes.array, + selectCard: PropTypes.func, + guessedRight: PropTypes.bool +} + +export default Card diff --git a/webapp/src/games/Memory/Header.js b/webapp/src/games/Memory/Header.js new file mode 100644 index 00000000..33d404c4 --- /dev/null +++ b/webapp/src/games/Memory/Header.js @@ -0,0 +1,30 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { makeStyles } from '@material-ui/styles' + +import styles from './styles' + +const useStyles = makeStyles(styles) + +const Header = ({ attempts, resetGame }) => { + const classes = useStyles() + + return ( +
+
React-Memory
+
+ +
+
Attempts: {attempts}
+
+ ) +} + +Header.propTypes = { + attempts: PropTypes.number, + resetGame: PropTypes.func +} + +export default Header diff --git a/webapp/src/games/Memory/index.js b/webapp/src/games/Memory/index.js new file mode 100644 index 00000000..b0383371 --- /dev/null +++ b/webapp/src/games/Memory/index.js @@ -0,0 +1,82 @@ +import React, { useState, useEffect } from 'react' +import { makeStyles } from '@material-ui/styles' + +import { buildDeck } from '../../utils' + +import Header from './Header' +import Board from './Board' +import styles from './styles' + +const useStyles = makeStyles(styles) + +const Memory = () => { + const classes = useStyles() + const [deck, setDeck] = useState() + const [pairSelected, setPairSelected] = useState() + const [pairCompared, setPairCompared] = useState() + const [attempts, setAttempts] = useState() + + const selectCard = card => { + if (pairCompared || pairSelected.indexOf(card) > -1 || card.guessedRight) { + return + } + + const newPairSelected = [...pairSelected, card] + + setPairSelected(newPairSelected) + + if (newPairSelected.length === 2) { + comparePair(newPairSelected) + } + } + + const comparePair = pair => { + setPairCompared(true) + + setTimeout(() => { + const [firstCard, secondCard] = pair + let newDeck = deck + + if (firstCard.image === secondCard.image) { + newDeck = newDeck.map(card => { + if (card.image !== firstCard.image) return card + + return { ...card, guessedRight: true } + }) + } + + verifyGame(deck) + + setDeck(newDeck) + setPairSelected([]) + setPairCompared(false) + setAttempts(attempts + 1) + }, 1000) + } + + const verifyGame = deck => { + if (deck.filter(card => !card.guessedRight).length === 0) { + console.log(`Win with ${attempts} attempts!`) + } + } + + const resetGame = () => { + setDeck(buildDeck()) + setPairSelected([]) + setPairCompared(false) + setAttempts(0) + } + + useEffect(() => { + resetGame() + }, []) + + return ( +
+
+ +
+ ) +} + +export default Memory diff --git a/webapp/src/games/Memory/styles.js b/webapp/src/games/Memory/styles.js new file mode 100644 index 00000000..b8d3cd97 --- /dev/null +++ b/webapp/src/games/Memory/styles.js @@ -0,0 +1,44 @@ +export default () => ({ + card: { + width: 125, + height: 125 + }, + cover: { + width: 125, + height: 125, + backgroundColor: '#ffb300' + }, + content: { + width: 125, + height: 125, + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + backgroundColor: 'rgb(3, 220, 244)' + }, + header: { + height: 50, + border: '1px solid black', + marginBottom: 10, + display: 'flex', + justifyContent: 'space-between', + alignContent: 'center' + }, + title: { + fontSize: 25, + padding: 10, + color: '#00' + }, + resetBtn: { + left: 12, + top: 58 + }, + board: { + display: 'flex', + flexWrap: 'wrap', + width: 700, + height: 600, + margin: '0 auto', + justifyContent: 'space-around' + } +}) diff --git a/webapp/src/images/templates/base/1.png b/webapp/src/images/templates/base/1.png index 328bd227..12cdce6a 100644 Binary files a/webapp/src/images/templates/base/1.png and b/webapp/src/images/templates/base/1.png differ diff --git a/webapp/src/images/templates/base/2.png b/webapp/src/images/templates/base/2.png index 6a58b3e9..ca75086f 100644 Binary files a/webapp/src/images/templates/base/2.png and b/webapp/src/images/templates/base/2.png differ diff --git a/webapp/src/images/templates/base/3.png b/webapp/src/images/templates/base/3.png index 183458e9..8a0ecbcd 100644 Binary files a/webapp/src/images/templates/base/3.png and b/webapp/src/images/templates/base/3.png differ diff --git a/webapp/src/images/templates/base/4.png b/webapp/src/images/templates/base/4.png index 487966fc..60633df9 100644 Binary files a/webapp/src/images/templates/base/4.png and b/webapp/src/images/templates/base/4.png differ diff --git a/webapp/src/routes/CreateTemplate/index.js b/webapp/src/routes/CreateTemplate/index.js index b147dc30..49519ab9 100644 --- a/webapp/src/routes/CreateTemplate/index.js +++ b/webapp/src/routes/CreateTemplate/index.js @@ -16,6 +16,7 @@ import { SketchPicker } from 'react-color' import { CREATE_TEMPLATE_MUTATION } from '../../gql' import { useSharedState } from '../../context/state.context' import AvatarMaker from '../../components/AvatarMaker' +import Memory from '../../games/Memory' import styles from './styles' @@ -27,6 +28,7 @@ const CreateTemplate = () => { const [createTemplate, { loading }] = useMutation(CREATE_TEMPLATE_MUTATION) const [, { showMessage }] = useSharedState() const [tab, setTab] = useState(0) + const [canvas, setCanvas] = useState() const [payload, setPayload] = useState({ category: '', name: '', @@ -83,143 +85,147 @@ const CreateTemplate = () => { } const handleSubmit = async () => { - try { - const { data } = await createTemplate({ - variables: { - ...payload - } - }) - setPayload({ - category: '', - name: '', - metadata: { - type: '2dgameAsset', - name: '', - description: '', - imageSmall: '', - imageLarge: '', - details: {}, - backgroundColor: '#FFEBC3' - } - }) - showMessage({ content: `txid: ${data.template.trxid}` }) - } catch (error) { - showMessage({ type: 'error', content: error.message }) - } + console.log({ createTemplate, canvas: canvas.toDataURL({ format: 'png' }) }) + // try { + // const { data } = await createTemplate({ + // variables: { + // ...payload + // } + // }) + // setPayload({ + // category: '', + // name: '', + // metadata: { + // type: '2dgameAsset', + // name: '', + // description: '', + // imageSmall: '', + // imageLarge: '', + // details: {}, + // backgroundColor: '#FFEBC3' + // } + // }) + // showMessage({ content: `txid: ${data.template.trxid}` }) + // } catch (error) { + // showMessage({ type: 'error', content: error.message }) + // } } return ( -
- - - - - - - - - - - { - handlePayloadChange('name')(event) - handlePayloadChange('metadata.name')(event) - }} - /> - - - - - - - - - setTab(value)} - aria-label="simple tabs example" - > - - - - - {tab === 0 && ( - - {}} /> - - )} - {tab === 1 && ( - - - handlePayloadChange('metadata.backgroundColor')({ - target: { value: color.hex } - }) - } - /> - - + + + + + + + + + + + + { + handlePayloadChange('name')(event) + handlePayloadChange('metadata.name')(event) + }} + /> + + + + + + + + + setTab(value)} + aria-label="simple tabs example" + > + + + + + {tab === 0 && ( + + + + )} + {tab === 1 && ( + + + handlePayloadChange('metadata.backgroundColor')({ + target: { value: color.hex } + }) } - }} - /> - - + + - - )} + }} + /> + + + + )} + - - - {loading && } - - -
+ + {loading && } + + + + + ) } diff --git a/webapp/src/utils/buildDeck.js b/webapp/src/utils/buildDeck.js new file mode 100644 index 00000000..cf2d69a9 --- /dev/null +++ b/webapp/src/utils/buildDeck.js @@ -0,0 +1,32 @@ +import shuffle from 'lodash.shuffle' + +const MAX_CARDS_NUMBER = 20 + +export const buildDeck = () => { + const data = [ + 'Banana', + 'Orange', + 'Apple', + 'Mango', + 'Papaya', + 'Melon', + 'Pepino', + 'kiwi', + 'platano', + 'banano' + ] + const cards = [] + + while (cards.length < MAX_CARDS_NUMBER) { + const index = Math.floor(Math.random() * data.length) + const card = { + image: data.splice(index, 1)[0], + guessedRight: false + } + + cards.push(card) + cards.push({ ...card }) + } + + return shuffle(cards) +} diff --git a/webapp/src/utils/index.js b/webapp/src/utils/index.js index 58f0f1e3..c658b267 100644 --- a/webapp/src/utils/index.js +++ b/webapp/src/utils/index.js @@ -1,3 +1,4 @@ export * from './eosapi' export * from './format-with-thousand-separator' export * from './on-img-error' +export * from './buildDeck' diff --git a/webapp/yarn.lock b/webapp/yarn.lock index 836cc3ff..850e2806 100644 --- a/webapp/yarn.lock +++ b/webapp/yarn.lock @@ -6512,72 +6512,6 @@ __metadata: languageName: node linkType: hard -"eosioboilerplate@workspace:.": - version: 0.0.0-use.local - resolution: "eosioboilerplate@workspace:." - dependencies: - "@ant-design/react-slick": ^0.28.2 - "@apollo/client": ^3.3.11 - "@babel/eslint-parser": ^7.13.10 - "@babel/plugin-proposal-optional-chaining": ^7.13.8 - "@babel/preset-env": ^7.13.10 - "@babel/preset-react": ^7.12.13 - "@date-io/core": ^1.3.6 - "@date-io/date-fns": ^2.10.8 - "@eoscostarica/ual-reactjs-renderer": ^0.3.1 - "@material-ui/core": ^4.11.3 - "@material-ui/icons": ^4.11.2 - "@material-ui/lab": ^4.0.0-alpha.57 - "@material-ui/pickers": ^3.2.10 - "@material-ui/styles": ^4.11.3 - "@material-ui/system": ^4.11.3 - clsx: ^1.1.1 - core-js: ^3.9.1 - customize-cra: ^1.0.0 - date-fns: ^2.19.0 - env-cmd: ^10.1.0 - eosjs-api: ^7.0.4 - eslint: ^7.22.0 - eslint-config-prettier: ^8.1.0 - eslint-config-standard: ^16.0.2 - eslint-config-standard-react: ^11.0.1 - eslint-plugin-import: ^2.22.1 - eslint-plugin-node: ^11.1.0 - eslint-plugin-prettier: ^3.3.1 - eslint-plugin-promise: ^4.3.1 - eslint-plugin-react: ^7.22.0 - fabric: ^4.3.1 - graphql: ^15.5.0 - graphql-tag: ^2.11.0 - history: ^5.0.0 - husky: 4.3.8 - i18next: ^19.9.1 - i18next-browser-languagedetector: ^6.0.1 - lint-staged: ^10.5.4 - material-ui-dropzone: ^3.5.0 - polished: ^4.1.1 - prettier: ^2.2.1 - prop-types: ^15.7.2 - react: ~17.0.1 - react-app-rewired: ^2.1.8 - react-color: ^2.19.3 - react-dom: ~17.0.1 - react-feather: ^2.0.9 - react-helmet: ^6.1.0 - react-i18next: ^11.8.8 - react-is: ^17.0.1 - react-perfect-scrollbar: ^1.5.8 - react-router: ^5.2.0 - react-router-dom: ^5.2.0 - react-scripts: ^4.0.3 - slick-carousel: ^1.8.1 - standard: ^16.0.3 - subscriptions-transport-ws: ^0.9.18 - ual-anchor: ^1.0.2 - ual-token-pocket: ^0.3.0 - languageName: unknown - linkType: soft - "eosjs-api@npm:^7.0.4": version: 7.0.4 resolution: "eosjs-api@npm:7.0.4" @@ -8045,6 +7979,74 @@ fsevents@^1.2.7: languageName: node linkType: hard +"gGoods@workspace:.": + version: 0.0.0-use.local + resolution: "gGoods@workspace:." + dependencies: + "@ant-design/react-slick": ^0.28.2 + "@apollo/client": ^3.3.11 + "@babel/eslint-parser": ^7.13.10 + "@babel/plugin-proposal-optional-chaining": ^7.13.8 + "@babel/preset-env": ^7.13.10 + "@babel/preset-react": ^7.12.13 + "@date-io/core": ^1.3.6 + "@date-io/date-fns": ^2.10.8 + "@eoscostarica/ual-reactjs-renderer": ^0.3.1 + "@material-ui/core": ^4.11.3 + "@material-ui/icons": ^4.11.2 + "@material-ui/lab": ^4.0.0-alpha.57 + "@material-ui/pickers": ^3.2.10 + "@material-ui/styles": ^4.11.3 + "@material-ui/system": ^4.11.3 + clsx: ^1.1.1 + core-js: ^3.9.1 + customize-cra: ^1.0.0 + date-fns: ^2.19.0 + env-cmd: ^10.1.0 + eosjs-api: ^7.0.4 + eslint: ^7.22.0 + eslint-config-prettier: ^8.1.0 + eslint-config-standard: ^16.0.2 + eslint-config-standard-react: ^11.0.1 + eslint-plugin-import: ^2.22.1 + eslint-plugin-node: ^11.1.0 + eslint-plugin-prettier: ^3.3.1 + eslint-plugin-promise: ^4.3.1 + eslint-plugin-react: ^7.22.0 + fabric: ^4.3.1 + graphql: ^15.5.0 + graphql-tag: ^2.11.0 + history: ^5.0.0 + husky: 4.3.8 + i18next: ^19.9.1 + i18next-browser-languagedetector: ^6.0.1 + lint-staged: ^10.5.4 + lodash.shuffle: ^4.2.0 + material-ui-dropzone: ^3.5.0 + polished: ^4.1.1 + prettier: ^2.2.1 + prop-types: ^15.7.2 + react: ~17.0.1 + react-app-rewired: ^2.1.8 + react-card-flip: ^1.1.0 + react-color: ^2.19.3 + react-dom: ~17.0.1 + react-feather: ^2.0.9 + react-helmet: ^6.1.0 + react-i18next: ^11.8.8 + react-is: ^17.0.1 + react-perfect-scrollbar: ^1.5.8 + react-router: ^5.2.0 + react-router-dom: ^5.2.0 + react-scripts: ^4.0.3 + slick-carousel: ^1.8.1 + standard: ^16.0.3 + subscriptions-transport-ws: ^0.9.18 + ual-anchor: ^1.0.2 + ual-token-pocket: ^0.3.0 + languageName: unknown + linkType: soft + "gauge@npm:~2.7.3": version: 2.7.4 resolution: "gauge@npm:2.7.4" @@ -10822,6 +10824,13 @@ fsevents@^1.2.7: languageName: node linkType: hard +"lodash.shuffle@npm:^4.2.0": + version: 4.2.0 + resolution: "lodash.shuffle@npm:4.2.0" + checksum: 9c2f9a18029e0f87250e6d1a7201b32f4152092a15ea12cbcf65d2a23f19ddbb688ae4770c9c1dcc0bf596c362847fbe5f8ff76ecb736b58af920518b8426f6f + languageName: node + linkType: hard + "lodash.sortby@npm:^4.7.0": version: 4.7.0 resolution: "lodash.sortby@npm:4.7.0" @@ -13865,6 +13874,16 @@ fsevents@^1.2.7: languageName: node linkType: hard +"react-card-flip@npm:^1.1.0": + version: 1.1.0 + resolution: "react-card-flip@npm:1.1.0" + peerDependencies: + react: ^17.0.1 + react-dom: ^17.0.1 + checksum: 066a4f3afd170497144bb0f455790ae5509f1cc30f58d31b4631e54421f258d724601c51bbeed4195b8b789cce647ea601e6b0094959cb18185c41f4ce40297c + languageName: node + linkType: hard + "react-color@npm:^2.19.3": version: 2.19.3 resolution: "react-color@npm:2.19.3"