moved folders around and added janken

This commit is contained in:
2020-08-01 01:41:44 +09:00
parent dbe12e3c86
commit b442e33405
124 changed files with 1178 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 467 KiB

View File

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 134 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 187 KiB

After

Width:  |  Height:  |  Size: 187 KiB

View File

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 186 KiB

View File

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 182 KiB

View File

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 199 KiB

View File

Before

Width:  |  Height:  |  Size: 225 KiB

After

Width:  |  Height:  |  Size: 225 KiB

View File

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

View File

Before

Width:  |  Height:  |  Size: 212 KiB

After

Width:  |  Height:  |  Size: 212 KiB

View File

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 213 KiB

View File

Before

Width:  |  Height:  |  Size: 209 KiB

After

Width:  |  Height:  |  Size: 209 KiB

View File

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 KiB

View File

Before

Width:  |  Height:  |  Size: 461 KiB

After

Width:  |  Height:  |  Size: 461 KiB

View File

Before

Width:  |  Height:  |  Size: 457 KiB

After

Width:  |  Height:  |  Size: 457 KiB

View File

Before

Width:  |  Height:  |  Size: 448 KiB

After

Width:  |  Height:  |  Size: 448 KiB

View File

Before

Width:  |  Height:  |  Size: 454 KiB

After

Width:  |  Height:  |  Size: 454 KiB

View File

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 206 KiB

View File

Before

Width:  |  Height:  |  Size: 215 KiB

After

Width:  |  Height:  |  Size: 215 KiB

View File

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 126 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

Before

Width:  |  Height:  |  Size: 226 KiB

After

Width:  |  Height:  |  Size: 226 KiB

View File

Before

Width:  |  Height:  |  Size: 219 KiB

After

Width:  |  Height:  |  Size: 219 KiB

View File

Before

Width:  |  Height:  |  Size: 702 KiB

After

Width:  |  Height:  |  Size: 702 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 161 KiB

After

Width:  |  Height:  |  Size: 161 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 748 KiB

After

Width:  |  Height:  |  Size: 748 KiB

