Clean before publish
This commit is contained in:
parent
5ab40a3501
commit
6377a50842
15 changed files with 110 additions and 297 deletions
76
README.md
76
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.<br />
|
||||
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.<br />
|
||||
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.<br />
|
||||
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.<br />
|
||||
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.<br />
|
||||
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
|
||||
```
|
||||
|
|
78
public/games/tiktok.svg
Normal file
78
public/games/tiktok.svg
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="1000"
|
||||
height="1000"
|
||||
viewBox="0 0 264.58333 264.58334"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||
sodipodi:docname="tiktok.svg">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.35"
|
||||
inkscape:cx="284.9497"
|
||||
inkscape:cy="560.1347"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1267"
|
||||
inkscape:window-height="701"
|
||||
inkscape:window-x="149"
|
||||
inkscape:window-y="121"
|
||||
inkscape:window-maximized="0"
|
||||
units="px" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Calque 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-32.41665)">
|
||||
<path
|
||||
style="fill:none;stroke:#3dde5f;stroke-width:2.67282083;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 84.906044,39.97619 V 288.38394"
|
||||
id="path823"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="fill:none;stroke:#3dde5f;stroke-width:2.67282083;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 172.00073,39.97619 V 288.38394"
|
||||
id="path825"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path817"
|
||||
d="M 259.11653,110.66881 H 3.0726933"
|
||||
style="fill:none;stroke:#3dde5f;stroke-width:2.67282083;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path819"
|
||||
d="M 259.11653,197.76349 H 3.0726933"
|
||||
style="fill:none;stroke:#3dde5f;stroke-width:2.67282083;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.7 KiB |
|
@ -1,8 +0,0 @@
|
|||
import { atom } from 'recoil';
|
||||
|
||||
export const ItemListState = atom({
|
||||
key: 'itemList',
|
||||
default: [],
|
||||
});
|
||||
|
||||
export default ItemListState;
|
|
@ -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%',
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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 <img src={content} draggable={false} />;
|
||||
const size = {};
|
||||
if (width) {
|
||||
size.width = width;
|
||||
}
|
||||
if (height) {
|
||||
size.height = height;
|
||||
}
|
||||
return <img src={content} draggable={false} {...size} />;
|
||||
};
|
||||
|
||||
const getComponent = (type) => {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import React from 'react';
|
||||
|
||||
export const Rect = ({
|
||||
color = '#DD0022',
|
||||
width = 10,
|
||||
height = 10,
|
||||
style,
|
||||
...props
|
||||
}) => (
|
||||
<div
|
||||
style={{
|
||||
...style,
|
||||
width: `100%`,
|
||||
height: `100%`,
|
||||
backgroundColor: color,
|
||||
}}
|
||||
{...props}
|
||||
></div>
|
||||
);
|
||||
|
||||
export default Rect;
|
|
@ -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;
|
|
@ -1,7 +0,0 @@
|
|||
import React from 'react';
|
||||
|
||||
export const UserContext = React.createContext([]);
|
||||
|
||||
export const UserProvider = UserContext.Provider;
|
||||
|
||||
export default { UserContext, UserProvider };
|
|
@ -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,
|
|
@ -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;
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
|
@ -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
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue