From 6377a5084228c61a8bded181259acd3d3e6ce44d Mon Sep 17 00:00:00 2001 From: Jeremie Pardou-Piquemal <571533+jrmi@users.noreply.github.com> Date: Sun, 7 Jun 2020 20:05:09 +0200 Subject: [PATCH] Clean before publish --- README.md | 76 ++++++---------------------- public/games/tiktok.svg | 78 +++++++++++++++++++++++++++++ src/atoms/ItemListState.js | 8 --- src/components/Board.js | 3 +- src/components/Cursors.js | 3 -- src/components/Item.js | 10 +++- src/components/PanZoomRotate.js | 6 +-- src/components/Rect.js | 21 -------- src/components/User.js | 23 --------- src/context/userCtx.js | 7 --- src/{utils => games}/tiktok.js | 4 +- src/hooks/useRoom.js | 88 --------------------------------- src/server.js | 38 -------------- src/socket-client.js | 35 ------------- src/views/BoardView.js | 7 +-- 15 files changed, 110 insertions(+), 297 deletions(-) create mode 100644 public/games/tiktok.svg delete mode 100644 src/atoms/ItemListState.js delete mode 100644 src/components/Rect.js delete mode 100644 src/components/User.js delete mode 100644 src/context/userCtx.js rename src/{utils => games}/tiktok.js (96%) delete mode 100644 src/hooks/useRoom.js delete mode 100644 src/socket-client.js diff --git a/README.md b/README.md index 54ef094..b1312b7 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,24 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +# Air board game -## Available Scripts +Play any board game with your friends thanks to this tabletop simulator. -In the project directory, you can run: +## Installation -### `npm start` +You need a recent node version. You can use nvm to initialize your environment. +Then, execute -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. +```sh +npm ci # To install dependencies +``` -The page will reload if you make edits.
-You will also see any lint errors in the console. +First you need to start the server: -### `npm test` +```sh +npm run server +``` -Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. +Then you can run the client: -### `npm run build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting - -### Analyzing the Bundle Size - -This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size - -### Making a Progressive Web App - -This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app - -### Advanced Configuration - -This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration - -### Deployment - -This section has moved here: https://facebook.github.io/create-react-app/docs/deployment - -### `npm run build` fails to minify - -This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify +```sh +npm start +``` diff --git a/public/games/tiktok.svg b/public/games/tiktok.svg new file mode 100644 index 0000000..30ec72c --- /dev/null +++ b/public/games/tiktok.svg @@ -0,0 +1,78 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/atoms/ItemListState.js b/src/atoms/ItemListState.js deleted file mode 100644 index e7b7809..0000000 --- a/src/atoms/ItemListState.js +++ /dev/null @@ -1,8 +0,0 @@ -import { atom } from 'recoil'; - -export const ItemListState = atom({ - key: 'itemList', - default: [], -}); - -export default ItemListState; diff --git a/src/components/Board.js b/src/components/Board.js index 66fbdc8..bf7b046 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -7,7 +7,6 @@ import { useRecoilValue } from 'recoil'; export const Board = ({ user, users, items, config }) => { const [c2c, joined, isMaster] = useC2C(); - const [background, setBackground] = React.useState(''); const panZoomRotate = useRecoilValue(PanZoomRotateState); const onMouseMove = (e) => { @@ -40,7 +39,7 @@ export const Board = ({ user, users, items, config }) => { className='content' style={{ background: - 'repeating-linear-gradient(45deg, #606dbcA0, #606dbcA0 10px, #46529880 10px, #46529880 20px)', + 'repeating-linear-gradient(45deg, #606dbc60, #606dbc60 10px, #46529860 10px, #46529860 20px)', /*backgroundImage: `url(${background})`, backgroundSize: '50%', backgroundPosition: '50% 50%', diff --git a/src/components/Cursors.js b/src/components/Cursors.js index a74033e..46c6044 100644 --- a/src/components/Cursors.js +++ b/src/components/Cursors.js @@ -1,13 +1,10 @@ import React from 'react'; import { useC2C } from '../hooks/useC2C'; import Cursor from './Cursor'; -import { PanZoomRotateState } from '../components/PanZoomRotate'; -import { useRecoilValue } from 'recoil'; export const Cursors = ({ users }) => { const [c2c, joined] = useC2C(); const [cursors, setCursors] = React.useState({}); - const panZoomRotate = useRecoilValue(PanZoomRotateState); const colors = React.useMemo(() => { return users.reduce((acc, user) => { diff --git a/src/components/Item.js b/src/components/Item.js index 05a3377..883ad8d 100644 --- a/src/components/Item.js +++ b/src/components/Item.js @@ -45,8 +45,16 @@ const Round = ({ radius, color }) => { }; // See https://stackoverflow.com/questions/3680429/click-through-div-to-underlying-elements +// https://developer.mozilla.org/fr/docs/Web/CSS/pointer-events const Image = ({ width, height, content }) => { - return ; + const size = {}; + if (width) { + size.width = width; + } + if (height) { + size.height = height; + } + return ; }; const getComponent = (type) => { diff --git a/src/components/PanZoomRotate.js b/src/components/PanZoomRotate.js index ee1d2d6..b53687e 100644 --- a/src/components/PanZoomRotate.js +++ b/src/components/PanZoomRotate.js @@ -4,9 +4,9 @@ import { atom, useRecoilState } from 'recoil'; export const PanZoomRotateState = atom({ key: 'PanZoomRotate', default: { - translateX: 50, - translateY: 50, - scale: 1.2, + translateX: 0, + translateY: 0, + scale: 1, rotate: 0, }, }); diff --git a/src/components/Rect.js b/src/components/Rect.js deleted file mode 100644 index c27275e..0000000 --- a/src/components/Rect.js +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; - -export const Rect = ({ - color = '#DD0022', - width = 10, - height = 10, - style, - ...props -}) => ( -
-); - -export default Rect; diff --git a/src/components/User.js b/src/components/User.js deleted file mode 100644 index c09c422..0000000 --- a/src/components/User.js +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import './App.css'; -import { emitMouseMove, init } from './socket-client'; - -function withUsers() { - const [size, setSize] = React.useState({ width: 20, height: 50 }); - const [cursorPos, setCursorPos] = React.useState({ x: 0, y: 0 }); - - const onMouseMove = (e) => { - emitMouseMove({ x: e.clientX, y: e.clientY }); - }; - - React.useEffect(() => { - const onCursorMove = ({ user, newPos }) => { - setCursorPos(newPos); - }; - init({ onCursorMove }); - }, []); - - return null; -} - -export default User; diff --git a/src/context/userCtx.js b/src/context/userCtx.js deleted file mode 100644 index 6b0f275..0000000 --- a/src/context/userCtx.js +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -export const UserContext = React.createContext([]); - -export const UserProvider = UserContext.Provider; - -export default { UserContext, UserProvider }; diff --git a/src/utils/tiktok.js b/src/games/tiktok.js similarity index 96% rename from src/utils/tiktok.js rename to src/games/tiktok.js index a3caf30..04b4571 100644 --- a/src/utils/tiktok.js +++ b/src/games/tiktok.js @@ -5,9 +5,7 @@ const genTikTok = () => { items.push({ type: 'image', - content: '/tiktok.svg', - width: 35, - height: 60, + content: '/games/tiktok.svg', locked: true, x: 100, y: 100, diff --git a/src/hooks/useRoom.js b/src/hooks/useRoom.js deleted file mode 100644 index 7bb504c..0000000 --- a/src/hooks/useRoom.js +++ /dev/null @@ -1,88 +0,0 @@ -import React from 'react'; -import { useSocket } from '@scripters/use-socket.io'; -// import { nanoid } from 'nanoid'; -//import debounce from 'lodash.debounce'; -import { join } from 'client2client.io'; - -const useRoom = ({ room, user, setUser, onMouseMove = () => {} }) => { - const socket = useSocket(); - //const [users, setUsers] = React.useState([]); - const [user, setUser] = React.useState([]); - const [joined, setJoined] = React.useState(false); - const [isMaster, setMaster] = React.useState(false); - const roomRef = React.useRef(null); - const usersRef = React.useRef([]); - - React.useEffect(() => { - if (!socket) { - return; - } - join(socket, room).then((newRoom) => { - console.log('Connected…'); - - roomRef.current = newRoom; - - roomRef.current.call('getUserList').then( - (userList) => { - console.log('get user list'); - usersRef.current = userList; - setJoined(true); - }, - () => { - console.log('I am the master'); - // I'm the master - setMaster(true); - - setUser((prevUser) => ({ ...prevUser, id: roomRef.current.userId })); - /*usersRef.current = [ - { - ...user, - }, - ];*/ - newRoom.register('getUserList', () => { - return usersRef.current; - }); - newRoom.subscribe('userLeave', () => {}); - setJoined(true); - } - ); - - const unsubscribeUpdateUsers = newRoom.subscribe( - 'updateUserList', - (userList) => { - console.log('upuser', userList); - usersRef.current = userList; - } - ); - - const unsubscribeMouseMouve = newRoom.subscribe('mouseMove', (data) => { - onMouseMove(data); - }); - - return () => { - unsubscribeMouseMouve(); - unsubscribeUpdateUsers(); - }; - }); - }, [room, socket]); - - React.useEffect(() => { - if (!joined) { - return; - } - console.log('should up users'); - if (usersRef.current.find((u) => u.id === user.id)) { - const newUsers = usersRef.current.map((u) => - u.id === user.id ? user : u - ); - roomRef.current.publish('updateUserList', newUsers, true); - } else { - const newUsers = [...usersRef.current, user]; - roomRef.current.publish('updateUserList', newUsers, true); - } - }, [user, joined]); - - return [usersRef, joined]; -}; - -export default useRoom; diff --git a/src/server.js b/src/server.js index 98510a8..e0f1cb9 100644 --- a/src/server.js +++ b/src/server.js @@ -1,43 +1,5 @@ -/*const io = require('socket.io')(); -const uuid = require('uuid'); - -const rooms = {}; - -io.on('connection', (socket) => { - socket.on('join', (roomName) => { - if (rooms[roomName] === undefined) { - rooms[roomName] = []; - } - const userId = uuid.v4(); - rooms[roomName].push(userId); - console.log(`User ${userId} join ${roomName}`); - - socket.join(roomName); - socket.emit('yourid', { user: userId }); - - // Send new user to all user of this room - socket.broadcast.to(roomName).emit('incoming', { user: userId }); - - socket.on('mouseMove', (newPos) => { - socket.broadcast - .to(roomName) - .emit('mouseMoved', { user: userId, newPos }); - }); - socket.on('disconnect', () => { - console.log(`User ${userId} disconnected`); - rooms[roomName] = rooms[roomName].filter((id) => id === userId); - }); - }); -}); - -const port = 8000; -io.listen(port); -console.log('listening on port ', port);*/ - -var nanoid = require('nanoid').nanoid; var express = require('express'); const path = require('path'); -/*const Datastore = require('nedb');*/ var app = express(); var http = require('http').createServer(app); diff --git a/src/socket-client.js b/src/socket-client.js deleted file mode 100644 index 58b53b8..0000000 --- a/src/socket-client.js +++ /dev/null @@ -1,35 +0,0 @@ -import openSocket from 'socket.io-client'; -import { nanoid } from 'nanoid'; - -const socket = openSocket('http://localhost:8000'); - -const queryString = window.location.search; -const urlParams = new URLSearchParams(queryString); - -const roomName = urlParams.get('room'); -console.log(roomName); - -let userList = []; - -export const init = ({ onCursorMove }) => { - const user = { - name: 'userx', - uid: nanoid(), - }; - - // When other move their mouse - socket.on('mouseMoved', (params) => { - onCursorMove(params); - }); - - socket.on('userListUpdate', () => {}); - - // Finally join the room - socket.emit('join', { room: roomName, user }); -}; - -export const emitMouseMove = (newPos) => { - socket.emit('mouseMove', newPos); -}; - -export default socket; diff --git a/src/views/BoardView.js b/src/views/BoardView.js index e762de0..e25ce95 100644 --- a/src/views/BoardView.js +++ b/src/views/BoardView.js @@ -1,13 +1,10 @@ import React from 'react'; -import Rect from '../components/Rect'; -import Cursors from '../components/Cursors'; import Users from '../components/Users'; -import Item from '../components/Item'; import { useC2C } from '../hooks/useC2C'; import useUser from '../hooks/useUser'; import useUsers from '../hooks/useUsers'; -import tiktok from '../utils/tiktok'; +import tiktok from '../games/tiktok'; import { nanoid } from 'nanoid'; import ZoomPanRotate from '../components/PanZoomRotate'; import Board from '../components/Board'; @@ -54,7 +51,7 @@ export const BoardView = ({ room }) => { }} onClick={loadGame} > - Start + TikTok )}