View File

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@@ -15,12 +15,14 @@
"cors": "^2.8.5",
"express": "^4.17.1",
"mysql": "^2.18.1",
"socket.io": "^2.3.0",
"ts-node-dev": "^1.0.0-pre.44",
"uuid": "^7.0.3"
},
"devDependencies": {
"@types/express": "^4.17.6",
"@types/mysql": "^2.1.4",
"@types/socket.io": "^2.1.4",
"typescript": "^3.8.3",
"tslint": "^5.18.0",
"tslint-config-airbnb": "^5.11.1"

View File

@@ -1,12 +1,17 @@
import express from 'express';
import socketIo from 'socket.io';
import http from 'http';
import cors from 'cors';
import mysql from 'mysql';
import { v1 } from 'uuid';
const port: number = 443;
import { IJankenSelect, IJankenResult } from './models/message';
const port: number = 8080;
const app: express.Express = express();
const httpServer: http.Server = http.createServer(app);
const io: socketIo.Server = socketIo(httpServer);
const tournaments: Record<string, number> = {};
const players: Record<string, number> = {};
const connection = mysql.createPool({
@@ -138,8 +143,134 @@ app.use('/about', express.static('client'));
app.use('/guide', express.static('client'));
app.use('/archive', express.static('client'));
app.use('/contact', express.static('client'));
app.use('/tool', express.static('tool'));
app.use(express.static('client'));
httpServer.listen(port, () => {
console.log(`listening to port ${port}`);
});
// Janken Tool
let room: boolean = false;
let playerOne: string = '';
let playerTwo: string = '';
let playerOneOption: string = '';
let playerTwoOption: string = '';
let stages: string[] = [];
let currentIndex: number = 0;
const defaultStages: string[] = ['cementery', 'prison', 'torture', 'inquisition', 'quadrangle', 'clock', 'spiral', 'empireo', 'cathedral', 'close', 'arrange'];
io.on('connection', (socket: socketIo.Socket) => {
socket.on('disconnect', () => {
console.log('disconnect');
});
socket.on('exitGame', () => {
console.log('exitGame');
io.emit('exitGame');
room = false;
initRoom();
Object.keys(io.sockets.sockets).forEach((s) => {
io.sockets.sockets[s].disconnect(true);
});
});
socket.on('janken', (data: IJankenSelect) => {
console.log('janken', data);
if (playerOne === data.userName) {
playerOneOption = data.option;
} else if (playerTwo === data.userName) {
playerTwoOption = data.option;
}
console.log('playerOneOption',playerOneOption);
console.log('playerTwoOption',playerTwoOption);
if (playerOneOption !== '' && playerTwoOption !== '') {
const message: IJankenResult = {
playerOne,
playerOneOption,
playerTwo,
playerTwoOption
}
io.emit('jankenResult', message);
}
});
socket.on('registerUser', (data: string) => {
console.log('registerUser', data);
if (playerOne === '') {
playerOne = data;
socket.emit('registerUser', data);
} else if (playerTwo === '') {
playerTwo = data;
socket.emit('registerUser', data);
}
const message = {
playerOne: playerOne,
playerTwo: playerTwo,
};
console.log()
io.emit('login', message);
});
socket.on('moveToStage', () => {
console.log('moveToStage');
stages = shuffle(defaultStages);
currentIndex = 0;
io.emit('stages', stages);
});
socket.on('nextIndex', () => {
console.log('nextIndex');
if (currentIndex < stages.length) {
currentIndex += 1;
io.emit('updateIndex', currentIndex);
}
});
socket.on('againGame', () => {
console.log('againGame');
io.emit('againGame');
playerOneOption = '';
playerTwoOption = '';
});
socket.on('previousIndex', () => {
console.log('previousIndex');
if (currentIndex > 0) {
currentIndex -= 1;
io.emit('updateIndex', currentIndex);
}
});
if (!room) {
// create new room
initRoom();
room = true;
const message = {
playerOne: '',
playerTwo: '',
};
socket.emit('login', message);
}
else {
if (playerOne === '' || playerTwo === '' || playerOneOption === '' || playerTwoOption === '') {
const message = {
playerOne: playerOne,
playerTwo: playerTwo,
};
socket.emit('login', message);
} else {
const message = {
stages,
currentIndex
}
socket.emit('stages', message);
}
}
});
const shuffle = (array: string[]): string[] => {
return array.sort(() => Math.random() - 0.5);
};
const initRoom = (): void => {
playerOne = '';
playerTwo = '';
playerOneOption = '';
playerTwoOption = '';
};

View File

@@ -0,0 +1,20 @@
export interface ILoginMessage {
playerOne: string;
playerTwo: string;
}
export interface IJankenResult {
playerOne: string;
playerTwo: string;
playerOneOption: string;
playerTwoOption: string;
}
export interface ILogin {
userName: string;
}
export interface IJankenSelect {
userName: string;
option: string;
}

1
tools/client/.env Normal file
View File

@@ -0,0 +1 @@
REACT_APP_WEBSOCKET=ws://localhost:8080

View File

@@ -0,0 +1 @@
REACT_APP_WEBSOCKET=wss://www.catherine-fc.com/

23
tools/client/.gitignore vendored Normal file
View File

@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

44
tools/client/README.md Normal file
View File

@@ -0,0 +1,44 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br />
You will also see any lint errors in the console.
### `npm test`
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.
### `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 cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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/).

50
tools/client/package.json Normal file
View File

@@ -0,0 +1,50 @@
{
"name": "catherine-janken",
"version": "0.1.0",
"private": true,
"dependencies": {
"dotenv": "^8.2.0",
"node-sass": "^4.13.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.88.2",
"socket.io-client": "^2.3.0",
"typescript": "^3.7.5"
},
"devDependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^24.9.1",
"@types/node": "^12.12.53",
"@types/react": "^16.9.43",
"@types/react-dom": "^16.9.8",
"@types/socket.io-client": "^1.4.32",
"tslint": "^5.18.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-react": "^4.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Catherine Janken"
/>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Catherine Janken</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

24
tools/client/src/App.css Normal file
View File

@@ -0,0 +1,24 @@
.App {
height: 100vh;
width: 100vw;
background-image: url('./straysheep.png') ;
background-size: cover;
background-repeat: none;
}
.EnterButton {
display: flex;
height: 100%;
width: 100%;
justify-content: center;
align-items: center;
}
.EnterButton > button {
height: 50px;
width: 150px;
}
.HiddenExit {
display: none;
}

View File

@@ -0,0 +1,9 @@
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

167
tools/client/src/App.tsx Normal file
View File

@@ -0,0 +1,167 @@
import React, { useState } from 'react';
import './App.css';
import 'semantic-ui-css/semantic.min.css';
import socketIOClient from 'socket.io-client';
import { ILoginMessage, IJankenResult, IJankenSelect } from './model/messages';
import { Button } from 'semantic-ui-react';
import { Janken } from './component/janken/Janken';
import { Stage } from './component/stage/Stage';
function App(): JSX.Element {
const [socket, setSocket] = useState<SocketIOClient.Socket | null>(null);
const [stages, setStages] = useState<string[]>([]);
const [currentUser, setCurrentUser] = useState<string>('');
const [currentPlayers, setCurrentPlayers] = useState<ILoginMessage>({playerOne:'', playerTwo:''});
const [currentIndex, setCurrentIndex] = useState<number>(0);
const [jankenResult, setJankenResult] = useState<IJankenResult | null>(null);
const join = (): void => {
const wsUrl: string | undefined = process.env.REACT_APP_WEBSOCKET;
if (wsUrl){
const sock: SocketIOClient.Socket = socketIOClient(wsUrl);
sock.on('connect', () => {
if (sock.connected) {
console.log('接続!');
} else if (sock.disconnected) {
setSocket(null);
setStages([]);
setCurrentUser('');
setCurrentPlayers({playerOne:'', playerTwo:''});
setCurrentIndex(0);
setJankenResult(null);
} else {
console.log('しらんがな', sock);
}
});
sock.on('login', (data: ILoginMessage) => {
console.log(data);
setCurrentPlayers(data);
});
sock.on('registerUser', (data: string) => {
console.log(data);
setCurrentUser(data);
});
sock.on('jankenResult', (data: IJankenResult) => {
setJankenResult(data);
});
sock.on('againGame', () => {
setJankenResult(null);
});
sock.on('stages', (data: string[]) => {
setStages(data);
setCurrentIndex(0);
});
sock.on('updateIndex', (data: number) => {
setCurrentIndex(data);
});
sock.on('exitGame', () => {
setSocket(null);
setStages([]);
setCurrentUser('');
setCurrentPlayers({playerOne:'', playerTwo:''});
setCurrentIndex(0);
setJankenResult(null);
});
setSocket(sock);
}
}
const janken = (option: string): void => {
if (socket && currentUser) {
const message: IJankenSelect = {
userName: currentUser,
option
};
socket.emit('janken', message);
}
};
const moveToStage = (): void => {
if (socket) {
socket.emit('moveToStage');
}
};
const registerUser = (username: string): void => {
if (socket) {
socket.emit('registerUser', username);
}
};
const previousIndex = (): void => {
if (socket && currentIndex > 0) {
socket.emit('previousIndex');
}
};
const nextIndex = (): void => {
if (socket && currentIndex < stages.length) {
socket.emit('nextIndex');
}
};
const againGame = (): void => {
if (socket) {
socket.emit('againGame');
}
};
const exitGame = (): void => {
if (socket) {
socket.emit('exitGame');
}
};
const render = (): JSX.Element => {
if (socket === null) {
return (
<div className="EnterButton">
<Button
color='pink'
size='large'
onClick={join}
>
JOIN
</Button>
</div>
);
} else {
if (stages.length === 0) {
return (
<Janken
currentUser={currentUser}
currentPlayers={currentPlayers}
jankenResults={jankenResult}
janken={janken}
onSubmit={registerUser}
moveToStage={moveToStage}
againGame={againGame}
/>
);
} else {
return (
<Stage
stages={stages}
currentIndex={currentIndex}
previousIndex={previousIndex}
nextIndex={nextIndex}
exitGame={exitGame}
/>
);
}
}
};
return (
<div className="App">
{render()}
<div className="HiddenExit">
<Button
color='pink'
size='large'
onClick={exitGame}
>
exit
</Button>
</div>
</div>
);
}
export default App;

Some files were not shown because too many files have changed in this diff Show More