Compare commits
No commits in common. "master" and "refactor_socket" have entirely different histories.
master
...
refactor_s
236 changed files with 5672 additions and 20229 deletions
|
@ -1,55 +0,0 @@
|
|||
# JavaScript Node CircleCI 2.0 configuration file
|
||||
#
|
||||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
|
||||
#
|
||||
version: 2
|
||||
|
||||
commands:
|
||||
create_concatenated_package_lock:
|
||||
description: "Concatenate all package-lock.json files recognized by lerna.js into single file. File is used as checksum source for part of caching key."
|
||||
parameters:
|
||||
filename:
|
||||
type: string
|
||||
steps:
|
||||
- run:
|
||||
name: Combine package-lock.json files to single file
|
||||
command: npx lerna list -p -a | awk -F packages '{printf "\"packages%s/package-lock.json\" ", $2}' | xargs cat > << parameters.filename >>
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
# specify the version you desire here
|
||||
- image: circleci/node:12.6
|
||||
|
||||
working_directory: ~/node-go
|
||||
|
||||
steps:
|
||||
- checkout
|
||||
# - run: sudo apt-get install postgresql-client-11.4
|
||||
# - run: pg_ctl -D /var/lib/postgresql/data -l logfile start
|
||||
# - run: psql CREATE DATABASE circle_test
|
||||
|
||||
# Download and cache dependencies
|
||||
- restore_cache:
|
||||
keys:
|
||||
- v1-dependencies-{{ checksum "package-lock.json" }}
|
||||
# fallback to using the latest cache if no exact match is found
|
||||
|
||||
|
||||
- run: npm install
|
||||
- run: npm run bootstrap
|
||||
|
||||
- save_cache:
|
||||
paths:
|
||||
- node_modules
|
||||
key:
|
||||
v1-dependencies-{{ checksum "package-lock.json" }}
|
||||
- run: npm test
|
||||
- run: npm install react
|
||||
- run: npm install react-dom
|
||||
|
||||
# ! temporary fix for deprecated package: minimist
|
||||
- run: npm audit --audit-level=moderate
|
||||
|
||||
# DEPLOY
|
||||
- run: git subtree push --prefix packages/server https://heroku:$HEROKU_API_KEY@git.heroku.com/$HK_API.git master
|
||||
- run: git subtree push --prefix packages/play-node-go https://heroku:$HEROKU_API_KEY@git.heroku.com/$HK_PLAY.git master
|
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Sorrel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
160
README.md
160
README.md
|
@ -1,170 +1,18 @@
|
|||
# Node Go
|
||||
A browser application to play Go in real time.
|
||||
|
||||
[The project in it's current state](https://play-node-go.herokuapp.com/)
|
||||
[Client only prototype](https://sorrelbri.github.io/browser-go-proto/)
|
||||
## Development Demo
|
||||
[The project in it's current state](https://play-node-go.herokuapp.com/)
|
||||
|
||||
![Screenshot of an in-progress game of Go.](public/game-in-progress.png)
|
||||
|
||||
[About Go](#the-game-of-go)
|
||||
[Technical Challenges](#technical-challenges)
|
||||
[Setup For Development](#setup)
|
||||
[Known Bugs](#known-bugs)
|
||||
[Roadmap](#roadmap)
|
||||
[Features](#features)
|
||||
[Tech](#built-with)
|
||||
|
||||
---
|
||||
## The Game of Go
|
||||
Go is a 2 player abstract strategy game of perfect information.
|
||||
|
||||
Players take turns placing playing pieces called stones on the intersections of a gridded board. This board is usually a square 19 points across. Stones remain on the points at which they are placed unless they are captured by the opposing player. Capture occurs when a stone or group of stones no longer has any adjascent empty points.
|
||||
|
||||
Play ends when both players agree that they have exhausted all advantageous moves. Scoring is determined by counting and comparing the area controlled by either player.
|
||||
|
||||
For a more detailed explanation of the rules, please see [my previous illustrated explanation of the game of go](https://github.com/sorrelbri/browser-go-proto#the-game-of-go) or the [American Go Association's Concise Rules of Go.](https://www.usgo.org/aga-concise-rules-go)
|
||||
|
||||
---
|
||||
## Technical Challenges
|
||||
### Modeling Game State
|
||||
A go board typically consists of 361 points which can exist in a number of states. Points can influence the state of points that are orthogonal neighbors. This relationship can be thought of as an undirected graph, with each point being a vertex typically of degree 4. Special cases include 'edge' points, whose degree is 3 or, in the case of corner points, 2.
|
||||
|
||||
Many of the methods that manage the state of the game and of the board, make use of this graph representation. Groups are contiguous points with the same color stone which are important in determining the life or death of stones on the board. When a player makes a move, (provided that move is legal,) the point at which the move is made will utilize a breadth-first graph traversal calling a `joinGroup` method on each point with the same color stone.
|
||||
|
||||
Adjacent points without stones are very important to the state of a point as well. These are known as liberties, and so long as a group of stones has at least one point with at least one liberty, that group remains alive and on the board. Therefore, the `joinGroup` method also utilizes a depth first traversal to mark all of the liberties of a group. Both the stones and the liberties of the group are memoized on the Game object.
|
||||
|
||||
![Image of Game logic](public/game-logic.png)
|
||||
|
||||
### Game Records
|
||||
For the moment, game records are modeled as a list where each move has the type `{player: <string: player color>, pos: {x: <integer>, y: <integer>}}`.
|
||||
|
||||
The database `move` table contains additional information `number`, `game_record`, and `prior_move` in addition to a foreign key for a `game` row. `number` represents the move number in a game record (for now this corresponds to list position), `game_record` is a boolean representing whether the move was 'official' or is an alternate move used in study, and `prior_move` is a reference to another `move` row allowing for the construction of a tree model for the game (see [Expanding this representation](#expanding-this-representation), below.)
|
||||
|
||||
There is a backend service that processes this list of moves into a current board state ([Modeling Game State](#modeling-game-state).) On the frontend, users have the option of expanding a menu to view the move order in the format below.
|
||||
|
||||
![Game Record: Black and white 19x19 grid with moves represented as circles filled in with stone color and marked with move number. Below the grid is an overflow area for moves made at previously played points in the format /[new move number and color at old move number and color/]](public/game-record.png)
|
||||
|
||||
This is a customary representation of game records printed in Go literature. A frontend service processes the list of moves and plots each move onto a `<canvas>` element drawn to resemble the grid lines on a board, with moves that are placed at prior points plotted on an additional `<canvas>` element below.
|
||||
|
||||
#### Expanding this representation
|
||||
This representation will be expanded when support for alternate game paths is added. Alternate game paths will allow users to study completed games by playing out the consequences of moves not in the completed game. This feature will require a tree structure for the game record where moves on the main line are referred with a `main` property on each move node and alternate moves with any number of alternate references.
|
||||
|
||||
### Caching multiple in-progress games
|
||||
![Image of Game module in context](public/game-module.png)
|
||||
|
||||
### Partitioning Game Rooms
|
||||
Finding a game starts with joining a game room.
|
||||
![Image of Home Screen with 'main' game room](public/home-screen.png)
|
||||
Watch an in progress game, join a game, or study a historic game.
|
||||
![Image of Room Screen with multiple games in various states](public/room-screen.png)
|
||||
|
||||
---
|
||||
## Setup
|
||||
### Local Repo
|
||||
```sh
|
||||
$ git clone https://github.com/sorrelbri/node-go.git
|
||||
```
|
||||
|
||||
### Install Deps
|
||||
```sh
|
||||
$ npm run bootstrap
|
||||
```
|
||||
Runs lerna `bootstrap` command installing dependencies for project, development and package dependencies
|
||||
|
||||
### Initialize Database
|
||||
#### Download PostgreSQL
|
||||
To verify PostgreSQL installation:
|
||||
```sh
|
||||
$ psql -V
|
||||
```
|
||||
Node Go API was built with version 11.4.
|
||||
[See documentation for Postgres download.](https://www.postgresql.org/download/)
|
||||
|
||||
#### Create Databases
|
||||
```sh
|
||||
$ psql
|
||||
# psql(11.4)
|
||||
```
|
||||
```sql
|
||||
CREATE DATABASE node-go;
|
||||
CREATE DATABASE node-go-test; # testing database
|
||||
```
|
||||
|
||||
### Configure Environment
|
||||
```sh
|
||||
$ touch packages/server/.env
|
||||
```
|
||||
|
||||
```
|
||||
# .env
|
||||
NODE_ENV=development
|
||||
PORT=# set development port for API
|
||||
REACT_ADDRESS=http://localhost:3000 # default
|
||||
PG_CONNECTION_STRING=postgresql://localhost:5432/node-go
|
||||
PG_CONNECTION_STRING_TEST=postgresql://localhost:5432/node-go-test
|
||||
JWT_SECRET=# generate a secret key for JWT signing algorithm
|
||||
TEST_SECRET=# same as above, for test environment
|
||||
SALT_ROUNDS=# set number of salt rounds for bcrypt hashing function
|
||||
DOMAIN=localhost
|
||||
USER_ONE_PASSWORD=# credentials for testing with
|
||||
USER_ONE_EMAIL=# same as above
|
||||
```
|
||||
|
||||
### Smoke test
|
||||
```sh
|
||||
$ lerna run test
|
||||
```
|
||||
|
||||
### Run Database Migrations
|
||||
```sh
|
||||
$ cd packages/server; npm run migrate; npm run seed
|
||||
```
|
||||
|
||||
### Running in development
|
||||
```sh
|
||||
$ cd packages/server
|
||||
$ npm start # or if you have nodemon
|
||||
$ nodemon
|
||||
```
|
||||
```sh
|
||||
$ cd packages/play-node-go
|
||||
$ npm start
|
||||
```
|
||||
|
||||
---
|
||||
## Known Bugs
|
||||
- game end logic not implemented on front end yet
|
||||
- no authorization for game moves
|
||||
- websocket connections may remain open, pooling prevents runaway leaks, but tests may hang
|
||||
|
||||
---
|
||||
## Roadmap
|
||||
### 6/20
|
||||
1. Frontend implementation of game end logic
|
||||
2. Auth for games
|
||||
3. Game request creation
|
||||
### 7/20
|
||||
1. Generate game records
|
||||
2. Implement chat
|
||||
3. Implement study mode
|
||||
|
||||
---
|
||||
## Features
|
||||
- [x] Realtime play
|
||||
- [x] Account authentication
|
||||
- [ ] Chat
|
||||
- [ ] Study mode
|
||||
- [ ] Realtime communications
|
||||
- [ ] Multiple game settings
|
||||
- [ ] Customizable board size
|
||||
- [ ] Download games in .sgf format
|
||||
|
||||
---
|
||||
|
||||
## Built with
|
||||
- [Express](https://expressjs.com)
|
||||
- [React](https://reactjs.org)
|
||||
- [PostgreSQL](https://postgresql.org)
|
||||
- [Socket.io](https://socket.io)
|
||||
- [Sass](https://sass-lang.com)
|
||||
### Management & Deployment
|
||||
- Lerna
|
||||
- CircleCI
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "independent"
|
||||
}
|
8014
package-lock.json
generated
8014
package-lock.json
generated
File diff suppressed because it is too large
Load diff
18
package.json
18
package.json
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "root",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "lerna run test",
|
||||
"bootstrap": "lerna bootstrap --hoist"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-flow": "^7.8.3",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.4.0",
|
||||
"chai": "^4.2.0",
|
||||
"chai-http": "^4.3.0",
|
||||
"lerna": "^3.20.2",
|
||||
"mocha": "^7.0.0",
|
||||
"react-test-renderer": "^16.12.0"
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
@mixin fullspan {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@mixin flexAround($direction) {
|
||||
display: flex;
|
||||
flex-direction: $direction;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
@mixin gameViewLabel {
|
||||
color: rgb(255,240,230);
|
||||
background-color: rgba(0,0,0,0.7);
|
||||
padding: 0.25em;
|
||||
}
|
||||
|
||||
@function place-below($grid-column, $grid-row) {
|
||||
@return $grid-row + 1 + '/' + $grid-column + 2 + '/ span 1 / span 1';
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
$dev-colors: (
|
||||
"a": #34dc90,
|
||||
"b": #9034dc,
|
||||
"c": #dc9034,
|
||||
"d": #dc34dc,
|
||||
"e": #34dcdc,
|
||||
"f": #dcdc34
|
||||
);
|
||||
|
||||
/* Responsive Design */
|
||||
$break-points: (
|
||||
"500": "only screen and (min-width: 500px)",
|
||||
"570": "only screen and (min-width: 570px)",
|
||||
"590": "only screen and (min-width: 590px)",
|
||||
"700": "only screen and (min-width: 700px)",
|
||||
"900": "only screen and (min-width: 900px)"
|
||||
);
|
||||
|
||||
$colors: (
|
||||
"error": #aa3333,
|
||||
"nav_bar": #6f3e68,
|
||||
"nav_link": #dae1b7,
|
||||
"sidebar": #3c013f,
|
||||
"sidebar_link": #f2ce3d,
|
||||
"main": #95acae,
|
||||
"home": #444444
|
||||
);
|
||||
|
||||
$backgrounds: (
|
||||
"game_room": radial-gradient(farthest-corner at 55% 40%, rgb(189, 131, 100) 0%, rgb(175, 113, 80) 65%, rgb(150, 90, 65) 90%, rgb(125, 65, 40) 100%),
|
||||
);
|
||||
|
||||
/* Game Room Components */
|
||||
$small-room: (
|
||||
"roof": linear-gradient(rgb(69, 36, 19), rgb(31, 22, 18)),
|
||||
"body": rgb(174, 169, 120),
|
||||
"door": radial-gradient(15vh 20vh at top left, #662413,#992413 15%, #cc3423),
|
||||
"door-handle": radial-gradient(circle at 40% 30%, rgb(247, 235, 183), rgb(213, 222, 41) 30%, rgb(121, 108, 7)),
|
||||
"window-x": linear-gradient(rgba(67, 149, 159, 0.4), rgba(196, 249, 255, 0.4) 50%, rgba(67, 149, 159, 0.4) 50%, rgba(196, 249, 255, 0.4)),
|
||||
"window-y": linear-gradient(to right, rgba(67, 149, 159, 0.5), rgba(196, 249, 255, 0.5) 50%, rgba(67, 149, 159, 0.5) 50%, rgba(196, 249, 255, 0.5)),
|
||||
"frame": rgb(69, 36, 19),
|
||||
"sign": rgb(188, 127, 95)
|
||||
);
|
|
@ -1,115 +0,0 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import './Game.scss';
|
||||
|
||||
const GameButton = (props) => {
|
||||
const { game, user } = props;
|
||||
|
||||
const setGameDisplayData = () => {
|
||||
const gameData = {
|
||||
playerBlack: game.playerBlack,
|
||||
playerBlackRank: game.playerBlackRank,
|
||||
gameId: game.id,
|
||||
}
|
||||
if (game.open) {
|
||||
gameData.gameLinkText = 'Request to Join Game';
|
||||
gameData.playerWhite = '';
|
||||
gameData.playerWhiteRank = 'could be you!';
|
||||
}
|
||||
if (!game.open) {
|
||||
gameData.playerWhite = game.playerWhite;
|
||||
gameData.playerWhiteRank = game.playerWhiteRank;
|
||||
gameData.gameLinkText = game.winType ? 'Study Game'
|
||||
: user ? 'Rejoin Game' : 'Watch Game'
|
||||
}
|
||||
return gameData;
|
||||
}
|
||||
|
||||
// TODO add to open game link
|
||||
// const requestJoinGame = () => {
|
||||
// console.log(`request to Join Game ${game.id}!`)
|
||||
// const requestAction = {
|
||||
// type: 'GAMES',
|
||||
// message: 'JOIN_REQUEST',
|
||||
// body: {id: game.id}
|
||||
// }
|
||||
// dispatch(requestAction);
|
||||
// }
|
||||
|
||||
const renderGame = () => {
|
||||
const {
|
||||
gameLinkText,
|
||||
playerBlack,
|
||||
playerBlackRank,
|
||||
gameId,
|
||||
playerWhite,
|
||||
playerWhiteRank
|
||||
} = setGameDisplayData();
|
||||
return (
|
||||
<>
|
||||
<div className="GameButton__seat GameButton__seat--black">
|
||||
|
||||
</div>
|
||||
|
||||
<div className="GameButton__table">
|
||||
<div className="GameButton__table__meta">
|
||||
<div
|
||||
className="GameButton__player-data GameButton__player-data--black"
|
||||
>
|
||||
<span
|
||||
className="GameButton__player-data__name GameButton__player-data__name--black"
|
||||
>{playerBlack}</span>
|
||||
<span
|
||||
className="GameButton__player-data__rank GameButton__player-data__rank"
|
||||
>{playerBlackRank}</span>
|
||||
</div>
|
||||
|
||||
<Link
|
||||
className="GameButton__link"
|
||||
to={`/games/${gameId}`}
|
||||
>{gameLinkText}</Link>
|
||||
|
||||
<div
|
||||
className={`GameButton__player-data GameButton__player-data--white ${
|
||||
playerWhite ? '' : 'GameButton__player-data--invisible'
|
||||
}`
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="GameButton__player-data__name GameButton__player-data__name--white"
|
||||
>{playerWhite}</span>
|
||||
<span
|
||||
className="GameButton__player-data__rank GameButton__player-data__rank--white"
|
||||
>{playerWhiteRank}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="GameButton__table__image">
|
||||
<div className="table__player-area table__player-area--black">
|
||||
<div className="table__player-bowl table__player-bowl--black"></div>
|
||||
</div>
|
||||
<div className="table__game-board">
|
||||
<div className="table__game-board--grid"></div>
|
||||
</div>
|
||||
<div className="table__player-area table__player-area--white">
|
||||
<div className="table__player-bowl table__player-bowl--white"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="GameButton__seat GameButton__seat--white">
|
||||
|
||||
</div>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="GameButton" data-testid="GameButton">
|
||||
{renderGame()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default GameButton;
|
|
@ -1,139 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/mixins';
|
||||
|
||||
div.GameButton {
|
||||
align-items: stretch;
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
height: 20vh;
|
||||
justify-content: space-around;
|
||||
margin: 1vw;
|
||||
width: 20vh;
|
||||
}
|
||||
|
||||
div.GameButton__seat {
|
||||
background: linear-gradient(190deg, rgb(232, 78, 78), rgb(172, 18, 18) 40%, rgb(100, 0, 0));
|
||||
height: 10%;
|
||||
margin: 0 auto;
|
||||
width: 50%;
|
||||
|
||||
&.GameButton__seat--black {
|
||||
border: rgba(83, 53, 35, 0.81);
|
||||
border-radius: 5vw 5vw 0 0;
|
||||
}
|
||||
|
||||
&.GameButton__seat--white {
|
||||
border: transparent;
|
||||
border-radius: 0 0 5vw 5vw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
div.GameButton__table {
|
||||
box-shadow: -2vmin 4vmin 2vmin rgba(83, 53, 35, 0.81);
|
||||
height: 80%;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.GameButton__table__meta {
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
height: 100%;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
div.GameButton__table__meta * {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
div.GameButton__table__image {
|
||||
align-items: center;
|
||||
background: radial-gradient(
|
||||
farthest-corner at 55% 40%,
|
||||
rgb(150, 200, 220) 0%, rgb(97, 166, 194) 65%, rgb(70,100,120) 100%
|
||||
);
|
||||
border-top: 0.1vw solid rgb(150, 200, 220);
|
||||
border-right: 0.05vw solid rgb(97, 166, 194);
|
||||
border-radius: 0.3vw;
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
height: 100%;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
top: -100%;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
|
||||
div.table__game-board {
|
||||
align-items: center;
|
||||
background: radial-gradient(
|
||||
farthest-corner at 55% 40%,
|
||||
rgb(244, 230, 120) 0%, rgb(234, 178, 78) 65%, rgb(200, 160, 90) 90%, rgb(200, 140, 90) 100%
|
||||
);
|
||||
box-shadow: -0.5vh 1vh 2vh rgba(30,30,30, 0.7);
|
||||
height: 60%;
|
||||
justify-content: center;
|
||||
width: 60%;
|
||||
display: flex;
|
||||
|
||||
div.table__game-board--grid {
|
||||
background:
|
||||
repeating-linear-gradient(0deg, #000 0%, transparent 0.75%, transparent 4.25%, #000 5%),
|
||||
repeating-linear-gradient(90deg, #000 0%, transparent 0.75%, transparent 4.25%, #000 5%);
|
||||
height: 94%;
|
||||
width: 94%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.table__player-area {
|
||||
height: 20%;
|
||||
width: 60%;
|
||||
|
||||
div.table__player-bowl {
|
||||
background: radial-gradient(
|
||||
farthest-corner at 48% 54%,
|
||||
rgb(30, 5, 0) 0%, rgb(30, 5, 0) 2%, rgb(30, 5, 0) 32%, rgb(0,0,0)35%, rgb(116,48,17) 48%,
|
||||
rgb(140, 60, 40) 52%, rgb(100, 40, 5) 55%, rgb(116, 48, 17) 58%, rgb(140,60,40) 65%,
|
||||
rgb(100, 40, 5) 80%, rgb(80, 20, 0) 90%
|
||||
);
|
||||
border-radius: 50%;
|
||||
box-shadow: -0.5vh 1vh 2vh rgba(30,30,30, 0.7);
|
||||
height: 100%;
|
||||
|
||||
&--white {
|
||||
margin: auto auto auto 75%;
|
||||
}
|
||||
|
||||
&--black {
|
||||
margin: auto 75% auto auto;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
div.GameButton__player-data {
|
||||
@include gameViewLabel;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
max-width: 100%;
|
||||
|
||||
&.GameButton__player-data--invisible {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
&.GameButton__player-data--white {
|
||||
margin: 0 5vw 1vw 0.5vw;
|
||||
}
|
||||
|
||||
&.GameButton__player-data--black {
|
||||
margin: 1vw 0.5vw 0 5vw;
|
||||
}
|
||||
}
|
||||
|
||||
a.GameButton__link {
|
||||
@include gameViewLabel;
|
||||
margin: 0 auto;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
import React from "react";
|
||||
import authServices from "../../../services/authServices";
|
||||
|
||||
const Guest = ({ dispatch }) => {
|
||||
const handleClick = async (e) => {
|
||||
e.preventDefault();
|
||||
// dispatch to guest endpoint
|
||||
const guestResponse = await authServices.guestService();
|
||||
|
||||
if (guestResponse.errors) {
|
||||
const authError = guestResponse.errors[0].auth;
|
||||
return dispatch({
|
||||
type: "ERR",
|
||||
message: "AUTH_ERROR",
|
||||
body: { authError },
|
||||
});
|
||||
}
|
||||
|
||||
return dispatch({
|
||||
type: "AUTH",
|
||||
message: "GUEST",
|
||||
body: guestResponse,
|
||||
});
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<button className="nav__section__button" onClick={handleClick}>
|
||||
Continue As Guest
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Guest;
|
|
@ -1,18 +0,0 @@
|
|||
import React from 'react';
|
||||
import './Library.scss';
|
||||
|
||||
const LibraryButton = () => {
|
||||
return (
|
||||
<div
|
||||
className="nav__section"
|
||||
>
|
||||
<p
|
||||
className="nav__section__label"
|
||||
>
|
||||
Library
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LibraryButton;
|
|
@ -1,18 +0,0 @@
|
|||
import React from 'react';
|
||||
import './NewGame.scss';
|
||||
|
||||
const NewGameButton = () => {
|
||||
return (
|
||||
<div
|
||||
className="nav__section"
|
||||
>
|
||||
<p
|
||||
className="nav__section__label"
|
||||
>
|
||||
New Game
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default NewGameButton;
|
|
@ -1,18 +0,0 @@
|
|||
import React from 'react';
|
||||
import './NewRoom.scss';
|
||||
|
||||
const NewRoomButton = () => {
|
||||
return (
|
||||
<div
|
||||
className="nav__section"
|
||||
>
|
||||
<p
|
||||
className="nav__section__label"
|
||||
>
|
||||
New Room
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default NewRoomButton;
|
|
@ -1,71 +0,0 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import RoomDetail from '../../Display/RoomDetail/RoomDetail';
|
||||
import './Room.scss';
|
||||
|
||||
const RoomButton = ({room, roomDetail, showRoomDetail}) => {
|
||||
const smallRoom = (
|
||||
<div className="small-room">
|
||||
<div className="small-room__roof">
|
||||
<div className="small-room__roof-top small-room__roof-top--left"></div>
|
||||
<div className="small-room__roof--left"></div>
|
||||
<div className="small-room__roof-top small-room__roof-top--right"></div>
|
||||
<div className="small-room__roof--right"></div>
|
||||
</div>
|
||||
<div className="small-room__body">
|
||||
<div className="small-room__trim small-room__trim--left"></div>
|
||||
<div className="small-room__sign">
|
||||
<div className="small-room__sign__stone small-room__sign__stone--black"></div>
|
||||
<div className="small-room__sign__stone small-room__sign__stone--white"></div>
|
||||
<div className="small-room__sign__stone small-room__sign__stone--white"></div>
|
||||
<div className="small-room__sign__stone small-room__sign__stone--black"></div>
|
||||
</div>
|
||||
<div className="small-room__window small-room__window--left">
|
||||
<div className="small-room__window-frame small-room__window-frame--top"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--left"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--middle"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--center"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--right"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--bottom"></div>
|
||||
</div>
|
||||
<div className="small-room__door">
|
||||
<div className="small-room__door-frame small-room__door-frame--top"></div>
|
||||
<div className="small-room__door-frame small-room__door-frame--left"></div>
|
||||
<div className="small-room__door-handle"></div>
|
||||
<div className="small-room__door-frame small-room__door-frame--right"></div>
|
||||
</div>
|
||||
<div className="small-room__window small-room__window--right">
|
||||
<div className="small-room__window-frame small-room__window-frame--top"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--left"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--middle"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--center"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--right"></div>
|
||||
<div className="small-room__window-frame small-room__window-frame--bottom"></div>
|
||||
</div>
|
||||
<div className="small-room__trim small-room__trim--bottom-left"></div>
|
||||
<div className="small-room__trim small-room__trim--right"></div>
|
||||
<div className="small-room__trim small-room__trim--bottom-right"></div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="RoomButton" data-testid="RoomButton">
|
||||
<h4 className="RoomButton__room-link RoomButton__room-link--action">
|
||||
<Link to={`/rooms/${room.id}`}>Join {room.name}</Link>
|
||||
</h4>
|
||||
<h4
|
||||
className="RoomButton__room-link RoomButton__room-link--info --link"
|
||||
onClick={e => showRoomDetail(room.id)}
|
||||
>
|
||||
?
|
||||
</h4>
|
||||
{smallRoom}
|
||||
</div>
|
||||
{roomDetail ? <RoomDetail room={room} /> : <></>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default RoomButton;
|
|
@ -1,227 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/mixins';
|
||||
@import '../../../../public/stylesheets/partials/variables';
|
||||
|
||||
div.RoomButton {
|
||||
display: grid;
|
||||
grid-template-columns: [left] 1fr [right];
|
||||
grid-template-rows: [top] 1fr [middle] 4fr [bottom];
|
||||
height: 20vh;
|
||||
padding: 1vw;
|
||||
width: 20vh;
|
||||
|
||||
.RoomButton__room-link {
|
||||
@include gameViewLabel;
|
||||
align-self: self-end;
|
||||
grid-area: top/left/middle/right;
|
||||
max-width: fit-content;
|
||||
z-index: 1;
|
||||
|
||||
&--info {
|
||||
justify-self: end;
|
||||
}
|
||||
}
|
||||
|
||||
div.small-room {
|
||||
display: grid;
|
||||
grid-area: top/left/bottom/right;
|
||||
grid-template-rows: [sky-start] 4vh [roof-start] 5vh [body-start] 1fr [body-end];
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
.small-room__roof {
|
||||
display: grid;
|
||||
grid-row: roof-start / body-start;
|
||||
grid-template-columns: [left] 10vh [middle] 10vh [right];
|
||||
grid-template-rows: 1fr;
|
||||
height: 100%;
|
||||
max-width: 20vh;
|
||||
|
||||
.small-room__roof-top {
|
||||
background: map-get($small-room, "roof");
|
||||
box-shadow: 0 0.35vh 0.75vh map-get($colors, "home");
|
||||
grid-row: 1 / 2;
|
||||
height: 0.7vh;
|
||||
position: relative;
|
||||
top: 3vh;
|
||||
width: 12vh;
|
||||
|
||||
&--left {
|
||||
grid-column: left / middle;
|
||||
left: -1.2vh;
|
||||
transform: rotate(-26deg);
|
||||
}
|
||||
|
||||
&--right {
|
||||
grid-column: middle / right;
|
||||
left: -0.8vh;
|
||||
transform: rotate(26deg);
|
||||
}
|
||||
}
|
||||
|
||||
&--left {
|
||||
border-right: map-get($small-room, "body") solid 10vh;
|
||||
border-top: map-get($colors, "home") solid 5vh;
|
||||
grid-column: left / middle;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
&--right {
|
||||
border-left: map-get($small-room, "body") solid 10vh;
|
||||
border-top: map-get($colors, "home") solid 5vh;
|
||||
grid-column: middle / right;
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.small-room__body {
|
||||
background-color: map-get($small-room, "body");
|
||||
display: grid;
|
||||
grid-row: body-start / body-end;
|
||||
grid-template-areas:
|
||||
"trim-left gap-left top-left gap-mid-left top-mid gap-mid-right top-right gap-right trim-right"
|
||||
"trim-left gap-left top-left gap-mid-left top-mid gap-mid-right top-right gap-right trim-right"
|
||||
"trim-left gap-left window--left gap-mid-left door gap-mid-right window--right gap-right trim-right"
|
||||
"trim-left trim--bottom-left trim--bottom-left trim--bottom-left door trim--bottom-right trim--bottom-right trim--bottom-right trim-right";
|
||||
grid-template-columns: 0.5vh 1vh 2fr 1vh 3fr 1vh 2fr 1vh 0.5vh;
|
||||
grid-template-rows: 1fr 1vh 5fr 0.75vh;
|
||||
justify-self: center;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.small-room__trim {
|
||||
background-color: map-get($small-room, "frame");
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
&--left {
|
||||
grid-area: trim-left;
|
||||
justify-self: start;
|
||||
}
|
||||
|
||||
&--right {
|
||||
grid-area: trim-right;
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
&--bottom-left {
|
||||
grid-area: trim--bottom-left;
|
||||
}
|
||||
|
||||
&--bottom-right {
|
||||
grid-area: trim--bottom-right;
|
||||
}
|
||||
}
|
||||
|
||||
.small-room__sign {
|
||||
background-color: map-get($small-room, "sign");
|
||||
display: grid;
|
||||
gap: 0.1vh;
|
||||
grid-area: top-mid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-rows: 1fr 1fr;
|
||||
height: 2vh;
|
||||
justify-self: center;
|
||||
padding: 0.1vh;
|
||||
width: 2vh;
|
||||
|
||||
.small-room__sign__stone {
|
||||
border-radius: 100%;
|
||||
|
||||
&--white {
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
&--black {
|
||||
background-color: #000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.small-room__window {
|
||||
align-self: center;
|
||||
background: map-get($small-room, "window-x"), map-get($small-room, "window-y");
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 5fr 1fr 5fr 1fr;
|
||||
grid-template-rows: 1fr 5fr 1fr 5fr 1fr;
|
||||
height: 60%;
|
||||
width: 100%;
|
||||
|
||||
&--left {
|
||||
grid-area: window--left;
|
||||
}
|
||||
&--right {
|
||||
grid-area: window--right;
|
||||
}
|
||||
|
||||
.small-room__window-frame {
|
||||
background-color: map-get($small-room, "frame");
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
&--top {
|
||||
grid-area: 1/1/2/6;
|
||||
}
|
||||
|
||||
&--center {
|
||||
grid-area: 3/1/4/6;
|
||||
}
|
||||
|
||||
&--bottom {
|
||||
grid-area: 5/1/6/6;
|
||||
}
|
||||
|
||||
&--left {
|
||||
grid-area: 1/1/6/2;
|
||||
}
|
||||
|
||||
&--middle {
|
||||
grid-area: 1/3/6/4;
|
||||
}
|
||||
|
||||
&--right {
|
||||
grid-area: 1/5/6/6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.small-room__door {
|
||||
grid-area: door;
|
||||
background: map-get($small-room, "door");
|
||||
display: grid;
|
||||
grid-template-columns: 0.5vh 1fr 0.5vh;
|
||||
grid-template-rows: 0.5vh 1fr;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
.small-room__door-handle {
|
||||
align-self: center;
|
||||
background: map-get($small-room, "door-handle");
|
||||
border-radius: 50%;
|
||||
box-shadow: 0.1vh 0.25vh 0.4vh rgba(30, 30, 30, 0.7);
|
||||
grid-area: 2/2/3/3;
|
||||
height: 0.75vh;
|
||||
justify-self: end;
|
||||
margin: 0.5vh 0.5vh 0 0;
|
||||
width: 0.75vh;
|
||||
}
|
||||
|
||||
.small-room__door-frame {
|
||||
background-color: map-get($small-room, "frame");
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
&--top {
|
||||
grid-area: 1/1/2/3;
|
||||
}
|
||||
|
||||
&--left {
|
||||
grid-area: 1/1/3/2;
|
||||
}
|
||||
|
||||
&--left {
|
||||
grid-area: 1/3/3/4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import React from 'react';
|
||||
import './RoomArchive.scss';
|
||||
|
||||
const RoomArchiveButton = () => {
|
||||
return (
|
||||
<div
|
||||
className="nav__section"
|
||||
>
|
||||
<p
|
||||
className="nav__section__label"
|
||||
>
|
||||
Room Archive
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default RoomArchiveButton;
|
|
@ -1,80 +0,0 @@
|
|||
import React from 'react';
|
||||
import './Loading.scss';
|
||||
|
||||
const Loading = () => {
|
||||
return (
|
||||
<div
|
||||
className="Loading"
|
||||
>
|
||||
<div
|
||||
className="point"
|
||||
id="a-1"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="a-2"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="a-3"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="a-4"
|
||||
></div>
|
||||
|
||||
<div
|
||||
className="point"
|
||||
id="b-1"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="b-2"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="b-3"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="b-4"
|
||||
></div>
|
||||
|
||||
<div
|
||||
className="point"
|
||||
id="c-1"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="c-2"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="c-3"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="c-4"
|
||||
></div>
|
||||
|
||||
<div
|
||||
className="point"
|
||||
id="d-1"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="d-2"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="d-3"
|
||||
></div>
|
||||
<div
|
||||
className="point"
|
||||
id="d-4"
|
||||
></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Loading;
|
|
@ -1,186 +0,0 @@
|
|||
div.Loading {
|
||||
background-color: rgb(234, 178, 78);
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
height: 6vw;
|
||||
left: 47vw;
|
||||
position: absolute;
|
||||
top: 45vh;
|
||||
width: 6vw;
|
||||
|
||||
div.point {
|
||||
height: 1vw;
|
||||
width: 1vw;
|
||||
border-radius: 50%;
|
||||
padding: 0.25vw;
|
||||
}
|
||||
|
||||
#a-1 {
|
||||
animation-name: white-stone--corner;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -2.75s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#a-2 {
|
||||
background-color: black;
|
||||
animation-name: black-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -1s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#a-3 {
|
||||
background-color: white;
|
||||
animation-name: white-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -2.25s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#a-4 {
|
||||
animation-name: black-stone--corner;
|
||||
animation-duration: 4s;
|
||||
animation-delay: 0s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
|
||||
#b-1 {
|
||||
background-color: black;
|
||||
animation-name: black-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -1.5s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#b-2 {
|
||||
animation-name: white-stone--center;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -3.25s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#b-3 {
|
||||
background-color: black;
|
||||
animation-name: black-stone--center;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -.5s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#b-4 {
|
||||
background-color: white;
|
||||
animation-name: white-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -1.75s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
|
||||
#c-1 {
|
||||
animation-name: white-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -3.75s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#c-2 {
|
||||
background-color: black;
|
||||
animation-name: black-stone--center;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -2.5s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#c-3 {
|
||||
background-color: white;
|
||||
animation-name: white-stone--center;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -1.25s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#c-4 {
|
||||
animation-name: black-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -3.5s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
|
||||
#d-1 {
|
||||
background-color: black;
|
||||
animation-name: black-stone--corner;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -2s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#d-2 {
|
||||
background-color: white;
|
||||
animation-name: white-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -.25s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#d-3 {
|
||||
animation-name: black-stone;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -3s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
#d-4 {
|
||||
background-color: white;
|
||||
animation-name: white-stone--corner;
|
||||
animation-duration: 4s;
|
||||
animation-delay: -.75s;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@keyframes black-stone {
|
||||
0% {background: black;}
|
||||
67.5% {background: black;}
|
||||
70% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);}
|
||||
99.5% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);}
|
||||
}
|
||||
|
||||
@keyframes white-stone {
|
||||
0% {background: white;}
|
||||
60% {background: white;}
|
||||
62.5% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);}
|
||||
92.5% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);}
|
||||
95% {background: white;}
|
||||
}
|
||||
|
||||
@keyframes black-stone--corner {
|
||||
0% {background: black;}
|
||||
52.5% {background: black;};
|
||||
55% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
99% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
}
|
||||
|
||||
@keyframes white-stone--corner {
|
||||
0% {background: white;}
|
||||
47.5% {background: white;};
|
||||
50% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
95% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
97.5% {background: white;}
|
||||
}
|
||||
|
||||
@keyframes black-stone--center {
|
||||
0% {background: black;}
|
||||
75.5% {background: black;};
|
||||
77.5% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
99% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
}
|
||||
|
||||
@keyframes white-stone--center {
|
||||
0% {background: white;}
|
||||
72.5% {background: white;};
|
||||
75% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
97.5% {background: repeating-linear-gradient(0deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%),
|
||||
repeating-linear-gradient(90deg, transparent 0%, transparent 45%, black 50%, transparent 55%, transparent 100%);};
|
||||
100% {background: white;}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
import React from 'react';
|
||||
import './RoomDetail.scss';
|
||||
|
||||
const RoomDetail = ({room}) => {
|
||||
return (
|
||||
<div className="RoomDetail">
|
||||
<div className="RoomDetail__arrow"></div>
|
||||
<div className="RoomDetail__data">
|
||||
<div className="RoomDetail__heading">
|
||||
<h3 className="RoomDetail__room-name">{room.name}</h3>
|
||||
<div className="RoomDetail__room-lang"></div>
|
||||
<p className="RoomDetail__room-description">{room.description}</p>
|
||||
</div>
|
||||
<div className="RoomDetail__current">
|
||||
<h4 className="RoomDetail__current-header">Current:</h4>
|
||||
<p className="RoomDetail__current-players"></p>
|
||||
<p className="RoomDetail__current-games"></p>
|
||||
<p className="RoomDetail__current-rank"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default RoomDetail;
|
|
@ -1,32 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/mixins';
|
||||
@import '../../../../public/stylesheets/partials/variables';
|
||||
|
||||
div.RoomDetail {
|
||||
display: grid;
|
||||
grid-template-columns: [left] 1fr [right];
|
||||
grid-template-rows: [top] 1fr [middle] 9fr [bottom];
|
||||
height: 20vh;
|
||||
padding: 1vw;
|
||||
width: 20vh;
|
||||
|
||||
div.RoomDetail__arrow {
|
||||
border-top: map-get($colors, 'home') solid 2vh;
|
||||
border-left: white solid 1.5vh;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
div.RoomDetail__data {
|
||||
background-color: white;
|
||||
height: 90%;
|
||||
width: 100%;
|
||||
padding: 1vh;
|
||||
display: grid;
|
||||
grid-template-rows: 2fr 3fr;
|
||||
|
||||
.RoomDetail__heading {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
import React, { useState } from "react";
|
||||
|
||||
import Login from "../Login/Login";
|
||||
import Signup from "../Signup/Signup";
|
||||
import Guest from "../../Button/Guest/Guest";
|
||||
|
||||
const Auth = (props) => {
|
||||
const [showForm, setShowForm] = useState("login");
|
||||
const { state, dispatch } = props;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="nav__section nav__section--auth"
|
||||
onClick={() => {
|
||||
setShowForm("login");
|
||||
}}
|
||||
>
|
||||
<p className="nav__section__label">Login</p>
|
||||
|
||||
{showForm === "login" ? (
|
||||
<Login dispatch={dispatch} state={state} />
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="nav__section nav__section--auth"
|
||||
onClick={() => {
|
||||
setShowForm("signup");
|
||||
}}
|
||||
>
|
||||
<p className="nav__section__label">Signup</p>
|
||||
|
||||
{showForm === "signup" ? (
|
||||
<Signup dispatch={dispatch} state={state} />
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
<div className="nav__section nav__section--auth">
|
||||
<Guest dispatch={dispatch} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Auth;
|
|
@ -1,18 +0,0 @@
|
|||
import React from 'react';
|
||||
import './FindGame.scss';
|
||||
|
||||
const FindGameForm = () => {
|
||||
return (
|
||||
<div
|
||||
className="nav__section"
|
||||
>
|
||||
<p
|
||||
className="nav__section__label"
|
||||
>
|
||||
Find Game
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FindGameForm;
|
|
@ -1,18 +0,0 @@
|
|||
import React from 'react';
|
||||
import './FindRoom.scss';
|
||||
|
||||
const FindRoomForm = () => {
|
||||
return (
|
||||
<div
|
||||
className="nav__section"
|
||||
>
|
||||
<p
|
||||
className="nav__section__label"
|
||||
>
|
||||
Find Room
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FindRoomForm;
|
|
@ -1,74 +0,0 @@
|
|||
import React from "react";
|
||||
import "./Board.scss";
|
||||
import Point from "../Point/Point";
|
||||
|
||||
const Board = (props) => {
|
||||
const { game, user, dispatch, board, meta } = props;
|
||||
const sizeFlag = `Game__board--size-${game.boardSize}`;
|
||||
const hoshiPoints = {
|
||||
9: { "3-3": true, "7-7": true, "3-7": true, "7-3": true },
|
||||
13: {
|
||||
"7-7": true,
|
||||
"10-7": true,
|
||||
"7-4": true,
|
||||
"7-10": true,
|
||||
"4-7": true,
|
||||
"4-4": true,
|
||||
"10-10": true,
|
||||
"4-10": true,
|
||||
"10-4": true,
|
||||
},
|
||||
19: {
|
||||
"10-10": true,
|
||||
"16-10": true,
|
||||
"10-4": true,
|
||||
"10-16": true,
|
||||
"4-10": true,
|
||||
"4-4": true,
|
||||
"16-16": true,
|
||||
"4-16": true,
|
||||
"16-4": true,
|
||||
},
|
||||
};
|
||||
|
||||
const isHoshi = (posX, posY) =>
|
||||
hoshiPoints[game.boardSize][`${posX}-${posY}`];
|
||||
|
||||
const renderPoints = (boardSize) => {
|
||||
let i = 0,
|
||||
boardPoints = [];
|
||||
while (i < boardSize * boardSize) {
|
||||
const posX = Math.floor(i / boardSize) + 1;
|
||||
const posY = (i % boardSize) + 1;
|
||||
const pointData = board[`${posX}-${posY}`];
|
||||
const dotData =
|
||||
meta && meta.turn === 0 && !meta.winner && meta.territory
|
||||
? meta.territory[`${posX}-${posY}`]
|
||||
: game.turn || meta?.turn;
|
||||
boardPoints.push(
|
||||
<Point
|
||||
key={`${posX}-${posY}`}
|
||||
posX={posX}
|
||||
posY={posY}
|
||||
pointData={pointData}
|
||||
dotData={dotData}
|
||||
dispatch={dispatch}
|
||||
user={user}
|
||||
meta={meta}
|
||||
hoshi={isHoshi(posX, posY)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
i++;
|
||||
}
|
||||
return boardPoints;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`Game__board ${sizeFlag}`}>
|
||||
{game.id ? renderPoints(game.boardSize) : <></>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Board;
|
|
@ -1,61 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/mixins';
|
||||
@import '../../../../public/stylesheets/partials/variables';
|
||||
|
||||
div.Game__board {
|
||||
// @include fullspan;
|
||||
background: radial-gradient(farthest-corner at 55% 40%, rgb(244, 230, 120) 0%, rgb(234, 178, 78) 65%, rgb(200, 160, 90) 90%, rgb(200, 140, 90) 100%);
|
||||
background-size: cover;
|
||||
box-shadow: -2vmin 4vmin 3vmin rgba(145, 92, 23, 0.5);
|
||||
display: grid;
|
||||
// flex: 1;
|
||||
margin: 0 auto;
|
||||
z-index: 1;
|
||||
|
||||
&--size-9 {
|
||||
grid-template-columns: repeat(9, 1fr);
|
||||
grid-template-rows: repeat(9, 1fr);
|
||||
|
||||
div.board__point {
|
||||
width: 9vmin;
|
||||
height: 9vmin;
|
||||
|
||||
@media #{map-get($break-points, "570")} {
|
||||
height: 7.5vh;
|
||||
width: 7.5vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&--size-13 {
|
||||
grid-template-columns: repeat(13, 1fr);
|
||||
grid-template-rows: repeat(13, 1fr);
|
||||
|
||||
div.board__point {
|
||||
width: 7vmin;
|
||||
height: 7vmin;
|
||||
|
||||
@media #{map-get($break-points, "570")} {
|
||||
height: 5vh;
|
||||
width: 5vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&--size-19 {
|
||||
grid-template-columns: repeat(19, 1fr);
|
||||
grid-template-rows: repeat(19, 1fr);
|
||||
|
||||
div.board__point {
|
||||
width: 5vmin;
|
||||
height: 5vmin;
|
||||
|
||||
@media #{map-get($break-points, "590")} {
|
||||
height: 2.6vw;
|
||||
width: 2.6vw;
|
||||
max-width: 3.5vh;
|
||||
max-height: 3.5vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
import React from 'react';
|
||||
import './GameTree.scss';
|
||||
|
||||
const GameTree = () => {
|
||||
return (
|
||||
<div className="GameTree">
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default GameTree;
|
|
@ -1,15 +0,0 @@
|
|||
import React from "react";
|
||||
import "./Kifu.scss";
|
||||
|
||||
const Kifu = ({ clickKifu }) => {
|
||||
return (
|
||||
<div className="Kifu">
|
||||
<p className="Kifu__show-menu" onClick={clickKifu}>
|
||||
Show Menu?
|
||||
</p>
|
||||
<div className="Kifu__board"></div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Kifu;
|
|
@ -1,31 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/mixins';
|
||||
|
||||
div.Kifu {
|
||||
order: 0;
|
||||
height: 10vh;
|
||||
width: 8vh;
|
||||
background-color: #FFF;
|
||||
transform: rotate(-20deg);
|
||||
|
||||
p.Kifu__show-menu {
|
||||
display: none;
|
||||
margin: 3vh auto;
|
||||
position: absolute;
|
||||
transform: rotate(20deg);
|
||||
width: fit-content;
|
||||
}
|
||||
&:hover {
|
||||
p.Kifu__show-menu {
|
||||
@include gameViewLabel;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
div.Kifu__board {
|
||||
border: 0.25vh solid #444;
|
||||
width: 5vh;
|
||||
height: 5vh;
|
||||
margin: 1vh 2vh 2vh auto;
|
||||
}
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
import React, { useEffect, useRef } from "react";
|
||||
import "./Menu.scss";
|
||||
|
||||
const Menu = ({ showMenu, clickClose, ...props }) => {
|
||||
const { active, meta } = props.state; // active.game.boardSize, meta.gameRecord
|
||||
const boardSize = active.game.boardSize;
|
||||
const handleBackgroundClick = (e) => {
|
||||
if (e.target.className === "Game__Menu-container") clickClose();
|
||||
};
|
||||
const canvasRef = useRef();
|
||||
const overflowRef = useRef();
|
||||
const drawGameRecord = () => {
|
||||
return (
|
||||
<>
|
||||
<canvas ref={canvasRef} />
|
||||
<canvas ref={overflowRef} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const clickPrint = () => {
|
||||
const iframe = document.createElement("iframe");
|
||||
const body = document.getElementsByTagName("body")[0];
|
||||
const record = document.getElementById("record");
|
||||
body.appendChild(iframe);
|
||||
// move game record to iframe and print iframe
|
||||
iframe.contentDocument.body.appendChild(canvasRef.current);
|
||||
iframe.contentDocument.body.appendChild(overflowRef.current);
|
||||
iframe.contentWindow.print();
|
||||
// move game record back to menu and remove iframe
|
||||
record.appendChild(canvasRef.current);
|
||||
record.appendChild(overflowRef.current);
|
||||
body.removeChild(iframe);
|
||||
};
|
||||
|
||||
// draw canvases
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const ctx = canvas.getContext("2d");
|
||||
const scale = Math.min(window.innerWidth * 0.75, 500);
|
||||
canvas.height = scale;
|
||||
canvas.width = scale;
|
||||
const space = scale / boardSize;
|
||||
const offset = space / 2;
|
||||
for (let i = 0; i < boardSize; i++) {
|
||||
const start = i * space + offset;
|
||||
const end = scale - offset;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(start, offset);
|
||||
ctx.lineTo(start, end);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(offset, start);
|
||||
ctx.lineTo(end, start);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
}
|
||||
if (!meta?.gameRecord) return;
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
const { overflow } = meta.gameRecord.reduce(
|
||||
(dict, { player, pos }, index) => {
|
||||
const past = dict[`${pos.x}-${pos.y}`];
|
||||
if (past) {
|
||||
// overflow: [ { move:#, player:'color', subsequentMoves: [ { move: #, player: 'color' } ] } ]
|
||||
if (dict.overflow) {
|
||||
const indexOfPrior = dict.overflow.findIndex(
|
||||
({ move }) => move === past
|
||||
);
|
||||
if (indexOfPrior !== -1) {
|
||||
// if multiple past moves at this point exist
|
||||
dict.overflow[indexOfPrior].subsequentMoves.push({
|
||||
move: index + 1,
|
||||
player,
|
||||
});
|
||||
return dict;
|
||||
}
|
||||
// if a second move at this point has not yet been encountered
|
||||
// prior move will be black if no active handicap and move is odd or if active handicap and move is even
|
||||
const playerPrior =
|
||||
(active.handicap && !(past % 2)) || past % 2 ? "black" : "white";
|
||||
return {
|
||||
...dict,
|
||||
overflow: [
|
||||
...dict.overflow,
|
||||
{
|
||||
move: past,
|
||||
player: playerPrior,
|
||||
subsequentMoves: [{ move: index + 1, player }],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
// if no move has yet been encountered at a previously made move
|
||||
return {
|
||||
...dict,
|
||||
overflow: [
|
||||
{ move: past, subsequentMoves: [{ move: index + 1, player }] },
|
||||
],
|
||||
};
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
(pos.y - 1) * space + offset,
|
||||
(pos.x - 1) * space + offset,
|
||||
offset * 0.95,
|
||||
0,
|
||||
Math.PI * 2,
|
||||
true
|
||||
);
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = player === "white" ? "#fff" : "#000";
|
||||
ctx.fill();
|
||||
ctx.fillStyle = player === "white" ? "#000" : "#fff";
|
||||
|
||||
ctx.fillText(
|
||||
index + 1,
|
||||
(pos.y - 1) * space + offset,
|
||||
(pos.x - 1) * space + offset
|
||||
);
|
||||
return { ...dict, [`${pos.x}-${pos.y}`]: index + 1 };
|
||||
},
|
||||
{}
|
||||
);
|
||||
if (!overflow?.length) return;
|
||||
// Draw Overflow Moves (moves made at prior points)
|
||||
const canvas2 = overflowRef.current;
|
||||
const ctx2 = canvas2.getContext("2d");
|
||||
canvas2.width = scale;
|
||||
canvas2.height = space * overflow.length;
|
||||
ctx2.textAlign = "center";
|
||||
ctx2.textBaseline = "middle";
|
||||
overflow.forEach(({ move, subsequentMoves, player }, index) => {
|
||||
subsequentMoves.forEach(({ player, move }, subIndex) => {
|
||||
ctx2.beginPath();
|
||||
ctx2.arc(
|
||||
subIndex * space + offset,
|
||||
index * space + offset,
|
||||
offset * 0.95,
|
||||
0,
|
||||
Math.PI * 2,
|
||||
true
|
||||
);
|
||||
ctx2.stroke();
|
||||
ctx2.fillStyle = player === "white" ? "#fff" : "#000";
|
||||
ctx2.fill();
|
||||
ctx2.fillStyle = player === "white" ? "#000" : "#fff";
|
||||
ctx2.fillText(move, subIndex * space + offset, index * space + offset);
|
||||
});
|
||||
ctx2.fillStyle = "#000";
|
||||
ctx2.fillText(
|
||||
"at",
|
||||
subsequentMoves.length * space + offset,
|
||||
index * space + offset
|
||||
);
|
||||
ctx2.fillStyle = player === "white" ? "#fff" : "#000";
|
||||
ctx2.beginPath();
|
||||
ctx2.arc(
|
||||
(subsequentMoves.length + 1) * space + offset,
|
||||
index * space + offset,
|
||||
offset * 0.95,
|
||||
0,
|
||||
Math.PI * 2,
|
||||
true
|
||||
);
|
||||
ctx2.fill();
|
||||
ctx2.stroke();
|
||||
ctx2.fillStyle = player === "white" ? "#000" : "#fff";
|
||||
ctx2.fillText(
|
||||
move,
|
||||
(subsequentMoves.length + 1) * space + offset,
|
||||
index * space + offset
|
||||
);
|
||||
});
|
||||
}, [showMenu, meta, active.handicap, boardSize]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`Game__Menu-container${showMenu ? "" : "--hidden"}`}
|
||||
onClick={(e) => handleBackgroundClick(e)}
|
||||
>
|
||||
<div className="Game__Menu-container__Menu">
|
||||
<button onClick={clickClose}>X</button>
|
||||
<button onClick={clickPrint}>Print Record</button>
|
||||
<div id="record" className="Game__Menu__game-record-container">
|
||||
{drawGameRecord()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Menu;
|
|
@ -1,29 +0,0 @@
|
|||
div.Game__Menu-container {
|
||||
&--hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
background: rgba(0,0,0,0.5);
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
position: absolute;
|
||||
width: 100vw;
|
||||
z-index: 2;
|
||||
|
||||
.Game__Menu-container__Menu {
|
||||
background: #eef;
|
||||
max-height: 90vh;
|
||||
max-width: 80vw;
|
||||
padding: 2vh;
|
||||
overflow: scroll;
|
||||
}
|
||||
|
||||
div.Game__Menu__game-record-container {
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import React from 'react';
|
||||
import './MessageContainer.scss';
|
||||
|
||||
const MessageContainer = () => {
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default MessageContainer;
|
|
@ -1,66 +0,0 @@
|
|||
import React from "react";
|
||||
import "./PlayerArea.scss";
|
||||
|
||||
const PlayerArea = ({
|
||||
handleResignClick,
|
||||
handlePassClick,
|
||||
playerMeta,
|
||||
turn,
|
||||
Kifu,
|
||||
}) => {
|
||||
const { stones, player, rank, captures } = playerMeta;
|
||||
const isTurn =
|
||||
(stones === "black" && turn === 1) || (stones === "white" && turn === -1);
|
||||
const bowlAttributes = () => {
|
||||
if (isTurn || turn === 0)
|
||||
return {
|
||||
"data-turn": true,
|
||||
onClick: () => handlePassClick(stones),
|
||||
};
|
||||
return null;
|
||||
};
|
||||
const bowlText = () => {
|
||||
if (isTurn) return "Pass?";
|
||||
if (turn === 0) return "End Game?";
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`player-container player-container--${stones}`}>
|
||||
<div
|
||||
className={`player-container__bowl player-container__bowl--${stones}`}
|
||||
{...bowlAttributes()}
|
||||
>
|
||||
<p>{bowlText()}</p>
|
||||
</div>
|
||||
{Kifu}
|
||||
<div
|
||||
className={`player-container__name-space player-container__name-space--${stones}`}
|
||||
>
|
||||
<h4>
|
||||
{playerMeta
|
||||
? `${player || stones} ${rank || "?"}`
|
||||
: "Waiting for player"}
|
||||
</h4>
|
||||
|
||||
<div
|
||||
className={`player-container__caps-space player-container__caps-space__${stones}`}
|
||||
>
|
||||
<p
|
||||
className={`player-container__resign-message player-container__resign-message--${stones}`}
|
||||
{...(isTurn ? { onClick: () => handleResignClick(stones) } : null)}
|
||||
>
|
||||
Resign?
|
||||
</p>
|
||||
|
||||
<p
|
||||
className={`player-container__caps-counter player-container__caps-counter--${stones}`}
|
||||
>
|
||||
{playerMeta ? captures : "Captures go here"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PlayerArea;
|
|
@ -1,102 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/variables';
|
||||
@import '../../../../public/stylesheets/partials/mixins';
|
||||
|
||||
div.player-container {
|
||||
align-items: flex-end;
|
||||
display: flex;
|
||||
flex: 5;
|
||||
height: 9vmin;
|
||||
justify-content: space-around;
|
||||
margin: 1em;
|
||||
width: 100%;
|
||||
|
||||
&:last-child {
|
||||
align-items: flex-start;
|
||||
flex-direction: row-reverse;
|
||||
justify-self: flex-end;
|
||||
}
|
||||
|
||||
@media #{map-get($break-points, "500")} {
|
||||
height: 14vh;
|
||||
}
|
||||
|
||||
div.player-container__bowl {
|
||||
align-items: center;
|
||||
background: radial-gradient(farthest-corner at 48% 54%, rgba(30, 5, 0, 0.25) 0%, rgba(30, 5, 0, 0.45) 2%, rgba(30, 5, 0, 0.75) 32%, rgba(0,0,0,0.85)35%, rgb(116,48,17) 48%, rgb(140, 60, 40) 52%, rgb(100, 40, 5) 55%, rgb(116, 48, 17) 58%, rgb(140,60,40) 65%, rgb(100, 40, 5) 80%, rgb(80, 20, 0) 90%);
|
||||
background-color: rgb(116, 48, 17);
|
||||
border-radius: 50%;
|
||||
box-shadow: -1vmin 2vmin 1.5vmin rgba(83, 53, 35, 0.61);
|
||||
display: flex;
|
||||
height: 15vh;
|
||||
justify-content: center;
|
||||
margin: 4vh;
|
||||
order: -1;
|
||||
width: 15vh;
|
||||
|
||||
@media #{map-get($break-points, "570")} {
|
||||
height: 10vh;
|
||||
margin: 3vh;
|
||||
width: 10vh;
|
||||
}
|
||||
|
||||
&[data-turn]:hover p {
|
||||
background-color: rgba(0,0,0,0.3);
|
||||
color: #FFF;
|
||||
cursor: grab;
|
||||
display: block;
|
||||
padding: .5em;
|
||||
}
|
||||
&[data-turn] {
|
||||
// highlight for turn
|
||||
box-shadow: 0 0 3vh 3vh rgb(255, 175, 2);
|
||||
|
||||
& + .player-container__name-space .player-container__caps-space:hover :first-child {
|
||||
background-color: rgba(0,0,0,0.7);
|
||||
cursor: grab;
|
||||
display: block;
|
||||
padding: .5em;
|
||||
position: absolute;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.player-container__caps-space {
|
||||
align-items: center;
|
||||
background: radial-gradient(farthest-side at 49% 52%, rgb(150, 75, 50) 0%, rgb(116,48,17) 35%, rgb(116,48,17) 64%, rgb(80, 20, 0) 65%, rgb(175, 140, 95) 70%, rgb(120, 50, 40) 80%, rgb(80, 20, 0) 95%, rgb(175, 140, 95) 100%);
|
||||
border-radius: 50%;
|
||||
box-shadow: -0.5vmin 1vmin 1vmin rgba(83, 53, 35, 0.61);
|
||||
color: #FFF;
|
||||
display: flex;
|
||||
height: 10vh;
|
||||
justify-content: center;
|
||||
margin: 1vh;
|
||||
width: 10vh;
|
||||
|
||||
@media #{map-get($break-points, "570")} {
|
||||
height: 7vh;
|
||||
margin: 2vh;
|
||||
width: 7vh;
|
||||
}
|
||||
|
||||
& :first-child {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
div.player-container__name-space {
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
display: flex;
|
||||
order: 1;
|
||||
|
||||
h4 {
|
||||
@include gameViewLabel;
|
||||
font-size: 120%;
|
||||
z-index: 1;
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
import React from "react";
|
||||
import "./Point.scss";
|
||||
|
||||
const Point = (props) => {
|
||||
const {
|
||||
posX,
|
||||
posY,
|
||||
user,
|
||||
game,
|
||||
meta,
|
||||
dispatch,
|
||||
pointData,
|
||||
dotData,
|
||||
hoshi,
|
||||
} = props;
|
||||
const turn =
|
||||
meta && meta.turn
|
||||
? meta.turn > 0
|
||||
? "black"
|
||||
: "white"
|
||||
: game.turn > 0
|
||||
? "black"
|
||||
: "white";
|
||||
|
||||
const stone = () => {
|
||||
if (pointData === 1) return "black";
|
||||
if (pointData === -1) return "white";
|
||||
if (pointData === "k") return "ko";
|
||||
return "none";
|
||||
};
|
||||
|
||||
const xFlag = () => {
|
||||
if (posX === 1) return `board__point--top`;
|
||||
if (posX === game.boardSize) return `board__point--bottom`;
|
||||
return "";
|
||||
};
|
||||
const yFlag = () => {
|
||||
if (posY === 1) return `board__point--left`;
|
||||
if (posY === game.boardSize) return `board__point--right`;
|
||||
return "";
|
||||
};
|
||||
const clickHandle = (e) => {
|
||||
if (meta?.turn === 0 && !meta?.winner) {
|
||||
const action = {
|
||||
type: "SOCKET",
|
||||
message: "TOGGLE_TERRITORY",
|
||||
body: { user, point: `${posX}-${posY}`, game, room: game.room },
|
||||
};
|
||||
return dispatch(action);
|
||||
}
|
||||
const action = {
|
||||
type: "SOCKET",
|
||||
message: "MAKE_MOVE",
|
||||
body: {
|
||||
user,
|
||||
game,
|
||||
room: game.room,
|
||||
board: {},
|
||||
move: { player: turn, pos: { x: posX, y: posY } },
|
||||
},
|
||||
};
|
||||
dispatch(action);
|
||||
};
|
||||
|
||||
const getDot = () => {
|
||||
if (meta?.turn === 0) {
|
||||
switch (dotData) {
|
||||
case -1:
|
||||
return "white";
|
||||
case 1:
|
||||
return "black";
|
||||
case "d":
|
||||
return "dame";
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return dotData;
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`board__point ${xFlag()} ${yFlag()}`}
|
||||
onClick={(e) => clickHandle(e)}
|
||||
>
|
||||
<div
|
||||
className={`board__point__stone ${hoshi ? "hoshi" : ""}`}
|
||||
data-stone={stone()}
|
||||
>
|
||||
<div className="board__point__dot" data-dot={getDot()}></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Point;
|
|
@ -1,107 +0,0 @@
|
|||
div.board__point {
|
||||
background: conic-gradient(#000 0%, rgba(0,0,0,0) 1%, rgba(0,0,0,0) 24%, #000 25%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 49%, #000 50%, rgba(0,0,0,0) 51%, rgba(0,0,0,0) 74%, #000 75%, rgba(0,0,0,0) 76%, rgba(0,0,0,0) 99%, #000 100%);
|
||||
border-radius: 50% solid black;
|
||||
color: black;
|
||||
margin: auto;
|
||||
padding: 0;
|
||||
vertical-align: middle;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
div.board__point--top {
|
||||
background: conic-gradient( rgba(0,0,0,0) 24%, #000 25%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 49%, #000 50%, rgba(0,0,0,0) 51%, rgba(0,0,0,0) 74%, #000 75%, rgba(0,0,0,0) 76%);
|
||||
}
|
||||
|
||||
div.board__point--bottom {
|
||||
background: conic-gradient(#000 0%, rgba(0,0,0,0) 1%, rgba(0,0,0,0) 24%, #000 25%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 74%, #000 75%, rgba(0,0,0,0) 76%, rgba(0,0,0,0) 99%, #000 100%);
|
||||
}
|
||||
|
||||
div.board__point--left {
|
||||
background: conic-gradient(#000 0%, rgba(0,0,0,0) 1%, rgba(0,0,0,0) 24%, #000 25%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 49%, #000 50%, rgba(0,0,0,0) 51%, rgba(0,0,0,0) 99%, #000 100%);
|
||||
}
|
||||
|
||||
div.board__point--right {
|
||||
background: conic-gradient(#000 0%, rgba(0,0,0,0) 1%, rgba(0,0,0,0) 49%, #000 50%, rgba(0,0,0,0) 51%, rgba(0,0,0,0) 74%, #000 75%, rgba(0,0,0,0) 76%, rgba(0,0,0,0) 99%, #000 100%);
|
||||
}
|
||||
|
||||
div.board__point--top.board__point--left {
|
||||
background: conic-gradient( rgba(0,0,0,0) 24%, #000 25%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 49%, #000 50%, rgba(0,0,0,0) 51%);
|
||||
}
|
||||
|
||||
div.board__point--top.board__point--right {
|
||||
background: conic-gradient( rgba(0,0,0,0) 49%, #000 50%, rgba(0,0,0,0) 51%, rgba(0,0,0,0) 74%, #000 75%, rgba(0,0,0,0) 76% );
|
||||
}
|
||||
|
||||
div.board__point--bottom.board__point--left {
|
||||
background: conic-gradient(#000 0%, rgba(0,0,0,0) 1%, rgba(0,0,0,0) 24%, #000 25%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 99%, #000 100%);
|
||||
}
|
||||
|
||||
div.board__point--bottom.board__point--right {
|
||||
background: conic-gradient(#000 0%, rgba(0,0,0,0) 1%, rgba(0,0,0,0) 74%, #000 75%, rgba(0,0,0,0) 76%, rgba(0,0,0,0) 99%, #000 100%);
|
||||
}
|
||||
|
||||
div.board__point__stone {
|
||||
width: 85%;
|
||||
height: 85%;
|
||||
border-radius: 50%;
|
||||
vertical-align: middle;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
&.hoshi {
|
||||
background: radial-gradient(circle farthest-corner at center, #000 0%, #000 14%, rgba(0,0,0,0) 15%);
|
||||
z-index: 3;
|
||||
}
|
||||
}
|
||||
|
||||
div.board__point div.board__point__stone div.board__point__dot {
|
||||
width: 35%;
|
||||
height: 35%;
|
||||
border-radius: 50%;
|
||||
margin: auto;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.board__point__stone{
|
||||
&[data-stone="white"] {
|
||||
background: radial-gradient(farthest-side at 55% 40%, white 0%, rgb(200,200,200) 65%, rgb(100,100,100) 90%, rgb(68, 50, 0) 100%);
|
||||
box-shadow: -.25vmin .5vmin .5vmin rgba(145, 92, 23, 0.5);
|
||||
}
|
||||
|
||||
&[data-stone="black"] {
|
||||
background-color: black;
|
||||
background: radial-gradient(farthest-side at 55% 40%, rgb(220,220,220) 0%, rgb(60,60,60) 45%, rgb(15,15,15) 90%, rgb(5, 5, 0) 100%);
|
||||
box-shadow: -.25vmin .5vmin .5vmin rgba(145, 92, 23, 0.75);
|
||||
}
|
||||
|
||||
&[data-stone="ko"] {
|
||||
background-color: transparent;
|
||||
border: .5vmin solid rgba(200,20,50,0.8);
|
||||
border-radius: 0%;
|
||||
height: 60%;
|
||||
width: 60%;
|
||||
}
|
||||
}
|
||||
|
||||
div.board__point {
|
||||
div.board__point__dot[data-dot="dame"] {
|
||||
background: purple;
|
||||
}
|
||||
div.board__point__dot[data-dot="black"] {
|
||||
background: black;
|
||||
}
|
||||
div.board__point__dot[data-dot="white"] {
|
||||
background: white;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
div.board__point__dot[data-dot="1"] {
|
||||
background: black;
|
||||
}
|
||||
div.board__point__dot[data-dot="-1"] {
|
||||
background: white;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import React from 'react';
|
||||
import './Timer.scss';
|
||||
|
||||
const Timer = () => {
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Timer;
|
|
@ -1,56 +0,0 @@
|
|||
import socketIOClient from "socket.io-client";
|
||||
import config from "./config";
|
||||
|
||||
const launch = (nsp, dispatch) => {
|
||||
const socket = socketIOClient(`${config.socketAddress}/${nsp}`);
|
||||
|
||||
socket.on("connected", () => {
|
||||
dispatch({
|
||||
type: "SOCKET",
|
||||
message: "CONNECTED",
|
||||
body: { nsp: socket.nsp },
|
||||
});
|
||||
});
|
||||
socket.on("connect_error", (err) => {
|
||||
dispatch({
|
||||
type: "ERR",
|
||||
message: "SOCKET_ERROR",
|
||||
body: { socketError: err },
|
||||
});
|
||||
});
|
||||
socket.on("error", (err) => {
|
||||
dispatch({
|
||||
type: "ERR",
|
||||
message: "SOCKET_ERROR",
|
||||
body: { socketError: err },
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("room_connected", (data) => {
|
||||
dispatch({ type: "ROOMS", message: "CONNECT_ROOM", body: data });
|
||||
});
|
||||
|
||||
socket.on("new_user", (data) => {
|
||||
dispatch({ type: "ROOMS", message: "NEW_USER", body: data });
|
||||
});
|
||||
|
||||
socket.on("game_connected", (data) => {
|
||||
dispatch({ type: "GAMES", message: "UPDATE_BOARD", body: data });
|
||||
});
|
||||
|
||||
socket.on("update_board", (data) => {
|
||||
dispatch({ type: "GAMES", message: "UPDATE_BOARD", body: data });
|
||||
});
|
||||
|
||||
socket.on("game_resign", (data) => {
|
||||
dispatch({ type: "GAMES", message: "GAME_RESIGN", body: data });
|
||||
});
|
||||
|
||||
socket.on("end_game", (data) => {
|
||||
dispatch({ type: "GAMES", message: "GAME_END", body: data });
|
||||
});
|
||||
|
||||
return socket;
|
||||
};
|
||||
|
||||
export { launch };
|
|
@ -1,163 +0,0 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import gamesServices from "../../services/api/gamesServices";
|
||||
import "./Game.scss";
|
||||
import Logo from "../../components/Display/Logo/Logo";
|
||||
import Board from "../../components/GameUI/Board/Board";
|
||||
import PlayerArea from "../../components/GameUI/PlayerArea/PlayerArea";
|
||||
import Kifu from "../../components/GameUI/Kifu/Kifu";
|
||||
import Menu from "../../components/GameUI/Menu/Menu";
|
||||
|
||||
const Game = (props) => {
|
||||
const { state, dispatch } = props;
|
||||
const gameId = parseInt(useParams().id) || 0;
|
||||
const [playerBlackMeta, setPlayerBlackMeta] = useState({});
|
||||
const [playerWhiteMeta, setPlayerWhiteMeta] = useState({});
|
||||
const [showMenu, setShowMenu] = useState(false);
|
||||
const playerState = state?.meta?.playerState;
|
||||
const game = state.active?.game;
|
||||
|
||||
useEffect(() => {
|
||||
const fetchGameAPI = async () => {
|
||||
const response = await gamesServices.getGameService(gameId);
|
||||
if (response) {
|
||||
const action = {
|
||||
type: "GAMES",
|
||||
message: "SET_ACTIVE",
|
||||
body: response,
|
||||
};
|
||||
return dispatch(action);
|
||||
}
|
||||
};
|
||||
fetchGameAPI();
|
||||
}, [gameId, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
const roomSocketConnect = () => {
|
||||
const game = state.active.game;
|
||||
const user = state.user;
|
||||
const action = {
|
||||
type: "SOCKET",
|
||||
message: "CONNECT_GAME",
|
||||
body: { game, user, dispatch },
|
||||
};
|
||||
return dispatch(action);
|
||||
};
|
||||
roomSocketConnect();
|
||||
}, [state.active.game, dispatch, state.user]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!game || !playerState) return;
|
||||
const { playerBlack, playerBlackRank, playerWhite, playerWhiteRank } = game;
|
||||
const { bCaptures, wCaptures } = playerState;
|
||||
setPlayerBlackMeta({
|
||||
player: playerBlack,
|
||||
rank: playerBlackRank,
|
||||
captures: bCaptures,
|
||||
stones: "black",
|
||||
});
|
||||
setPlayerWhiteMeta({
|
||||
player: playerWhite,
|
||||
rank: playerWhiteRank,
|
||||
captures: wCaptures,
|
||||
stones: "white",
|
||||
});
|
||||
}, [playerState, game]);
|
||||
|
||||
const handleResignClick = (player) => {
|
||||
const action = {
|
||||
type: "SOCKET",
|
||||
message: "RESIGN",
|
||||
body: { game, player },
|
||||
};
|
||||
dispatch(action);
|
||||
};
|
||||
|
||||
const handlePassClick = (player) => {
|
||||
if (state?.meta && state?.meta?.winner) return;
|
||||
if (state?.meta && state?.meta?.turn === 0) {
|
||||
const action = {
|
||||
type: "SOCKET",
|
||||
message: "END_GAME",
|
||||
body: { game, player },
|
||||
};
|
||||
return dispatch(action);
|
||||
}
|
||||
const action = {
|
||||
type: "SOCKET",
|
||||
message: "PASS",
|
||||
body: { game, player },
|
||||
};
|
||||
dispatch(action);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="Game" data-testid="Game">
|
||||
<Menu
|
||||
showMenu={showMenu}
|
||||
clickClose={() => setShowMenu(false)}
|
||||
{...props}
|
||||
/>
|
||||
<div className="Game__meta-container">
|
||||
<span className="Game__socket-flag">{state.socket ? "✓" : " ⃠"}</span>
|
||||
<Logo />
|
||||
{state?.meta?.winner ? (
|
||||
<p>
|
||||
{`winner: ${
|
||||
state.meta.winner === 1
|
||||
? playerBlackMeta?.player
|
||||
: playerWhiteMeta?.player
|
||||
}
|
||||
`}
|
||||
</p>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<p>Timer</p>
|
||||
<p>? Game Tree</p>
|
||||
</div>
|
||||
|
||||
<div className="Game__board-container">
|
||||
<PlayerArea
|
||||
handleResignClick={handleResignClick}
|
||||
handlePassClick={handlePassClick}
|
||||
playerMeta={
|
||||
state.user &&
|
||||
playerBlackMeta.playerBlack &&
|
||||
state.user === playerBlackMeta.playerBlack
|
||||
? playerBlackMeta
|
||||
: playerWhiteMeta
|
||||
}
|
||||
turn={state?.meta?.turn}
|
||||
/>
|
||||
<Board
|
||||
dispatch={dispatch}
|
||||
game={state.active.game}
|
||||
meta={state.meta}
|
||||
user={state.user}
|
||||
board={state.board}
|
||||
/>
|
||||
<PlayerArea
|
||||
handleResignClick={handleResignClick}
|
||||
handlePassClick={handlePassClick}
|
||||
playerMeta={
|
||||
state.user &&
|
||||
playerBlackMeta.playerWhite &&
|
||||
state.user === playerWhiteMeta.playerWhite
|
||||
? playerWhiteMeta
|
||||
: playerBlackMeta
|
||||
}
|
||||
Kifu={<Kifu clickKifu={() => setShowMenu(true)} />}
|
||||
turn={state?.meta?.turn}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="Game__message-container">
|
||||
<p>Messages</p>
|
||||
<p>Message Form</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Game;
|
|
@ -1,18 +0,0 @@
|
|||
div.Game {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr 1fr;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background: radial-gradient(
|
||||
farthest-corner at 55% 40%,
|
||||
rgb(150, 200, 220) 0%, rgb(97, 166, 194) 65%, rgb(70,100,120) 90%, rgb(40, 80, 90) 100%
|
||||
);
|
||||
}
|
||||
|
||||
div.Game__board-container {
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
justify-content: space-evenly;
|
||||
max-width: 50vw;
|
||||
max-height: 100vh;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import './Home.scss';
|
||||
import roomsServices from '../../services/api/roomsServices';
|
||||
import RoomButton from '../../components/Button/Room/Room';
|
||||
|
||||
import Loading from '../../components/Display/Loading/Loading';
|
||||
|
||||
const Home = props => {
|
||||
const state = props.state || {};
|
||||
const dispatch = props.dispatch;
|
||||
const [ roomDetail, setRoomDetail ] = useState(1);
|
||||
|
||||
const showRoomDetail = id => roomDetail === id ? setRoomDetail(0) : setRoomDetail(id);
|
||||
|
||||
const renderRooms = () => {
|
||||
const rooms = state.rooms || [];
|
||||
if (rooms.length) {
|
||||
return rooms.map(roomData => (
|
||||
<RoomButton
|
||||
key={`room-${roomData.id}`}
|
||||
room={roomData}
|
||||
roomDetail={roomDetail === roomData.id}
|
||||
showRoomDetail={showRoomDetail}
|
||||
/>
|
||||
))
|
||||
}
|
||||
// TODO stub loader
|
||||
return <Loading />
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const fetchRoomsAPI = async () => {
|
||||
const response = await roomsServices.indexService();
|
||||
if (response) {
|
||||
const action = {
|
||||
type: 'ROOMS',
|
||||
message: 'SET_ROOMS',
|
||||
body: response.rooms
|
||||
}
|
||||
return dispatch(action)
|
||||
}
|
||||
}
|
||||
fetchRoomsAPI();
|
||||
}, [ dispatch ])
|
||||
|
||||
return (
|
||||
<div className="Home" data-testid="Home">
|
||||
{renderRooms()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Home;
|
|
@ -1,11 +0,0 @@
|
|||
@import '../../../public/stylesheets/partials/variables';
|
||||
@import '../../../public/stylesheets/partials/mixins';
|
||||
|
||||
div.Home {
|
||||
@include fullspan;
|
||||
background-color: map-get($colors, "home");
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, 22vh);
|
||||
grid-template-rows: repeat(auto-fill, minmax(22vh, 1fr));
|
||||
overflow: scroll;
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
import React from 'react';
|
||||
|
||||
import Auth from '../../components/Form/Auth/Auth';
|
||||
import NewRoomButton from '../../components/Button/NewRoom/NewRoom';
|
||||
import FindRoomForm from '../../components/Form/FindRoom/FindRoom';
|
||||
import LibraryButton from '../../components/Button/Library/Library';
|
||||
|
||||
const HomeSidebar = (props) => {
|
||||
const { state, dispatch } = props;
|
||||
|
||||
const ifUser = <>
|
||||
<FindRoomForm />
|
||||
<NewRoomButton />
|
||||
<LibraryButton />
|
||||
</>
|
||||
|
||||
const ifNoUser = <Auth state={state} dispatch={dispatch} />
|
||||
|
||||
return (
|
||||
<nav>
|
||||
{
|
||||
state.user.username
|
||||
? ifUser
|
||||
: ifNoUser
|
||||
}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export default HomeSidebar;
|
|
@ -1,54 +0,0 @@
|
|||
import React from 'react';
|
||||
import './MainWrapper.scss';
|
||||
|
||||
import NavBar from '../NavBar/NavBar';
|
||||
import Sidebar from '../Sidebar/Sidebar';
|
||||
import Account from '../../Account/Account';
|
||||
import Game from '../../Game/Game';
|
||||
import Home from '../../Home/Home';
|
||||
import News from '../../News/News';
|
||||
import Room from '../../Room/Room';
|
||||
|
||||
const MainWrapper = (props) => {
|
||||
const { state, page, dispatch } = props;
|
||||
|
||||
const setWrapperWithSidebarAndPage = () => {
|
||||
if (page === 'game') return selectPage()
|
||||
return (
|
||||
<div className="main-wrapper" data-testid="main-wrapper">
|
||||
<NavBar state={state}/>
|
||||
<div className="content-wrapper">
|
||||
<Sidebar page={page} state={state} dispatch={dispatch}/>
|
||||
<main>
|
||||
{selectPage()}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const selectPage = () =>{
|
||||
switch (page) {
|
||||
case 'account':
|
||||
return <Account state={state} dispatch={dispatch}/>
|
||||
case 'game':
|
||||
return <Game state={state} dispatch={dispatch}/>
|
||||
case 'home':
|
||||
return <Home state={state} dispatch={dispatch}/>
|
||||
case 'news':
|
||||
return <News state={state} dispatch={dispatch}/>
|
||||
case 'room':
|
||||
return <Room state={state} dispatch={dispatch}/>
|
||||
default:
|
||||
return <></>
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{ setWrapperWithSidebarAndPage() }
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default MainWrapper;
|
|
@ -1,36 +0,0 @@
|
|||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import "./NavBar.scss";
|
||||
import Logo from "../../../components/Display/Logo/Logo";
|
||||
|
||||
const NavBar = ({ state }) => {
|
||||
return (
|
||||
<div className="NavBar" data-testid="NavBar">
|
||||
<Link to="/home">
|
||||
<div className="NavBar__logo">
|
||||
<Logo />
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<Link to="/home">
|
||||
<div className="NavBar__menu-item NavBar__home">
|
||||
<p className="--link">Find a Game</p>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<Link to="/news">
|
||||
<div className="NavBar__menu-item NavBar__news">
|
||||
<p className="--link">News</p>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<Link to="/account">
|
||||
<div className="NavBar__menu-item NavBar__account">
|
||||
{state.user.username ? state.user.username : <></>}
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default NavBar;
|
|
@ -1,22 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/_variables.scss';
|
||||
|
||||
div.NavBar {
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: map-get($colors, "nav_bar");
|
||||
color: map-get($colors, "nav_link");
|
||||
|
||||
p {
|
||||
font-size: 1.4em;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a{
|
||||
color: inherit;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
@import '../../../../public/stylesheets/partials/variables';
|
||||
|
||||
aside {
|
||||
color: map-get($colors, "sidebar_link");
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
|
||||
nav {
|
||||
align-items: stretch;
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 130%;
|
||||
margin: .2em auto;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
input {
|
||||
display: block;
|
||||
margin: .2em 0 .2em auto;
|
||||
}
|
||||
|
||||
div.nav__section {
|
||||
border: rgba(100,100,100,0.5) solid .25em;
|
||||
margin: .5em;
|
||||
padding: .75em .5em;
|
||||
}
|
||||
|
||||
p.nav__section__label {
|
||||
font-size: 110%;
|
||||
margin-bottom: .5em;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
@import '../../../public/stylesheets/partials/_variables';
|
||||
|
||||
div.Room {
|
||||
align-items: initial;
|
||||
background: map-get($backgrounds, "game_room");
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
height: 100%;
|
||||
justify-content: stretch;
|
||||
overflow: scroll;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
div.Room__heading {
|
||||
align-self: center;
|
||||
height: 100%;
|
||||
position: sticky;
|
||||
top: 1em;
|
||||
z-index: 3;
|
||||
|
||||
span.error--action {
|
||||
padding: 1em;
|
||||
background-color: map-get($colors, "error");
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
div.Room__game-container {
|
||||
min-height: 100%;
|
||||
min-width: 100%;
|
||||
justify-self: flex-start;
|
||||
align-self: flex-start;
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
}
|
||||
|
||||
div.Room__message-container {
|
||||
height: 100%;
|
||||
justify-self: flex-end;
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
export const authReducer = (state, action) => {
|
||||
switch (action.message) {
|
||||
case "LOGIN":
|
||||
return loginReducer(state, action);
|
||||
|
||||
case "SIGNUP":
|
||||
return loginReducer(state, action);
|
||||
|
||||
case "GUEST":
|
||||
return loginReducer(state, action);
|
||||
|
||||
case "LOGOUT":
|
||||
return state;
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
function loginReducer(state, action) {
|
||||
const newUser = action.body;
|
||||
return { ...state, user: newUser };
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
import { stateReducer } from "../reducer";
|
||||
|
||||
export const gamesReducer = (state, action) => {
|
||||
switch (action.message) {
|
||||
case "SET_GAMES": {
|
||||
const games = formatGames(action);
|
||||
return { ...state, games };
|
||||
}
|
||||
|
||||
case "JOIN_REQUEST": {
|
||||
return joinRequest(state, action);
|
||||
}
|
||||
|
||||
case "UPDATE_BOARD": {
|
||||
return updateBoard(state, action);
|
||||
}
|
||||
|
||||
case "GAME_RESIGN": {
|
||||
return gameResign(state, action);
|
||||
}
|
||||
|
||||
case "SET_ACTIVE": {
|
||||
return { ...state, active: action.body };
|
||||
}
|
||||
|
||||
case "GAME_END": {
|
||||
return gameEnd(state, action);
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// parse ranks from db in K9 format to 9k format
|
||||
function parseRank(rank) {
|
||||
switch (rank[0]) {
|
||||
// Dan ranks
|
||||
case "D":
|
||||
return `${rank.slice(1)}${rank[0].toLowerCase()}`;
|
||||
// Kyu ranks
|
||||
case "K":
|
||||
return `${rank.slice(1)}${rank[0].toLowerCase()}`;
|
||||
// Unranked
|
||||
case "U":
|
||||
return "?";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
function formatGames(action) {
|
||||
const games = [...action.body].map((game) => {
|
||||
if (game.playerBlackRank) {
|
||||
game.playerBlackRank = parseRank(game.playerBlackRank);
|
||||
}
|
||||
|
||||
if (game.playerWhiteRank) {
|
||||
game.playerWhiteRank = parseRank(game.playerWhiteRank);
|
||||
}
|
||||
|
||||
return game;
|
||||
});
|
||||
|
||||
return games;
|
||||
}
|
||||
|
||||
function joinRequest(state, action) {
|
||||
if (!Object.entries(state.user).length) {
|
||||
const errAction = {
|
||||
type: "ERR",
|
||||
message: "JOIN_GAME_ERROR",
|
||||
body: { joinGameError: "user not logged in" },
|
||||
};
|
||||
return stateReducer(state, errAction);
|
||||
}
|
||||
const id = action.body;
|
||||
return { ...state, joinGame: id };
|
||||
}
|
||||
|
||||
function updateBoard(state, action) {
|
||||
console.log(action.body);
|
||||
const { gameRecord, pass, turn, winner, playerState } = action.body.meta;
|
||||
const territory = action.body.territory;
|
||||
return {
|
||||
...state,
|
||||
board: action.body.board,
|
||||
meta: { gameRecord, pass, turn, winner, playerState, territory },
|
||||
};
|
||||
}
|
||||
|
||||
function gameResign(state, action) {
|
||||
const { gameRecord, pass, turn, winner, playerState } = action.body;
|
||||
return {
|
||||
...state,
|
||||
meta: { gameRecord, pass, turn, winner, playerState },
|
||||
};
|
||||
}
|
||||
|
||||
function gameEnd(state, action) {
|
||||
const { winner, score } = action.body.meta;
|
||||
return { ...state, meta: { ...state.meta, winner, score } };
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
export const initState = () => {
|
||||
return {
|
||||
active: {
|
||||
game: {
|
||||
id: 0, room: 0,
|
||||
mainTime: '', timePeriod: 0, periodLength: 0, overtime: '', overtimePeriod: 0, overtimeLength: 0,
|
||||
application: '', applicationVersion: '', open: false, description: null,
|
||||
event: null, round: null, name: null,
|
||||
winType: null, capturesBlack: null, capturesWhite: null, score: null,
|
||||
boardSize: 0, komi: 0.0, handicap: 0,
|
||||
playerBlack: '', playerBlackRank: '', playerWhite: '', playerWhiteRank: '',
|
||||
},
|
||||
record: []
|
||||
},
|
||||
|
||||
board: {},
|
||||
|
||||
connect: { location: '', type: '' },
|
||||
|
||||
currentRoom: {
|
||||
description: '', id: 0, language: '', name: ''
|
||||
},
|
||||
|
||||
errors: {},
|
||||
|
||||
games: [ {
|
||||
boardSize: 0, handicap: 0, id: 0, komi: 0.0, open: false,
|
||||
playerBlack: '', playerBlackRank: '', playerWhite: '',
|
||||
playerWhiteRank: '', winType: null
|
||||
} ],
|
||||
|
||||
joinGame: {},
|
||||
|
||||
messages: [ {
|
||||
admin: false, content: '', username: ''
|
||||
} ],
|
||||
|
||||
socket: {
|
||||
connected: false,
|
||||
nsp: ''
|
||||
},
|
||||
|
||||
user: { username: '', email: '', id: 0 }
|
||||
};
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
export const messagesReducer = (state, action) => {
|
||||
switch(action.message) {
|
||||
|
||||
case 'SET_MESSAGES':
|
||||
const messages = action.body;
|
||||
return {...state, messages};
|
||||
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
import { initState } from './init/reducer.init';
|
||||
import { authReducer } from './auth/reducer.auth';
|
||||
import { errorReducer } from './err/reducer.err';
|
||||
import { indexReducer } from './index/reducer.index';
|
||||
import { roomsReducer } from './rooms/reducer.rooms';
|
||||
import { messagesReducer } from './messages/reducer.messages';
|
||||
import { gamesReducer } from './games/reducer.games';
|
||||
import { socketReducer } from './socket/reducer.socket';
|
||||
|
||||
|
||||
export const stateReducer = (state, action) => {
|
||||
const errorStrippedState = stripErrors({...state});
|
||||
|
||||
switch (action.type) {
|
||||
case 'INIT': return initState();
|
||||
|
||||
case 'AUTH':
|
||||
return authReducer(errorStrippedState, action);
|
||||
|
||||
case 'GAMES':
|
||||
return gamesReducer(errorStrippedState, action);
|
||||
|
||||
case 'INDEX':
|
||||
return indexReducer(errorStrippedState, action);
|
||||
|
||||
case 'MESSAGES':
|
||||
return messagesReducer(errorStrippedState, action);
|
||||
|
||||
case 'ROOMS':
|
||||
return roomsReducer(errorStrippedState, action);
|
||||
|
||||
case 'SOCKET':
|
||||
return socketReducer(errorStrippedState, action);
|
||||
|
||||
case 'ERR':
|
||||
return errorReducer(errorStrippedState, action);
|
||||
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
||||
function stripErrors(state) {
|
||||
return {...state, errors: {}}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
import { stateReducer } from "../reducer";
|
||||
const io = require("../../io");
|
||||
|
||||
export const socketReducer = (state, action) => {
|
||||
switch (action.message) {
|
||||
case "CONNECTED":
|
||||
return { ...state, connect: { type: "home", location: action.body.nsp } };
|
||||
|
||||
case "LAUNCH": {
|
||||
const { nsp, dispatch } = action.body;
|
||||
const launchedSocket = io.launch(nsp, dispatch);
|
||||
return { ...state, socket: launchedSocket };
|
||||
}
|
||||
|
||||
case "CONNECT_ROOM": {
|
||||
const { user, room, dispatch } = action.body;
|
||||
let priorSocket = state.socket;
|
||||
if (!priorSocket.nsp) {
|
||||
priorSocket = io.launch("", dispatch);
|
||||
}
|
||||
if (priorSocket.nsp !== `/${room}`) {
|
||||
priorSocket.emit("connect_room", { user, room });
|
||||
priorSocket.close();
|
||||
}
|
||||
const socket = io.launch(room, dispatch);
|
||||
return { ...state, socket };
|
||||
}
|
||||
|
||||
case "CONNECT_GAME": {
|
||||
return connectGame(state, action);
|
||||
}
|
||||
|
||||
case "MAKE_MOVE": {
|
||||
return makeMove(state, action);
|
||||
}
|
||||
|
||||
case "RESIGN": {
|
||||
return resign(state, action);
|
||||
}
|
||||
|
||||
case "PASS": {
|
||||
return pass(state, action);
|
||||
}
|
||||
|
||||
case "TOGGLE_TERRITORY": {
|
||||
return toggleTerritory(state, action);
|
||||
}
|
||||
|
||||
case "END_GAME": {
|
||||
return endGame(state, action);
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
function connectGame(state, action) {
|
||||
const { user, game, dispatch } = action.body;
|
||||
const priorSocket = state.socket;
|
||||
let updatedState;
|
||||
if (!priorSocket.nsp || priorSocket.nsp !== `/${game.room}`) {
|
||||
const connectRoomAction = {
|
||||
type: "SOCKET",
|
||||
message: "CONNECT_ROOM",
|
||||
body: { user, room: game.room, dispatch },
|
||||
};
|
||||
updatedState = stateReducer(state, connectRoomAction);
|
||||
}
|
||||
if (!updatedState) updatedState = { ...state };
|
||||
const socket = updatedState.socket;
|
||||
socket.emit("connect_game", { user, game });
|
||||
return { ...updatedState };
|
||||
}
|
||||
|
||||
function makeMove(state, action) {
|
||||
const socket = state.socket;
|
||||
socket.emit("make_move", { ...action.body });
|
||||
return state;
|
||||
}
|
||||
|
||||
function resign(state, action) {
|
||||
const socket = state.socket;
|
||||
socket.emit("resign", { ...action.body });
|
||||
return state;
|
||||
}
|
||||
|
||||
function pass(state, action) {
|
||||
const socket = state.socket;
|
||||
socket.emit("pass", { ...action.body });
|
||||
return state;
|
||||
}
|
||||
|
||||
function toggleTerritory(state, action) {
|
||||
const socket = state.socket;
|
||||
socket.emit("toggle_territory", { ...action.body });
|
||||
return state;
|
||||
}
|
||||
|
||||
function endGame(state, action) {
|
||||
console.log("end game");
|
||||
const socket = state.socket;
|
||||
socket.emit("end_game", { ...action.body });
|
||||
return state;
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
import config from '../../config';
|
||||
|
||||
const apiAddress = config.apiAddress;
|
||||
const gamesAddress = `${apiAddress}/games`
|
||||
|
||||
var headers = new Headers();
|
||||
headers.append('Content-Type', 'application/json');
|
||||
headers.append('Accept', 'application/json');
|
||||
headers.append('Sec-Fetch-Site', 'cross-site')
|
||||
|
||||
const getGameService = async (gameIndex) => {
|
||||
const response = await fetch(`${gamesAddress}/${gameIndex}`,
|
||||
{method: 'GET', credentials: 'include', headers: headers}
|
||||
)
|
||||
.then(res => res.text())
|
||||
.then(text => JSON.parse(text))
|
||||
.then(obj => {
|
||||
// Reformat from SQL coluumn name convention to JS
|
||||
delete Object.assign(obj.game, {applicationVersion: obj.game.application_version }).application_version;
|
||||
delete Object.assign(obj.game, {boardSize: obj.game.board_size }).board_size;
|
||||
delete Object.assign(obj.game, {playerBlack: obj.game.player_black }).player_black;
|
||||
delete Object.assign(obj.game, {playerBlackRank: obj.game.player_black_rank }).player_black_rank;
|
||||
delete Object.assign(obj.game, {playerWhite: obj.game.player_white }).player_white;
|
||||
delete Object.assign(obj.game, {playerWhiteRank: obj.game.player_white_rank }).player_white_rank;
|
||||
delete Object.assign(obj.game, {capturesWhite: obj.game.captures_white }).captures_white;
|
||||
delete Object.assign(obj.game, {capturesBlack: obj.game.captures_black }).captures_black;
|
||||
delete Object.assign(obj.game, {mainTime: obj.game.main_time }).main_time;
|
||||
delete Object.assign(obj.game, {timePeriod: obj.game.time_period }).time_period;
|
||||
delete Object.assign(obj.game, {periodLength: obj.game.period_length }).period_length;
|
||||
delete Object.assign(obj.game, {overtimePeriod: obj.game.overtime_period }).overtime_period;
|
||||
delete Object.assign(obj.game, {overtimeLength: obj.game.overtime_length }).overtime_length;
|
||||
delete Object.assign(obj.game, {winType: obj.game.win_type }).win_type;
|
||||
|
||||
return obj;
|
||||
})
|
||||
.catch(err => err);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export default {
|
||||
getGameService
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
import config from "../config";
|
||||
|
||||
const authEndpoint = config.authAddress;
|
||||
const signupEndpoint = `${authEndpoint}/signup`;
|
||||
const loginEndpoint = `${authEndpoint}/login`;
|
||||
const guestEndpoint = `${authEndpoint}/guest`;
|
||||
|
||||
var headers = new Headers();
|
||||
headers.append("Content-Type", "application/json");
|
||||
headers.append("Accept", "application/json");
|
||||
headers.append("Sec-Fetch-Site", "cross-site");
|
||||
|
||||
const loginService = async (formData) => {
|
||||
const response = await fetch(loginEndpoint, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify(formData),
|
||||
headers: headers,
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((text) => JSON.parse(text))
|
||||
.catch((err) => err);
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
const signupService = async (formData) => {
|
||||
const response = await fetch(signupEndpoint, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify(formData),
|
||||
headers: headers,
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((text) => JSON.parse(text))
|
||||
.catch((err) => err);
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
const guestService = async () => {
|
||||
const response = await fetch(guestEndpoint, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers,
|
||||
})
|
||||
.then((res) => res.text())
|
||||
.then((text) => JSON.parse(text))
|
||||
.catch((err) => err);
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export default {
|
||||
loginService,
|
||||
signupService,
|
||||
guestService,
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
# Node Go
|
||||
A browser application to play Go in real time.
|
||||
|
||||
## Development Demo
|
||||
[The project in it's current state](https://play-node-go.herokuapp.com/)
|
||||
|
||||
## Features
|
||||
- [ ] Realtime communications
|
||||
- [ ] Multiple game settings
|
||||
- [ ] Customizable board size
|
||||
|
||||
|
||||
## Built with
|
||||
- [Express](https://expressjs.com)
|
||||
- [React](https://reactjs.org)
|
||||
- [PostgreSQL](https://postgresql.org)
|
||||
- [Socket.io](https://socket.io)
|
||||
- [Sass](https://sass-lang.com)
|
|
@ -1,88 +0,0 @@
|
|||
const { validationResult } = require("express-validator");
|
||||
|
||||
const userQueries = require("../data/queries/user");
|
||||
const { hashPassword, compareHash } = require("../services/bcrypt");
|
||||
const signToken = require("../services/signToken");
|
||||
const guestServices = require("../services/guestServices");
|
||||
|
||||
const checkValidationErrors = (req, res) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) {
|
||||
return res.status(422).json({ errors: errors.array() });
|
||||
}
|
||||
};
|
||||
|
||||
const signup = async (req, res, next) => {
|
||||
checkValidationErrors(req, res);
|
||||
const user = req.body;
|
||||
try {
|
||||
delete user.confirmPassword;
|
||||
const existingUser = await userQueries.findUserByNameOrEmail(user);
|
||||
const hashedPassword = await hashPassword(user.password);
|
||||
const secureUser = { ...user, password: hashedPassword };
|
||||
if (existingUser.length) {
|
||||
return res
|
||||
.status(409)
|
||||
.json({ errors: [{ auth: "User already exists!" }] });
|
||||
}
|
||||
|
||||
const newUser = await userQueries.insertUser(secureUser);
|
||||
signToken(res, newUser);
|
||||
res.status(201).json({ ...newUser });
|
||||
} catch (err) {
|
||||
res.status(500).json(err);
|
||||
}
|
||||
};
|
||||
|
||||
const login = async (req, res, next) => {
|
||||
checkValidationErrors(req, res);
|
||||
const user = req.body;
|
||||
|
||||
try {
|
||||
const queryResults = await userQueries.findUserByNameOrEmail(user);
|
||||
const savedUser = queryResults[0] || null;
|
||||
|
||||
if (!savedUser) {
|
||||
return res.status(401).send({ errors: "bad credentials" });
|
||||
}
|
||||
|
||||
const hashedPassword = savedUser.password;
|
||||
const passwordMatch = await compareHash(user.password, hashedPassword);
|
||||
|
||||
if (!passwordMatch) {
|
||||
return res.status(401).send({ errors: "bad credentials" });
|
||||
}
|
||||
|
||||
const authorizedUser = { ...savedUser };
|
||||
delete authorizedUser.password;
|
||||
|
||||
signToken(res, authorizedUser);
|
||||
res.send({ ...authorizedUser }).status(200);
|
||||
} catch (e) {
|
||||
res.status(500).send({ errors: e });
|
||||
}
|
||||
};
|
||||
|
||||
const guest = async (req, res, next) => {
|
||||
try {
|
||||
// username generator returns `Guest-${num}`
|
||||
const { username, password } = guestServices.generateGuest();
|
||||
// generateGuestUser();
|
||||
const email = null;
|
||||
// id generator returns `
|
||||
const id = null;
|
||||
const user = { username, email, id, password };
|
||||
signToken(res, user);
|
||||
delete user.password;
|
||||
res.send(user);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).send({ errors: e });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
signup,
|
||||
login,
|
||||
guest,
|
||||
};
|
|
@ -1,81 +0,0 @@
|
|||
const winType = ["B+R", "B+", "B+T", "W+R", "W+", "W+T", "0", "Void", "?"];
|
||||
|
||||
const rankArray = [
|
||||
"D9",
|
||||
"D8",
|
||||
"D7",
|
||||
"D6",
|
||||
"D5",
|
||||
"D4",
|
||||
"D3",
|
||||
"D2",
|
||||
"D1",
|
||||
"K1",
|
||||
"K2",
|
||||
"K3",
|
||||
"K4",
|
||||
"K5",
|
||||
"K6",
|
||||
"K7",
|
||||
"K8",
|
||||
"K9",
|
||||
"K10",
|
||||
"K11",
|
||||
"K12",
|
||||
"K13",
|
||||
"K14",
|
||||
"K15",
|
||||
"K16",
|
||||
"K17",
|
||||
"K18",
|
||||
"K19",
|
||||
"K20",
|
||||
"K21",
|
||||
"K22",
|
||||
"K23",
|
||||
"K24",
|
||||
"K25",
|
||||
"K26",
|
||||
"K27",
|
||||
"K28",
|
||||
"K29",
|
||||
"K30",
|
||||
"UR",
|
||||
];
|
||||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable("game", (table) => {
|
||||
table.increments("id").primary();
|
||||
table.datetime("date");
|
||||
table.float("komi").default(6.5);
|
||||
table.integer("handicap").default(0);
|
||||
table.integer("board_size").default(19);
|
||||
table.boolean("open").default(true);
|
||||
|
||||
table.string("application");
|
||||
table.string("application_version");
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.string("player_black");
|
||||
table.string("player_white");
|
||||
table.enu("player_black_rank", rankArray).default("UR");
|
||||
table.enu("player_white_rank", rankArray).default("UR");
|
||||
|
||||
table.string("event");
|
||||
table.string("name");
|
||||
table.string("description");
|
||||
table.integer("round");
|
||||
|
||||
table.enu("win_type", winType);
|
||||
table.float("score");
|
||||
table.integer("captures_black");
|
||||
table.integer("captures_white");
|
||||
|
||||
table.integer("user_black").references("id").inTable("user");
|
||||
table.integer("user_white").references("id").inTable("user");
|
||||
table.integer("room").references("id").inTable("room");
|
||||
table.integer("time_setting").references("id").inTable("time_setting");
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists("game");
|
|
@ -1,18 +0,0 @@
|
|||
const players = ["white", "black"];
|
||||
|
||||
exports.up = (knex) => {
|
||||
return knex.schema.createTable("move", (table) => {
|
||||
table.increments("id").primary();
|
||||
table.enu("player", players).notNullable();
|
||||
table.integer("point_x").notNullable();
|
||||
table.integer("point_y").notNullable();
|
||||
table.integer("number").notNullable();
|
||||
table.boolean("game_record").notNullable().default(true);
|
||||
table.boolean("placement").notNullable().default(false);
|
||||
|
||||
table.integer("game").references("id").inTable("game").notNullable();
|
||||
table.integer("prior_move").references("id").inTable("move");
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists("move");
|
|
@ -1,97 +0,0 @@
|
|||
const knex = require("../db");
|
||||
|
||||
const gameDetailSelect = [
|
||||
"game.id",
|
||||
"application",
|
||||
"application_version",
|
||||
"board_size",
|
||||
"komi",
|
||||
"handicap",
|
||||
"open",
|
||||
"win_type",
|
||||
"player_black",
|
||||
"player_black_rank",
|
||||
"player_white",
|
||||
"player_white_rank",
|
||||
"captures_black",
|
||||
"captures_white",
|
||||
"score",
|
||||
"win_type",
|
||||
"description",
|
||||
"event",
|
||||
"round",
|
||||
"name",
|
||||
"room",
|
||||
];
|
||||
|
||||
const timeSettingSelect = [
|
||||
"main_time",
|
||||
"time_period",
|
||||
"period_length",
|
||||
"overtime",
|
||||
"overtime_period",
|
||||
"overtime_length",
|
||||
];
|
||||
|
||||
const gameOverviewSelect = [
|
||||
"id",
|
||||
"board_size",
|
||||
"komi",
|
||||
"handicap",
|
||||
"open",
|
||||
"win_type",
|
||||
"player_black",
|
||||
"player_black_rank",
|
||||
"player_white",
|
||||
"player_white_rank",
|
||||
];
|
||||
|
||||
const findGameById = async function (gameId) {
|
||||
const selection = gameDetailSelect.concat(timeSettingSelect);
|
||||
|
||||
const game = await knex
|
||||
.from("game")
|
||||
.select(selection)
|
||||
.where({ "game.id": gameId })
|
||||
.leftJoin("time_setting", function () {
|
||||
this.on("time_setting.id", "=", "game.time_setting");
|
||||
});
|
||||
|
||||
return game[0];
|
||||
};
|
||||
|
||||
const findGameByRoom = async (roomId) => {
|
||||
const games = await knex("game")
|
||||
.where({ room: roomId })
|
||||
.select(gameOverviewSelect);
|
||||
|
||||
return games;
|
||||
};
|
||||
|
||||
const insertGame = async (game) => {};
|
||||
|
||||
const endGame = async ({ id, winType, score, bCaptures, wCaptures }) => {
|
||||
try {
|
||||
const game = await knex
|
||||
.from("game")
|
||||
.returning(gameDetailSelect)
|
||||
.where({ id: id })
|
||||
.update({
|
||||
win_type: winType,
|
||||
score: score,
|
||||
captures_black: bCaptures,
|
||||
captures_white: wCaptures,
|
||||
open: false,
|
||||
});
|
||||
return game;
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
findGameById,
|
||||
findGameByRoom,
|
||||
insertGame,
|
||||
endGame,
|
||||
};
|
|
@ -1,47 +0,0 @@
|
|||
const knex = require("../db");
|
||||
|
||||
const findGameRecord = async (gameId) => {
|
||||
return await knex("move")
|
||||
.where({ game: gameId, game_record: true })
|
||||
.select("player", "point_x", "point_y", "number", "prior_move", "placement")
|
||||
.orderBy("number")
|
||||
.then((record) =>
|
||||
record.map(({ player, point_x, point_y }) => ({
|
||||
player,
|
||||
pos: { x: point_x, y: point_y },
|
||||
}))
|
||||
);
|
||||
// .then(res => res)
|
||||
};
|
||||
|
||||
// id: 1, player: 'black', point_x: 3, point_y: 3, number: 1, game_record: true, game: 1, prior_move: null
|
||||
|
||||
const addMove = async ({ gameId, player, x, y, gameRecord, priorMove }) => {
|
||||
// ! priorMove must be FK not move number
|
||||
const number = priorMove + 1;
|
||||
let result;
|
||||
try {
|
||||
result = await knex("move")
|
||||
.returning("*")
|
||||
.insert({
|
||||
game: gameId,
|
||||
player,
|
||||
point_x: x,
|
||||
point_y: y,
|
||||
number,
|
||||
game_record: gameRecord,
|
||||
prior_move: priorMove,
|
||||
})
|
||||
.then((res) => res);
|
||||
} catch (e) {
|
||||
result = e;
|
||||
} finally {
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
findGameRecord,
|
||||
addMove,
|
||||
};
|
|
@ -1,72 +0,0 @@
|
|||
exports.seed = async function (knex) {
|
||||
// Deletes ALL existing entries
|
||||
return await knex("game")
|
||||
.del()
|
||||
.then(async function () {
|
||||
// Inserts seed entries
|
||||
await knex("user")
|
||||
.select("id")
|
||||
.orderBy("id")
|
||||
.whereIn("username", ["user-one", "user-two"])
|
||||
.then(async ([userOne, userTwo]) => {
|
||||
const res = await knex("room")
|
||||
.select("id")
|
||||
.where({ name: "main" })
|
||||
.then(([room]) => {
|
||||
console.log("inserting");
|
||||
return knex("game")
|
||||
.insert(
|
||||
[
|
||||
{
|
||||
date: new Date(),
|
||||
application: "node-go",
|
||||
application_version: "0.1.0",
|
||||
player_black: "user-one",
|
||||
player_white: "user-two",
|
||||
player_black_rank: "UR",
|
||||
player_white_rank: "UR",
|
||||
user_black: userOne.id,
|
||||
user_white: userTwo.id,
|
||||
room: room.id,
|
||||
open: false,
|
||||
},
|
||||
{
|
||||
date: new Date(),
|
||||
application: "node-go",
|
||||
application_version: "0.1.0",
|
||||
player_black: "user-one",
|
||||
player_black_rank: "UR",
|
||||
user_black: userTwo.id,
|
||||
room: room.id,
|
||||
open: true,
|
||||
},
|
||||
{
|
||||
date: new Date("1971-05-06"),
|
||||
application: "node-go",
|
||||
application_version: "0.1.0",
|
||||
player_black: "Ishida Yoshio",
|
||||
player_black_rank: "D7",
|
||||
player_white: "Rin Kaiho",
|
||||
player_white_rank: "D9",
|
||||
room: room.id,
|
||||
open: false,
|
||||
event: "",
|
||||
round: 2,
|
||||
win_type: "B+",
|
||||
score: 1.5,
|
||||
},
|
||||
],
|
||||
["*"]
|
||||
)
|
||||
.then((res) => res)
|
||||
.catch((e) => {
|
||||
console.log("error");
|
||||
console.log(e);
|
||||
});
|
||||
})
|
||||
.then((entries) => {
|
||||
console.log({ success: "game", entries });
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
exports.seed = async function(knex) {
|
||||
// Deletes ALL existing entries
|
||||
return await knex('message').del()
|
||||
.then(async function () {
|
||||
// Inserts seed entries
|
||||
await knex('room')
|
||||
.where({name: 'main'})
|
||||
.then(async ([room]) => await knex('user')
|
||||
.where({username: 'user-two'})
|
||||
.then(async ([user]) => {
|
||||
const res = await knex('message')
|
||||
.returning('*')
|
||||
.insert(
|
||||
[
|
||||
{content: 'Hey! Welcome to the general room!', room: room.id, user: user.id}
|
||||
]
|
||||
)
|
||||
.then(entries => {console.log({success: 'message', entries}); return res;})
|
||||
.catch(e => e)
|
||||
return res;
|
||||
}
|
||||
)
|
||||
.then(() => {})
|
||||
).then(() => {})
|
||||
}).then(() => {})
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "independent"
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const app = require("../server");
|
||||
const authController = require("../controllers/auth");
|
||||
const {
|
||||
signupValidationRules,
|
||||
loginValidationRules,
|
||||
validate,
|
||||
} = require("../middleware/userValidator");
|
||||
|
||||
router.post(
|
||||
"/signup",
|
||||
signupValidationRules(),
|
||||
validate,
|
||||
authController.signup
|
||||
);
|
||||
router.post("/login", loginValidationRules(), validate, authController.login);
|
||||
router.post("/guest", authController.guest);
|
||||
|
||||
module.exports = router;
|
|
@ -1,62 +0,0 @@
|
|||
const createError = require("http-errors");
|
||||
const express = require("express");
|
||||
|
||||
const cors = require("cors");
|
||||
|
||||
const path = require("path");
|
||||
const cookieParser = require("cookie-parser");
|
||||
const logger = require("morgan");
|
||||
|
||||
const db = require("./data/db");
|
||||
|
||||
const dotenv = require("dotenv");
|
||||
dotenv.config();
|
||||
|
||||
const indexRouter = require("./routes/index");
|
||||
const usersRouter = require("./routes/users");
|
||||
const authRouter = require("./routes/auth");
|
||||
const apiRouter = require("./routes/api");
|
||||
|
||||
const app = express();
|
||||
|
||||
const allowedOrigin = process.env.REACT_ADDRESS;
|
||||
const corsOptions = {
|
||||
origin: allowedOrigin,
|
||||
credentials: true,
|
||||
methods: "GET,PUT,POST,DELETE",
|
||||
};
|
||||
|
||||
app.options("*", cors(corsOptions));
|
||||
app.use("*", cors(corsOptions));
|
||||
|
||||
// disable logging for tests
|
||||
if (process.env.NODE_ENV !== "test") app.use(logger("dev"));
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, "public")));
|
||||
|
||||
app.use("/", indexRouter);
|
||||
app.use("/users", usersRouter);
|
||||
app.use("/auth", authRouter);
|
||||
// @auth
|
||||
app.use("/api/v1", apiRouter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function (req, res, next) {
|
||||
next(createError(404));
|
||||
});
|
||||
|
||||
// error handler
|
||||
app.use(function (err, req, res, next) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get("env") === "development" ? err : {};
|
||||
|
||||
// render the error page
|
||||
res.status(err.status || 500);
|
||||
res.send("error");
|
||||
});
|
||||
|
||||
module.exports = app;
|
|
@ -1,624 +0,0 @@
|
|||
// index corresponds to difference in player rank
|
||||
const KOMI_REC = {
|
||||
"9": [5.5, 2.5, -0.5, -3.5, -6.5, -9.5, 12.5, 15.5, 18.5, 21.5],
|
||||
"13": [5.5, 0.5, -5.5, 0.5, -5.5, 0.5, -5.5, 0.5, -5.5, 0.5],
|
||||
"19": [7.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
|
||||
};
|
||||
|
||||
const HANDI_REC = {
|
||||
"9": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"13": [0, 0, 0, 2, 2, 3, 3, 4, 4, 5],
|
||||
"19": [0, 0, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
};
|
||||
|
||||
// index represents handicap placement for different board-sizes, eg handiPlace['9][1] = { (3, 3), (7, 7) }
|
||||
// last array in each property also used for hoshi rendering
|
||||
const HANDI_PLACE = {
|
||||
9: [
|
||||
0,
|
||||
0,
|
||||
["7-3", "3-7"], // 2
|
||||
["7-7", "7-3", "3-7"],
|
||||
["3-3", "7-7", "3-7", "7-3"],
|
||||
],
|
||||
13: [
|
||||
0,
|
||||
0,
|
||||
["4-10", "10-4"], // 2
|
||||
["10-10", "4-10", "10-4"],
|
||||
["4-4", "10-10", "4-10", "10-4"],
|
||||
["7-7", "4-4", "10-10", "4-10", "10-4"],
|
||||
["7-4", "4-7", "4-4", "10-10", "4-10", "10-4"],
|
||||
["7-7", "7-4", "4-7", "4-4", "10-10", "4-10", "10-4"],
|
||||
["10-7", "7-4", "7-10", "4-7", "4-4", "10-10", "4-10", "10-4"],
|
||||
["7-7", "10-7", "7-4", "7-10", "4-7", "4-4", "10-10", "4-10", "10-4"],
|
||||
],
|
||||
19: [
|
||||
0,
|
||||
0,
|
||||
["4-16", "16-4"], // 2
|
||||
["16-16", "4-16", "16-4"],
|
||||
["4-4", "16-16", "4-16", "16-4"],
|
||||
["10-10", "4-4", "16-16", "4-16", "16-4"],
|
||||
["10-4", "4-10", "4-4", "16-16", "4-16", "16-4"],
|
||||
["10-10", "10-4", "4-10", "4-4", "16-16", "4-16", "16-4"],
|
||||
["16-10", "10-4", "10-16", "4-10", "4-4", "16-16", "4-16", "16-4"],
|
||||
["10-10", "16-10", "10-4", "10-16", "4-10", "4-4", "16-16", "4-16", "16-4"],
|
||||
],
|
||||
};
|
||||
|
||||
const getSingleItemFromSet = (set) => {
|
||||
let entry;
|
||||
for (entry of set.entries()) {
|
||||
}
|
||||
return entry[0];
|
||||
};
|
||||
|
||||
const pipeMap = (...funcs) => (obj) => {
|
||||
const arr = Object.entries(obj).reduce((acc, [key, value], i, arr) => {
|
||||
funcs.forEach((func) => (value = func(value, i, arr)));
|
||||
return [...acc, [key, value]];
|
||||
}, []);
|
||||
return arr.reduce((acc, [key, value]) => {
|
||||
return { ...acc, [key]: value };
|
||||
}, {});
|
||||
};
|
||||
|
||||
const checkLegal = ({ point, Game }) => {
|
||||
// if stone (includes ko) return false
|
||||
if (point.stone) {
|
||||
point.legal = false;
|
||||
return point;
|
||||
}
|
||||
const neighbors = getNeighbors({ Game, point });
|
||||
|
||||
const isEmpty = (point) => point.stone === 0 && point.legal === true;
|
||||
const isEmptyAdjacent = neighbors.filter(isEmpty);
|
||||
|
||||
// if empty point adjacent return true
|
||||
if (!isEmptyAdjacent.length) {
|
||||
// if group has liberties return true
|
||||
const isTurnStone = (neighbor) => neighbor.stone === Game.turn;
|
||||
const getGroupLiberties = (point) =>
|
||||
Array.from(Game.groups[point.group].liberties);
|
||||
const isNotSamePoint = (liberty) =>
|
||||
!(liberty.pos.x === point.pos.x && liberty.pos.y === point.pos.y);
|
||||
const isInGroupWithLiberties = (neighbor) =>
|
||||
getGroupLiberties(neighbor).filter(isNotSamePoint).length;
|
||||
const isInLiveGroup = neighbors
|
||||
.filter(isTurnStone)
|
||||
.filter(isInGroupWithLiberties).length;
|
||||
|
||||
if (isInLiveGroup) {
|
||||
point.legal = true;
|
||||
return point;
|
||||
}
|
||||
|
||||
// if move would capture opposing group return true
|
||||
if (point.capturing[Game.turn].size) {
|
||||
point.legal = true;
|
||||
return point;
|
||||
}
|
||||
|
||||
point.legal = false;
|
||||
return point;
|
||||
}
|
||||
point.legal = true;
|
||||
return point;
|
||||
};
|
||||
|
||||
const getBoardState = (Game) => {
|
||||
const getLegal = (point) => checkLegal({ point, Game });
|
||||
const boardState = pipeMap(getLegal)(Game.boardState);
|
||||
Game.kos.forEach((ko) => {
|
||||
boardState[ko].legal = false;
|
||||
});
|
||||
return boardState;
|
||||
};
|
||||
|
||||
const getLegalMoves = (Game) => {
|
||||
const mapLegal = (point) => (point.legal ? "l" : point.stone);
|
||||
const legalMoves = pipeMap(mapLegal)(Game.boardState);
|
||||
Game.kos.forEach((ko) => {
|
||||
legalMoves[ko] = "k";
|
||||
});
|
||||
return legalMoves;
|
||||
};
|
||||
|
||||
const getTerritory = (Game) => {
|
||||
const mapTerritory = (point) => {
|
||||
if (point.territory === "d") return "d";
|
||||
if (point.territory > 0) return 1;
|
||||
if (point.territory < 0) return -1;
|
||||
};
|
||||
const territory = pipeMap(mapTerritory)(Game.boardState);
|
||||
return territory;
|
||||
};
|
||||
|
||||
const getNeighbors = ({ Game, point }) => {
|
||||
let { top = null, btm = null, lft = null, rgt = null } = point.neighbors;
|
||||
const { boardState, boardSize } = Game;
|
||||
// boardState[0] = [ '1-1', Point({x:1, y:1, boardSize}) ]
|
||||
if (top) top = boardState[top];
|
||||
if (btm) btm = boardState[btm];
|
||||
if (lft) lft = boardState[lft];
|
||||
if (rgt) rgt = boardState[rgt];
|
||||
return [top, btm, lft, rgt].filter((value) => value);
|
||||
};
|
||||
|
||||
const initBoard = (game) => {
|
||||
const boardState = {};
|
||||
const { boardSize, handicap } = game;
|
||||
for (let i = 0; i < Math.pow(boardSize, 2); i++) {
|
||||
const point = Point({
|
||||
x: Math.floor(i / boardSize) + 1,
|
||||
y: (i % boardSize) + 1,
|
||||
boardSize,
|
||||
});
|
||||
boardState[`${point.pos.x}-${point.pos.y}`] = point;
|
||||
}
|
||||
|
||||
if (handicap) {
|
||||
HANDI_PLACE[boardSize][handicap].forEach((pt) => {
|
||||
boardState[pt].makeMove({ ...game, boardState });
|
||||
});
|
||||
game.turn *= -1;
|
||||
}
|
||||
return boardState;
|
||||
};
|
||||
|
||||
// returns Game object
|
||||
const Game = ({ gameData = {}, gameRecord = [] } = {}) => {
|
||||
const helper = {
|
||||
clearKo: function () {
|
||||
this.kos.forEach((ko) => {
|
||||
this.boardState[ko] = {
|
||||
...this.boardState[ko],
|
||||
legal: true,
|
||||
ko: false,
|
||||
};
|
||||
});
|
||||
this.kos = [];
|
||||
},
|
||||
};
|
||||
if (gameRecord.length) {
|
||||
// play through all the moves
|
||||
const game = gameRecord.reduce(
|
||||
(game, move) => game.makeMove(move),
|
||||
Game({ gameData }).initGame()
|
||||
);
|
||||
// ? why is this being wrapped?
|
||||
if (gameData && gameData.gameData && gameData.gameData.winner) {
|
||||
const { winner, score } = gameData.gameData;
|
||||
return game.manualEnd({ winner, score });
|
||||
}
|
||||
return game;
|
||||
}
|
||||
return {
|
||||
winner: gameData.winner || null,
|
||||
turn: gameData.turn || 0, // turn logic depends on handicap stones
|
||||
pass: gameData.pass || 0, // -1 represents state in which resignation has been submitted, not confirmed
|
||||
komi: gameData.komi || 6.5, // komi depends on handicap stones + player rank
|
||||
handicap: gameData.handicap || 0,
|
||||
boardSize: gameData.boardSize || 19,
|
||||
score: 0,
|
||||
groups: {}, // key is Symbol(position): {points: Set(), liberties: Set()}
|
||||
boardState: {},
|
||||
territory: {},
|
||||
kos: [],
|
||||
gameRecord: gameRecord,
|
||||
playerState: gameData.playerState || {
|
||||
bCaptures: 0,
|
||||
wCaptures: 0,
|
||||
bScore: 0,
|
||||
wScore: 0,
|
||||
},
|
||||
|
||||
initGame: function () {
|
||||
this.winner = null;
|
||||
this.pass = 0;
|
||||
this.turn = 1;
|
||||
this.boardState = initBoard(this);
|
||||
this.boardState = getBoardState(this);
|
||||
this.legalMoves = getLegalMoves(this);
|
||||
return this;
|
||||
},
|
||||
|
||||
addToRecord: function (moveObject) {
|
||||
this.gameRecord.push(moveObject);
|
||||
},
|
||||
|
||||
getMeta: function () {
|
||||
// cannot be chained
|
||||
// does not affect game object
|
||||
return {
|
||||
winner: this.winner,
|
||||
turn: this.turn,
|
||||
pass: this.pass,
|
||||
playerState: this.playerState,
|
||||
gameRecord: this.gameRecord,
|
||||
boardSize: this.boardSize,
|
||||
handicap: this.handicap,
|
||||
komi: this.komi,
|
||||
score: this.score,
|
||||
};
|
||||
},
|
||||
|
||||
checkMove: function ({ player, pos: { x, y } }) {
|
||||
// if game is over
|
||||
// TODO either change logic here or add additional method for handling moves off of record
|
||||
if (this.pass > 1) {
|
||||
return { ...this, success: false };
|
||||
}
|
||||
const point = this.boardState[`${x}-${y}`];
|
||||
const isTurn =
|
||||
(this.turn === 1 && player === "black") ||
|
||||
(this.turn === -1 && player === "white");
|
||||
if (isTurn) {
|
||||
if (point.legal) {
|
||||
return { ...this, success: true, move: { player, pos: { x, y } } };
|
||||
}
|
||||
}
|
||||
return { ...this, success: false };
|
||||
},
|
||||
|
||||
makeMove: function ({ player, pos: { x, y } }) {
|
||||
if (this.pass > 1) {
|
||||
return { ...this, success: false };
|
||||
}
|
||||
|
||||
let success = false;
|
||||
let game = this;
|
||||
|
||||
if (x === 0) return game.submitPass(player);
|
||||
|
||||
// if checkMove has not been run, determine legality
|
||||
if (!game.move) {
|
||||
game = game.checkMove({ player, pos: { x, y } });
|
||||
}
|
||||
if (
|
||||
// if move is legal
|
||||
// ? unclear if checking move values is beneficial to prevent race conditions
|
||||
game.move &&
|
||||
game.move.player === player &&
|
||||
game.move.pos.x === x &&
|
||||
game.move.pos.y
|
||||
) {
|
||||
const point = game.boardState[`${x}-${y}`];
|
||||
game.pass = 0;
|
||||
// allows for recording of prior move on game record
|
||||
game.addToRecord(game.move);
|
||||
if (game.kos.length) helper.clearKo.call(game);
|
||||
point.makeMove(game);
|
||||
game.turn *= -1;
|
||||
success = true;
|
||||
}
|
||||
game.boardState = getBoardState(game);
|
||||
// remove move attribute to prevent duplicate moves
|
||||
delete game.move;
|
||||
return { ...game, legalMoves: getLegalMoves(game), success };
|
||||
},
|
||||
|
||||
initGroup: function (point) {
|
||||
const group = Symbol(`${point.pos.x}-${point.pos.y}`);
|
||||
this.groups[group] = { stones: new Set(), liberties: new Set() };
|
||||
return { game: this, group };
|
||||
},
|
||||
|
||||
returnToMove: function (lastMove) {
|
||||
const { komi, handicap, boardSize } = this;
|
||||
if (lastMove === 0) {
|
||||
return Game({
|
||||
gameData: { komi, handicap, boardSize },
|
||||
}).initGame();
|
||||
}
|
||||
const length = this.gameRecord.length;
|
||||
const index = lastMove < 0 ? length + lastMove : lastMove;
|
||||
if (lastMove >= length && lastMove > 0) return this;
|
||||
return Game({
|
||||
gameData: { komi, handicap, boardSize },
|
||||
gameRecord: [...this.gameRecord.slice(0, index)],
|
||||
});
|
||||
},
|
||||
|
||||
submitPass: function (player) {
|
||||
if (player !== "black" && player !== "white") {
|
||||
return { ...this, success: false };
|
||||
}
|
||||
if (this.pass > 0) {
|
||||
return this.calculateTerritory();
|
||||
}
|
||||
this.pass = 1;
|
||||
this.addToRecord({ player, pos: { x: null, y: null } });
|
||||
if (this.kos.length) helper.clearKo.call(this);
|
||||
this.turn = player === "black" ? -1 : 1;
|
||||
this.boardState = getBoardState(this);
|
||||
return { ...this, legalMoves: getLegalMoves(this), success: true };
|
||||
},
|
||||
|
||||
submitResign: function (player) {
|
||||
if (player === "black") this.winner = -1;
|
||||
if (player === "white") this.winner = 1;
|
||||
this.turn = 0;
|
||||
return this;
|
||||
},
|
||||
|
||||
calculateTerritory: function () {
|
||||
// TODO manage territory counting
|
||||
// form groups for empty points
|
||||
const joinEmptyPoints = (point) => {
|
||||
if (point.stone) return point;
|
||||
point.joinEmptyPoints({ point, Game: this });
|
||||
return point;
|
||||
};
|
||||
// for each point determine territory
|
||||
const determineTerritory = (point) => {
|
||||
if (point.stone || point.territory) return point;
|
||||
const points = Array.from(this.groups[point.group].stones);
|
||||
const neighbors = points.flatMap((pt) =>
|
||||
getNeighbors({ Game: this, point: pt })
|
||||
);
|
||||
const stones = neighbors.filter((point) => point.stone !== 0);
|
||||
point.territory =
|
||||
stones.reduce((acc, { stone }) => acc + stone, 0) || "d";
|
||||
return point;
|
||||
};
|
||||
// for each non-empty point group determine life
|
||||
const determineLife = (point) => {
|
||||
if (!point.stone || point.territory) return point;
|
||||
const liberties = Array.from(this.groups[point.group].liberties);
|
||||
point.territory =
|
||||
liberties.reduce(
|
||||
(acc, { territory }) => (territory === "d" ? acc : acc + territory),
|
||||
0
|
||||
) || point.stone;
|
||||
return point;
|
||||
};
|
||||
let boardState = pipeMap(joinEmptyPoints)(this.boardState);
|
||||
boardState = pipeMap(determineTerritory)(boardState);
|
||||
boardState = pipeMap(determineLife)(boardState);
|
||||
this.boardState = boardState;
|
||||
// submit board state to users
|
||||
this.turn = 0;
|
||||
return { ...this, territory: getTerritory(this) };
|
||||
},
|
||||
|
||||
toggleTerritory: function (key) {
|
||||
if (this.turn) return { ...this, success: false };
|
||||
const groupKey = this.boardState[key].group;
|
||||
const group = this.groups[groupKey];
|
||||
const newStones = Array.from(group.stones).forEach((point) => {
|
||||
// console.log(point);
|
||||
if (point.stone) {
|
||||
return (point.territory = -1 * point.territory);
|
||||
}
|
||||
if (point.territory === "d") return (point.territory = 1);
|
||||
if (point.territory > 0) return (point.territory = -1);
|
||||
if (point.territory < 0) return (point.territory = "d");
|
||||
});
|
||||
this.groups[groupKey];
|
||||
return { ...this, territory: getTerritory(this) };
|
||||
},
|
||||
|
||||
endGame: function () {
|
||||
// if boardState is approved calculate winner
|
||||
const [blackTerritory, whiteTerritory] = Object.values(
|
||||
this.boardState
|
||||
).reduce(
|
||||
([blackTerritory, whiteTerritory], { territory, stone }) => {
|
||||
if (territory === "d") return [blackTerritory, whiteTerritory];
|
||||
if (territory > 0) {
|
||||
if (stone === -1) return [blackTerritory + 2, whiteTerritory];
|
||||
return [blackTerritory + 1, whiteTerritory];
|
||||
}
|
||||
if (territory < 0) {
|
||||
if (stone === 1) return [blackTerritory, whiteTerritory + 2];
|
||||
return [blackTerritory, whiteTerritory + 1];
|
||||
}
|
||||
},
|
||||
[0, 0]
|
||||
);
|
||||
this.playerState.bScore = blackTerritory + this.playerState.bCaptures;
|
||||
this.playerState.wScore = whiteTerritory + this.playerState.wCaptures;
|
||||
const score =
|
||||
this.playerState.bScore - (this.playerState.wScore + this.komi);
|
||||
return { ...this, score, winner: score > 0 ? 1 : -1 };
|
||||
},
|
||||
|
||||
// for playing historic games
|
||||
manualEnd: function ({ winner, score }) {
|
||||
this.turn = 0;
|
||||
this.winner = winner;
|
||||
this.score = score;
|
||||
return this;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const Point = ({ x, y, boardSize = 19 }) => {
|
||||
let point = {
|
||||
pos: { x, y },
|
||||
key: `${x}-${y}`,
|
||||
stone: 0, // can be 1, -1, 0,
|
||||
ko: false,
|
||||
legal: true,
|
||||
territory: 0,
|
||||
capturing: {
|
||||
"1": new Set(),
|
||||
"-1": new Set(),
|
||||
},
|
||||
group: null,
|
||||
neighbors: {
|
||||
top: x > 1 ? `${x - 1}-${y}` : null,
|
||||
btm: x < boardSize ? `${x + 1}-${y}` : null,
|
||||
rgt: y < boardSize ? `${x}-${y + 1}` : null,
|
||||
lft: y > 1 ? `${x}-${y - 1}` : null,
|
||||
},
|
||||
|
||||
makeMove: function (Game) {
|
||||
this.stone = Game.turn;
|
||||
this.legal = false;
|
||||
if (this.capturing[this.stone].size) {
|
||||
Game = this.makeCaptures(Game);
|
||||
}
|
||||
Game = this.joinGroup({ point: this, Game });
|
||||
return this.checkCaptures(Game);
|
||||
},
|
||||
|
||||
joinGroup: function ({ point, Game }) {
|
||||
if (point.group !== this.group || !point.group) {
|
||||
// if point has no group set current group to new Symbol in game object
|
||||
if (!point.group) {
|
||||
const { game, group } = Game.initGroup(point);
|
||||
this.group = group;
|
||||
Game = game;
|
||||
}
|
||||
|
||||
// add current point to global group and override current group
|
||||
Game.groups[point.group].stones.add(this);
|
||||
if (this.group !== point.group) {
|
||||
this.group = point.group;
|
||||
}
|
||||
Game = this.setLiberties(Game);
|
||||
getNeighbors({ point: this, Game }).forEach((neighbor) => {
|
||||
if (
|
||||
neighbor.stone === this.stone &&
|
||||
// this check prevents infinite call chains
|
||||
neighbor.group !== this.group
|
||||
) {
|
||||
Game = neighbor.joinGroup({ point: this, Game });
|
||||
}
|
||||
});
|
||||
}
|
||||
return Game;
|
||||
},
|
||||
|
||||
joinEmptyPoints: function ({ point, Game }) {
|
||||
if (point.group !== this.group || !point.group) {
|
||||
if (!point.group) {
|
||||
const { game, group } = Game.initGroup(point);
|
||||
this.group = group;
|
||||
Game = game;
|
||||
}
|
||||
Game.groups[point.group].stones.add(this);
|
||||
if (this.group !== point.group) {
|
||||
this.group = point.group;
|
||||
}
|
||||
getNeighbors({ point: this, Game }).forEach((neighbor) => {
|
||||
if (
|
||||
neighbor.stone === this.stone &&
|
||||
// this check prevents infinite call chains
|
||||
neighbor.group !== this.group
|
||||
) {
|
||||
Game = neighbor.joinEmptyPoints({ point: this, Game });
|
||||
}
|
||||
});
|
||||
return Game;
|
||||
}
|
||||
},
|
||||
|
||||
setLiberties: function (Game) {
|
||||
const neighbors = getNeighbors({ point: this, Game });
|
||||
const liberties = Game.groups[this.group].liberties;
|
||||
// if point is occupied remove it from liberties set of point group, else add it
|
||||
neighbors.forEach((neighbor) => {
|
||||
if (neighbor.stone !== 0) {
|
||||
liberties.delete(neighbor);
|
||||
Game.groups[neighbor.group].liberties.delete(this);
|
||||
}
|
||||
if (neighbor.stone === 0) {
|
||||
liberties.add(neighbor);
|
||||
}
|
||||
});
|
||||
return Game;
|
||||
},
|
||||
|
||||
checkCaptures: function (game) {
|
||||
// if this stone has one liberty
|
||||
const liberties = game.groups[this.group].liberties;
|
||||
if (liberties.size === 1) {
|
||||
const lastLiberty = getSingleItemFromSet(liberties);
|
||||
lastLiberty.capturing[this.stone * -1].add(this.group);
|
||||
}
|
||||
if (liberties.size > 1) {
|
||||
liberties.forEach((liberty) =>
|
||||
liberty.capturing[this.stone * -1].delete(this.group)
|
||||
);
|
||||
}
|
||||
|
||||
// if neighbors have one liberty
|
||||
const neighbors = getNeighbors({ point: this, Game: game }).filter(
|
||||
(neighbor) => neighbor.stone === -1 * this.stone
|
||||
);
|
||||
neighbors.forEach((neighbor) => {
|
||||
const liberties =
|
||||
game.groups[neighbor.group] && game.groups[neighbor.group].liberties;
|
||||
if (liberties && liberties.size === 1) {
|
||||
const lastLiberty = getSingleItemFromSet(liberties);
|
||||
lastLiberty.capturing[neighbor.stone * -1].add(neighbor.group);
|
||||
}
|
||||
});
|
||||
return game;
|
||||
},
|
||||
|
||||
makeCaptures: function (game) {
|
||||
// for each group
|
||||
for (let [captureGroup, _] of this.capturing[this.stone].entries()) {
|
||||
const capturesSet = game.groups[captureGroup].stones;
|
||||
for (let [capture, _] of capturesSet.entries()) {
|
||||
game = capture.removeStone(game);
|
||||
if (capturesSet.size === 1) {
|
||||
const neighbors = getNeighbors({ point: this, Game: game });
|
||||
const liberties = neighbors.filter(
|
||||
(neighbor) => neighbor.stone === 0
|
||||
);
|
||||
const groupStones = neighbors.filter(
|
||||
(neighbor) => neighbor.stone === this.stone
|
||||
);
|
||||
if (liberties.length === 1 && groupStones.length === 0) {
|
||||
capture.ko = true;
|
||||
game.kos.push(capture.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// points with stones cannot be played to capture
|
||||
this.capturing = { "1": new Set(), "-1": new Set() };
|
||||
return { ...game, boardState: { ...game.boardState, [this.key]: this } };
|
||||
},
|
||||
|
||||
removeStone: function (game) {
|
||||
if ((this.stone = 0)) {
|
||||
return game;
|
||||
}
|
||||
// reset point
|
||||
this.stone = 0;
|
||||
this.group = null;
|
||||
this.capturing[game.turn] = new Set();
|
||||
// add captures
|
||||
const player = game.turn > 0 ? "b" : "w";
|
||||
game.playerState[`${player}Captures`] += 1;
|
||||
|
||||
// add as liberty to neighbors
|
||||
const neighbors = getNeighbors({ point: this, Game: game }).filter(
|
||||
(neighbor) => neighbor.stone !== 0 && neighbor.group
|
||||
);
|
||||
neighbors.forEach((neighbor) => {
|
||||
game.groups[neighbor.group].liberties.add(this);
|
||||
neighbor.checkCaptures(game);
|
||||
});
|
||||
|
||||
return { ...game, boardState: { ...game.boardState, [this.key]: this } };
|
||||
},
|
||||
};
|
||||
for (let [key, value] of Object.entries(point.neighbors)) {
|
||||
if (value) continue;
|
||||
delete point.neighbors[key];
|
||||
}
|
||||
return point;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Game,
|
||||
Point,
|
||||
};
|
|
@ -1,422 +0,0 @@
|
|||
/*----- constants -----*/
|
||||
const STONES_DATA = {
|
||||
'-1': 'white',
|
||||
'0': 'none',
|
||||
'1': 'black',
|
||||
'k': 'ko'
|
||||
}
|
||||
|
||||
|
||||
// index corresponds to difference in player rank
|
||||
const KOMI_REC = {
|
||||
'9': [
|
||||
5.5, 2.5, -0.5, -3.5, -6.5, -9.5, 12.5, 15.5, 18.5, 21.5
|
||||
],
|
||||
'13': [
|
||||
5.5, 0.5, -5.5, 0.5, -5.5, 0.5, -5.5, 0.5, -5.5, 0.5
|
||||
],
|
||||
'19': [
|
||||
7.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5
|
||||
]
|
||||
}
|
||||
|
||||
const HANDI_REC = {
|
||||
'9': [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
],
|
||||
'13': [
|
||||
0, 0, 0, 2, 2, 3, 3, 4, 4, 5
|
||||
],
|
||||
'19': [
|
||||
0, 0, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
]
|
||||
}
|
||||
|
||||
// index represents handicap placement for different board-sizes, eg handiPlace['9][1] = { (3, 3), (7, 7) }
|
||||
// last array in each property also used for hoshi rendering
|
||||
const HANDI_PLACE = {
|
||||
'9' : [
|
||||
0, 0,
|
||||
[[ 7, 3 ], [ 3, 7 ] ],
|
||||
[ [ 7, 7 ], [ 7, 3 ], [ 3, 7 ] ],
|
||||
[ [ 3, 3 ], [ 7, 7 ], [ 3, 7 ], [ 7, 3 ] ]
|
||||
],
|
||||
'13' : [
|
||||
0, 0,
|
||||
[ [ 4, 10 ], [ 10, 4 ] ],
|
||||
[ [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
[ [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
[ [ 7, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
[ [ 7, 4 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
[ [ 7, 7 ], [ 7, 4 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
[ [ 10, 7 ], [ 7, 4 ], [ 7, 10 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
[ [ 7, 7 ], [ 10, 7 ], [ 7, 4 ], [ 7, 10 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||
],
|
||||
'19' : [
|
||||
0, 0,
|
||||
[ [ 4, 16 ], [ 16, 4 ] ],
|
||||
[ [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
[ [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
[ [ 10, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
[ [ 10, 4 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
[ [ 10, 10 ], [ 10, 4 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
[ [ 16, 10 ], [ 10, 4 ], [ 10, 16 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
[ [ 10, 10 ], [ 16, 10 ], [ 10, 4 ], [ 10, 16 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||
]
|
||||
};
|
||||
|
||||
class Game {
|
||||
constructor(gameData, gameRecord) {
|
||||
this.winner = gameData.winner || null,
|
||||
this.turn = gameData.turn || 1, // turn logic depends on handicap stones
|
||||
this.pass = gameData.pass || 0, // -1 represents state in which resignation has been submitted, not confirmed
|
||||
this.komi = gameData.komi || 6.5, // komi depends on handicap stones + player rank
|
||||
this.handicap = gameData.handicap || 0,
|
||||
this.boardSize = gameData.boardSize || 19,
|
||||
this.groups = {},
|
||||
this.boardState = [],
|
||||
this.gameRecord = gameRecord || [],
|
||||
this.playerState = gameData.playerState || {
|
||||
bCaptures: 0,
|
||||
wCaptures: 0,
|
||||
bScore: 0,
|
||||
wScore: 0
|
||||
}
|
||||
}
|
||||
|
||||
initGame = () => {
|
||||
this.winner = null;
|
||||
this.pass = null;
|
||||
this.turn = this.handicap ? -1 : 1;
|
||||
|
||||
this.initBoard();
|
||||
return this.getBoardState();
|
||||
}
|
||||
|
||||
initBoard = () => {
|
||||
let i = 0;
|
||||
while (i < this.boardSize * this.boardSize) {
|
||||
let point = new Point( Math.floor(i / this.boardSize) + 1, i % this.boardSize + 1, this)
|
||||
this.boardState.push(point);
|
||||
i++;
|
||||
}
|
||||
this.initHandi();
|
||||
}
|
||||
|
||||
initHandi = () => {
|
||||
if (this.handicap < 2) return;
|
||||
HANDI_PLACE[this.boardSize][this.handicap].forEach(pt => {
|
||||
if (!pt) return;
|
||||
let handi = this.findPointFromIdx(pt);
|
||||
handi.stone = 1;
|
||||
handi.joinGroup(this);
|
||||
})
|
||||
}
|
||||
|
||||
getBoardState = () => {
|
||||
this.boardState.forEach(point => point.legal = checkLegal(point, this))
|
||||
return this.boardState.reduce((boardState, point) => {
|
||||
boardState[`${point.pos[0]}-${point.pos[1]}`] = point.legal || point.stone;
|
||||
return boardState;
|
||||
}, {})
|
||||
}
|
||||
|
||||
getMeta = () => {
|
||||
return { winner: this.winner, turn: this.turn, pass: this.pass, playerState: this.playerState, gameRecord: this.gameRecord }
|
||||
}
|
||||
|
||||
findPointFromIdx = (arr) => {
|
||||
return this.boardState.find( point => point.pos[0] === arr[0] && point.pos[1] === arr[1] );
|
||||
}
|
||||
|
||||
makeMove = (move) => {
|
||||
const player = move.player === 'white' ? -1 : 1;
|
||||
const point = this.findPointFromIdx([move.pos.x, move.pos.y])
|
||||
if ( !checkLegal(point, this) ) throw Error('illegal move');
|
||||
clearKo(this);
|
||||
clearPass(this);
|
||||
resolveCaptures(point, this);
|
||||
point.stone = this.turn;
|
||||
point.joinGroup(this);
|
||||
clearCaptures(this);
|
||||
this.gameRecord.push(move)
|
||||
this.turn*= -1;
|
||||
return { board: this.getBoardState(), meta: this.getMeta()};
|
||||
}
|
||||
|
||||
clickBoard = (evt) => {
|
||||
evt.stopPropagation();
|
||||
if (gameState.pass > 1 || gameState.winner) return editTerritory(evt);
|
||||
// checks for placement and pushes to cell
|
||||
let placement = [ parseInt(evt.target.closest('td').id.split('-')[0]), parseInt(evt.target.closest('td').id.split('-')[1]) ];
|
||||
let point = findPointFromIdx(placement);
|
||||
//checks that this placement was marked as legal
|
||||
if ( !checkLegal(point) ) return;
|
||||
clearKo();
|
||||
clearPass();
|
||||
resolveCaptures(point);
|
||||
point.stone = gameState.turn;
|
||||
point.joinGroup();
|
||||
playSound(point);
|
||||
clearCaptures();
|
||||
gameState.gameRecord.push(`${STONES_DATA[gameState.turn]}: ${point.pos}`)
|
||||
gameState.turn*= -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Point {
|
||||
constructor(x, y, Game) {
|
||||
this.pos = [ x, y ]
|
||||
this.stone = 0; // this is where move placement will go 0, 1, -1, also contains ko: 'k'
|
||||
this.legal;
|
||||
this.territory;
|
||||
this.capturing = [];
|
||||
this.groupMembers = [ this ];
|
||||
this.neighbors = {
|
||||
top: {},
|
||||
btm: {},
|
||||
lft: {},
|
||||
rgt: {}
|
||||
}
|
||||
this.neighbors.top = x > 1 ? [ x - 1, y ] : null;
|
||||
this.neighbors.btm = x < Game.boardSize ? [ x + 1, y ] : null;
|
||||
this.neighbors.rgt = y < Game.boardSize ? [ x, y + 1 ] : null;
|
||||
this.neighbors.lft = y > 1 ? [ x, y - 1 ] : null;
|
||||
}
|
||||
|
||||
checkNeighbors = (Game) => {
|
||||
let neighborsArr = [];
|
||||
for (let neighbor in this.neighbors) {
|
||||
let nbr = this.neighbors[neighbor];
|
||||
// neighbor exists it's point is stored as { rPos, cPos}
|
||||
if ( nbr !== null ) {
|
||||
neighborsArr.push(Game.boardState.find(pt => pt.pos[0] === nbr[0] && pt.pos[1] === nbr[1]))
|
||||
}
|
||||
};
|
||||
// returns array of existing neighbors to calling function
|
||||
return neighborsArr;
|
||||
}
|
||||
|
||||
getLiberties = (Game) => {
|
||||
let neighborsArr = this.checkNeighbors(Game).filter(pt => pt.stone === 0);
|
||||
return neighborsArr;
|
||||
}
|
||||
|
||||
joinGroup = (Game) => {
|
||||
this.groupMembers = this.groupMembers.filter(grp => grp.stone === this.stone);
|
||||
this.groupMembers.push(this);
|
||||
let frns = this.checkNeighbors(Game).filter(nbr => nbr.stone === this.stone);
|
||||
for (let frn of frns) {
|
||||
this.groupMembers.push(frn);
|
||||
}
|
||||
this.groupMembers = Array.from(new Set(this.groupMembers));
|
||||
for (let grpMem in this.groupMembers) {
|
||||
this.groupMembers = Array.from(new Set(this.groupMembers.concat(this.groupMembers[grpMem].groupMembers)));
|
||||
}
|
||||
for (let grpMem in this.groupMembers) {
|
||||
this.groupMembers[grpMem].groupMembers = Array.from(new Set(this.groupMembers[grpMem].groupMembers.concat(this.groupMembers)));
|
||||
}
|
||||
}
|
||||
|
||||
checkCapture = (Game) => {
|
||||
let opps = this.checkNeighbors(Game).filter(nbr => nbr.stone === Game.turn * -1
|
||||
&& nbr.getLiberties(Game).every(liberty => liberty === this));
|
||||
for (let opp of opps) {
|
||||
if (opp.groupMembers.every(stone => stone.getLiberties().filter(liberty => liberty !== this).length === 0)) {
|
||||
this.capturing = this.capturing.concat(opp.groupMembers);
|
||||
};
|
||||
}
|
||||
this.capturing = Array.from(new Set(this.capturing));
|
||||
return this.capturing;
|
||||
}
|
||||
|
||||
checkGroup = () => { // liberty is true when called by move false when called by check Capture
|
||||
let frns = this.checkNeighbors().filter(nbr => nbr.stone === gameState.turn);
|
||||
for (let frn in frns) {
|
||||
if (frns[frn].groupMembers.find(stone => stone.getLiberties().find(liberty => liberty !== this))) return true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
cycleTerritory = () => {
|
||||
if (this.stone) {
|
||||
this.groupMembers.forEach(pt => pt.territory = pt.territory * -1);
|
||||
} else {
|
||||
this.groupMembers.forEach(pt => {
|
||||
switch (pt.territory) {
|
||||
case 1:
|
||||
pt.territory = -1;
|
||||
break;
|
||||
case -1:
|
||||
pt.territory = 'd';
|
||||
break;
|
||||
case 'd':
|
||||
pt.territory = 1;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function clearKo(Game) {
|
||||
for (let point in Game.boardState) {
|
||||
point = Game.boardState[point];
|
||||
point.stone = point.stone === 'k' ? 0 : point.stone;
|
||||
}
|
||||
}
|
||||
|
||||
function clearPass(Game) {
|
||||
Game.pass = 0;
|
||||
}
|
||||
|
||||
function resolveCaptures(point, Game) {
|
||||
if(!point.capturing.length) {
|
||||
point.checkCapture(Game);
|
||||
}
|
||||
if(point.capturing.length) {
|
||||
point.capturing.forEach(cap => {
|
||||
Game.playerState[gameState.turn > 0 ? 'bCaptures' : 'wCaptures']++;
|
||||
cap.stone = checkKo(point) ? 'k' : 0;
|
||||
cap.groupMembers = [];
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function checkLegal(point, Game) {
|
||||
// clearOverlay();
|
||||
// first step in logic: is point occupied, or in ko
|
||||
if (point.stone) return 0;
|
||||
// if point is not empty check if liberties
|
||||
if (point.getLiberties(Game).length < 1) {
|
||||
//if no liberties check if enemy group has liberties
|
||||
if ( point.checkCapture(Game).length ) return 'l';
|
||||
//if neighboring point is not empty check if friendly group is alive
|
||||
if (point.checkGroup(Game)) return 'l';
|
||||
return 0;
|
||||
}
|
||||
return 'l';
|
||||
}
|
||||
|
||||
function clearOverlay() {
|
||||
for (let point in boardState) {
|
||||
point = boardState[point];
|
||||
point.legal = false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkKo(point) { // currently prevents snapback // capturing point has no liberties and is only capturing one stone and
|
||||
if (!point.getLiberties().length && point.capturing.length === 1 && !point.checkNeighbors().some(stone => stone.stone === gameState.turn)) return true;
|
||||
}
|
||||
|
||||
|
||||
function clearCaptures(Game) {
|
||||
for (let point in Game.boardState) {
|
||||
point = Game.boardState[point];
|
||||
point.capturing = [];
|
||||
}
|
||||
}
|
||||
|
||||
function playerPass() {
|
||||
// display confirmation message
|
||||
clearKo();
|
||||
clearCaptures();
|
||||
gameState.gameRecord.push(`${STONES_DATA[gameState.turn]}: pass`)
|
||||
gameState.pass++;
|
||||
if (gameState.pass === 2) return endGame();
|
||||
gameState.turn*= -1;
|
||||
}
|
||||
|
||||
|
||||
/*----- endgame functions -----*/
|
||||
|
||||
function playerResign() {
|
||||
// display confirmation message
|
||||
gameState.pass = -1;
|
||||
}
|
||||
|
||||
function clickGameHud() {
|
||||
if (gameState.pass > 1 && !gameState.winner) calculateWinner();
|
||||
if (gameState.pass < 0) confirmResign();
|
||||
}
|
||||
|
||||
function confirmResign() {
|
||||
gameState.gameRecord.push(`${STONES_DATA[gameState.turn]}: resign`);
|
||||
gameState.winner = STONES_DATA[gameState.turn * -1];
|
||||
endGame();
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
if (!gameState.winner) endGameSetTerritory()
|
||||
}
|
||||
|
||||
function calculateWinner() {
|
||||
let whiteTerritory = boardState.reduce((acc, pt) => {
|
||||
if (pt.territory === -1 && pt.stone !== -1) {
|
||||
return acc = acc + (pt.stone === 0 ? 1 : 2);
|
||||
}
|
||||
return acc;
|
||||
}, 0);
|
||||
let blackTerritory = boardState.reduce((acc, pt) => {
|
||||
if (pt.territory === 1 && pt.stone !== 1) {
|
||||
return acc + (pt.stone === 0 ? 1 : 2);
|
||||
}
|
||||
return acc;
|
||||
}, 0);
|
||||
gameState.playerState.wScore =
|
||||
gameState.playerState.wCaptures
|
||||
+ (gameState.komi < 0 ? gameState.komi * -1 : 0)
|
||||
+ whiteTerritory;
|
||||
gameState.playerState.bScore =
|
||||
gameState.playerState.bCaptures
|
||||
+ (gameState.komi > 0 ? gameState.komi : 0)
|
||||
+ blackTerritory;
|
||||
gameState.winner = gameState.playerState.wScore > gameState.playerState.bScore ? -1 : 1;
|
||||
gameState.gameRecord.push(`${STONES_DATA[gameState.winner]}: +${Math.abs(gameState.playerState.wScore - gameState.playerState.bScore)}`)
|
||||
}
|
||||
|
||||
function endGameSetTerritory() {
|
||||
let emptyPoints = boardState.filter(pt => !pt.stone);
|
||||
emptyPoints.forEach(pt => pt.joinGroup());
|
||||
emptyPointSetTerritory(emptyPoints);
|
||||
groupsMarkDeadLive();
|
||||
}
|
||||
|
||||
function groupsMarkDeadLive() {
|
||||
boardState.filter(pt => (!pt.territory ))
|
||||
.forEach(pt => {
|
||||
if (pt.groupMembers.some(grpMem => {
|
||||
return grpMem.checkNeighbors().some(nbr => nbr.territory === pt.stone && nbr.stone === 0)
|
||||
})) {
|
||||
pt.groupMembers.forEach(grpMem => grpMem.territory = pt.stone);
|
||||
}
|
||||
});
|
||||
boardState.filter(pt => (!pt.territory)).forEach(pt => {
|
||||
pt.territory = pt.stone * -1;
|
||||
});
|
||||
}
|
||||
|
||||
function emptyPointSetTerritory(emptyPoints) {
|
||||
emptyPoints.filter(pt => !pt.territory && pt.checkNeighbors().filter(nbr => nbr.stone !== 0))
|
||||
.forEach(pt => {
|
||||
let b = pt.groupMembers.reduce((acc, grpMem) => {
|
||||
let bNbr = grpMem.checkNeighbors().filter(nbr => nbr.stone === 1).length;
|
||||
return acc + bNbr;
|
||||
}, 0);
|
||||
let w = pt.groupMembers.reduce((acc, grpMem) => {
|
||||
let wNbr = grpMem.checkNeighbors().filter(nbr => nbr.stone === -1).length;
|
||||
return acc + wNbr;
|
||||
}, 0);
|
||||
pt.groupMembers.forEach(grp => {
|
||||
if (Math.abs(b - w) < 4 && b && w) grp.territory = 'd'
|
||||
else grp.territory = b > w ? 1 : -1;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Game
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
const Game = require("./Game").Game;
|
||||
|
||||
const GameService = ({ moveQueries, gameQueries }) => {
|
||||
const storeGame = (game) => {
|
||||
gamesInProgress[game.id] = Game(game);
|
||||
return gamesInProgress[game.id];
|
||||
};
|
||||
const gamesInProgress = {};
|
||||
|
||||
const storeMove = (gameId) => async ({ player, pos: { x, y } }) => {
|
||||
let move = { player, pos: { x, y } };
|
||||
try {
|
||||
if (moveQueries) {
|
||||
const { id } = await moveQueries.addMove({
|
||||
gameId,
|
||||
player,
|
||||
x,
|
||||
y,
|
||||
gameRecord: true,
|
||||
priorMove: null,
|
||||
});
|
||||
move.id = id;
|
||||
move.success = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
move.success = false;
|
||||
} finally {
|
||||
return move;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
initGame({ id, gameRecord = [], ...gameData }) {
|
||||
if (gamesInProgress[id]) return this.getDataForUI(id);
|
||||
if (gameRecord.length) {
|
||||
gamesInProgress[id] = Game({ gameData, gameRecord });
|
||||
} else {
|
||||
gamesInProgress[id] = Game({ gameData }).initGame();
|
||||
}
|
||||
return this.getDataForUI(id);
|
||||
},
|
||||
|
||||
async makeMove({ id, move }) {
|
||||
// check cache
|
||||
if (!gamesInProgress[id]) {
|
||||
try {
|
||||
let gameRecord;
|
||||
if (moveQueries) {
|
||||
gameRecord = await moveQueries.findGameRecord(id);
|
||||
}
|
||||
storeGame({ id, gameRecord }).initGame();
|
||||
} catch {
|
||||
return { message: "error restoring game" };
|
||||
}
|
||||
}
|
||||
gamesInProgress[id] = await gamesInProgress[id].checkMove(move);
|
||||
gamesInProgress[id] = gamesInProgress[id].makeMove(move);
|
||||
if (gamesInProgress[id].success === false)
|
||||
return { message: "illegal move" };
|
||||
try {
|
||||
if (moveQueries) {
|
||||
const priorMove = gamesInProgress[id].gameRecord.length;
|
||||
const moveInsert = {
|
||||
gameId: id,
|
||||
player: move.player,
|
||||
x: move.pos.x,
|
||||
y: move.pos.y,
|
||||
gameRecord: true,
|
||||
priorMove,
|
||||
};
|
||||
let moveDbResult;
|
||||
moveDbResult = await moveQueries.addMove(moveInsert);
|
||||
}
|
||||
} catch {
|
||||
gamesInProgress[id].returnToMove(-1);
|
||||
} finally {
|
||||
return this.getDataForUI(id);
|
||||
}
|
||||
},
|
||||
|
||||
getDataForUI: (id) => {
|
||||
return {
|
||||
board: gamesInProgress[id].legalMoves,
|
||||
territory: gamesInProgress[id].territory,
|
||||
...gamesInProgress[id].getMeta(),
|
||||
};
|
||||
},
|
||||
|
||||
dropGame: (id) => {
|
||||
return { message: `${delete gamesInProgress[id]}` };
|
||||
},
|
||||
|
||||
getAllGames: () => {
|
||||
return gamesInProgress;
|
||||
},
|
||||
|
||||
resign: ({ id, player }) => {
|
||||
// add resign gamesQueries
|
||||
return gamesInProgress[id].submitResign(player).getMeta();
|
||||
},
|
||||
|
||||
async pass({ id, player }) {
|
||||
gamesInProgress[id] = gamesInProgress[id].submitPass(player);
|
||||
if (gamesInProgress[id].success === false)
|
||||
return { message: "illegal move" };
|
||||
try {
|
||||
if (moveQueries) {
|
||||
const priorMove = gamesInProgress[id].gameRecord.length;
|
||||
const movePass = {
|
||||
gameId: id,
|
||||
player,
|
||||
x: 0,
|
||||
y: 0,
|
||||
gameRecord: true,
|
||||
priorMove,
|
||||
};
|
||||
let moveDbResult;
|
||||
moveDbResult = await moveQueries.addMove(movePass);
|
||||
}
|
||||
} catch {
|
||||
gamesInProgress[id].returnToMove(-1);
|
||||
} finally {
|
||||
return this.getDataForUI(id);
|
||||
}
|
||||
},
|
||||
|
||||
toggleTerritory({ id, point }) {
|
||||
gamesInProgress[id] = gamesInProgress[id].toggleTerritory(point);
|
||||
return this.getDataForUI(id);
|
||||
},
|
||||
|
||||
async endGame({ id }) {
|
||||
gamesInProgress[id] = gamesInProgress[id].endGame();
|
||||
const { winner, score, playerState } = gamesInProgress[id];
|
||||
const { bCaptures, wCaptures } = playerState;
|
||||
const winType = winner > 0 ? "B+" : "W+";
|
||||
try {
|
||||
if (gameQueries) {
|
||||
const result = await gameQueries.endGame({
|
||||
id,
|
||||
winType,
|
||||
score,
|
||||
bCaptures,
|
||||
wCaptures,
|
||||
});
|
||||
console.log(result);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return this.getDataForUI(id);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = GameService;
|
|
@ -1,25 +0,0 @@
|
|||
const generateRandomPassword = () => {
|
||||
const minLength = 8,
|
||||
maxLength = 16,
|
||||
minUTF = 33,
|
||||
maxUTF = 126;
|
||||
const randomize = (min, max) => Math.floor(Math.random() * (max - min) + min);
|
||||
return Array(randomize(minLength, maxLength))
|
||||
.fill(0)
|
||||
.map(() => String.fromCharCode(randomize(minUTF, maxUTF)))
|
||||
.join("");
|
||||
};
|
||||
|
||||
const guestService = {
|
||||
currentGuest: 0,
|
||||
generateGuest() {
|
||||
// generate unique username
|
||||
const username = `Guest-${String(this.currentGuest++).padStart(6, 0)}`;
|
||||
// generate random "password"
|
||||
// this exists solely to add extra randomness to signed token and is not validated
|
||||
const password = generateRandomPassword();
|
||||
return { username, password };
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = guestService;
|
|
@ -1,157 +0,0 @@
|
|||
// TODO const someSocketLogic = require('./middleware/sockets/...');
|
||||
const socketIO = require("socket.io");
|
||||
const io = socketIO({ cookie: false });
|
||||
|
||||
// const gameQueries = require('./data/queries/game');
|
||||
const moveQueries = require("./data/queries/move");
|
||||
const gameQueries = require("./data/queries/game");
|
||||
const gameServices = require("./services/gameServices")({
|
||||
moveQueries,
|
||||
gameQueries,
|
||||
});
|
||||
|
||||
io.on("connection", async (socket) => {
|
||||
socket.emit("connected", { message: "socket connected" });
|
||||
socket.on("connect_room", async (data) => {
|
||||
if (data.user && data.user.email) {
|
||||
delete data.user.email;
|
||||
}
|
||||
const room = data.room;
|
||||
const roomIo = io.of(room);
|
||||
roomIo.on("connection", async (socket) => {
|
||||
socket.emit("connected");
|
||||
socket.emit("new_user", data);
|
||||
socket.on("connect_game", (data) => {
|
||||
const game = `game-${data.game.id}`;
|
||||
socket.join(game, async () => {
|
||||
// TODO move this logic into game service
|
||||
const gameData = await gameQueries.findGameById(data.game.id);
|
||||
const convertWinType = (winType) => {
|
||||
if (winType.includes("B")) return 1;
|
||||
if (winType.includes("W")) return -1;
|
||||
if (winType.includes("0")) return "D";
|
||||
return "?";
|
||||
};
|
||||
gameData.winner = gameData.win_type
|
||||
? convertWinType(gameData.win_type)
|
||||
: 0;
|
||||
const gameRecord = await moveQueries.findGameRecord(data.game.id);
|
||||
await gameServices.initGame({
|
||||
id: data.game.id,
|
||||
gameRecord,
|
||||
gameData,
|
||||
});
|
||||
const { board, ...meta } = await gameServices.getDataForUI(
|
||||
data.game.id
|
||||
);
|
||||
io.of(room).to(game).emit("game_connected", { board, meta });
|
||||
});
|
||||
});
|
||||
|
||||
// MAKE MOVE
|
||||
socket.on("make_move", async (data) => {
|
||||
const { user, move, board, game, room } = data;
|
||||
const gameNsp = `game-${data.game.id}`;
|
||||
try {
|
||||
const { board, message, ...meta } = await gameServices.makeMove({
|
||||
id: data.game.id,
|
||||
move,
|
||||
});
|
||||
const socketAction = message ? "error" : "update_board";
|
||||
socket.join(gameNsp, () => {
|
||||
io.of(room)
|
||||
.to(gameNsp)
|
||||
.emit(socketAction, { board, meta, message });
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
socket.join(gameNsp, () => {
|
||||
io.of(room).to(gameNsp).emit("error", e);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// RESIGN
|
||||
socket.on("resign", async ({ game, player }) => {
|
||||
const { id, room } = game;
|
||||
const gameNsp = `game-${id}`;
|
||||
try {
|
||||
const meta = await gameServices.resign({
|
||||
id,
|
||||
player,
|
||||
});
|
||||
socket.join(gameNsp, () => {
|
||||
io.of(room).to(gameNsp).emit("game_resign", meta);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
// PASS
|
||||
socket.on("pass", async ({ game, player }) => {
|
||||
const { id, room } = game;
|
||||
const gameNsp = `game${id}`;
|
||||
try {
|
||||
const {
|
||||
board,
|
||||
message,
|
||||
territory,
|
||||
...meta
|
||||
} = await gameServices.pass({
|
||||
id,
|
||||
player,
|
||||
});
|
||||
socket.join(gameNsp, () => {
|
||||
io.of(room)
|
||||
.to(gameNsp)
|
||||
.emit("update_board", { board, message, territory, meta });
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
// TOGGLE TERRITORY
|
||||
socket.on("toggle_territory", async ({ user, point, board, game }) => {
|
||||
const { id, room } = game;
|
||||
const gameNsp = `game${id}`;
|
||||
try {
|
||||
const {
|
||||
board,
|
||||
territory,
|
||||
...meta
|
||||
} = await gameServices.toggleTerritory({
|
||||
id,
|
||||
point,
|
||||
});
|
||||
socket.join(gameNsp, () => {
|
||||
io.of(room)
|
||||
.to(gameNsp)
|
||||
.emit("update_board", { board, territory, meta });
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
// END GAME
|
||||
socket.on("end_game", async ({ user, game }) => {
|
||||
const { id, room } = game;
|
||||
const gameNsp = `game${id}`;
|
||||
try {
|
||||
const { board, ...meta } = await gameServices.endGame({ id });
|
||||
socket.join(gameNsp, () => {
|
||||
io.of(room).to(gameNsp).emit("end_game", { board, meta });
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
io,
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,64 +0,0 @@
|
|||
const authSignupSpec = (chai, knex, server) => {
|
||||
const newUserFormData = {
|
||||
'username':'newUser',
|
||||
'password':'password',
|
||||
'confirmPassword':'password',
|
||||
'email':'user@example.com'
|
||||
}
|
||||
const loginFormData = {
|
||||
'username':'newUser',
|
||||
'password':'password'
|
||||
}
|
||||
|
||||
|
||||
// it('post to /login with non-registered user should return status 401 with bad creds err', done => {
|
||||
// chai.request(server)
|
||||
// .post('/auth/login')
|
||||
// .type('form')
|
||||
// .send(newUserFormData)
|
||||
// .end((err, res) => {
|
||||
// if (err) done(err);
|
||||
// res.should.status(401);
|
||||
// res.body.errors.should.equal('bad credentials');
|
||||
// done();
|
||||
// });
|
||||
// })
|
||||
|
||||
// it('post to /login with non-registered user should return status 401 with bad creds err', done => {
|
||||
// chai.request(server)
|
||||
// .post('/auth/login')
|
||||
// .type('form')
|
||||
// .send(newUserFormData)
|
||||
// .end((err, res) => {
|
||||
// if (err) done(err);
|
||||
// res.should.status(401);
|
||||
// res.body.errors.should.equal('bad credentials');
|
||||
// done();
|
||||
// })
|
||||
// })
|
||||
|
||||
// it('post to /login with registered user should return cookie', done => {
|
||||
// chai.request(server)
|
||||
// .post('/auth/signup')
|
||||
// .type('form')
|
||||
// .send(newUserFormData)
|
||||
// .end((err, res) => {
|
||||
// if (err) done(err);
|
||||
|
||||
// chai.request(server)
|
||||
// .post('/auth/login')
|
||||
// .type('form')
|
||||
// .send(loginFormData)
|
||||
// .end((err, res) => {
|
||||
// if(err) done(err);
|
||||
// res.should.status(200);
|
||||
// res.should.cookie('token');
|
||||
// done();
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
|
||||
|
||||
}
|
||||
module.exports = authSignupSpec;
|
|
@ -1,434 +0,0 @@
|
|||
const chai = require("chai");
|
||||
const should = chai.should();
|
||||
const gameServices = require("../services/gameServices")({});
|
||||
|
||||
describe("game services", () => {
|
||||
afterEach(() => gameServices.dropGame(1));
|
||||
|
||||
it("init game returns game board", (done) => {
|
||||
gameServices
|
||||
.initGame({ id: 1, handicap: 4 })
|
||||
.board.should.eql(fourHandicapBoard);
|
||||
done();
|
||||
});
|
||||
|
||||
it("init game returns game metadata", (done) => {
|
||||
const { board, ...game } = gameServices.initGame({ id: 1, handicap: 4 });
|
||||
game.should.eql({ ...initialMeta, handicap: 4, turn: -1, territory: {} });
|
||||
done();
|
||||
});
|
||||
|
||||
it("games services places move", async () => {
|
||||
gameServices.initGame({ id: 1, handicap: 4 });
|
||||
const move = { player: "white", pos: { x: 6, y: 3 } };
|
||||
const afterMove = await gameServices.makeMove({ id: 1, move });
|
||||
const afterMoveShould = {
|
||||
board: { ...fourHandicapBoard, "6-3": -1 },
|
||||
...initialMeta,
|
||||
handicap: 4,
|
||||
turn: 1,
|
||||
gameRecord: [move],
|
||||
territory: {},
|
||||
};
|
||||
afterMove.should.eql(afterMoveShould);
|
||||
});
|
||||
|
||||
it("illegal move returns error message", async () => {
|
||||
gameServices.initGame({ id: 1, handicap: 4 });
|
||||
const afterMove = await gameServices.makeMove({
|
||||
id: 1,
|
||||
move: { player: "white", pos: { x: 4, y: 4 } },
|
||||
});
|
||||
afterMove.message.should.equal("illegal move");
|
||||
});
|
||||
|
||||
it("game services places move next to stone", async () => {
|
||||
gameServices.initGame({ id: 1, handicap: 4 });
|
||||
const afterMove = await gameServices.makeMove({
|
||||
id: 1,
|
||||
move: { player: "white", pos: { x: 4, y: 3 } },
|
||||
});
|
||||
afterMove.board.should.eql({ ...fourHandicapBoard, "4-3": -1 });
|
||||
});
|
||||
});
|
||||
|
||||
const fourHandicapBoard = {
|
||||
"1-1": "l",
|
||||
"1-2": "l",
|
||||
"1-3": "l",
|
||||
"1-4": "l",
|
||||
"1-5": "l",
|
||||
"1-6": "l",
|
||||
"1-7": "l",
|
||||
"1-8": "l",
|
||||
"1-9": "l",
|
||||
"1-10": "l",
|
||||
"1-11": "l",
|
||||
"1-12": "l",
|
||||
"1-13": "l",
|
||||
"1-14": "l",
|
||||
"1-15": "l",
|
||||
"1-16": "l",
|
||||
"1-17": "l",
|
||||
"1-18": "l",
|
||||
"1-19": "l",
|
||||
"2-1": "l",
|
||||
"2-2": "l",
|
||||
"2-3": "l",
|
||||
"2-4": "l",
|
||||
"2-5": "l",
|
||||
"2-6": "l",
|
||||
"2-7": "l",
|
||||
"2-8": "l",
|
||||
"2-9": "l",
|
||||
"2-10": "l",
|
||||
"2-11": "l",
|
||||
"2-12": "l",
|
||||
"2-13": "l",
|
||||
"2-14": "l",
|
||||
"2-15": "l",
|
||||
"2-16": "l",
|
||||
"2-17": "l",
|
||||
"2-18": "l",
|
||||
"2-19": "l",
|
||||
"3-1": "l",
|
||||
"3-2": "l",
|
||||
"3-3": "l",
|
||||
"3-4": "l",
|
||||
"3-5": "l",
|
||||
"3-6": "l",
|
||||
"3-7": "l",
|
||||
"3-8": "l",
|
||||
"3-9": "l",
|
||||
"3-10": "l",
|
||||
"3-11": "l",
|
||||
"3-12": "l",
|
||||
"3-13": "l",
|
||||
"3-14": "l",
|
||||
"3-15": "l",
|
||||
"3-16": "l",
|
||||
"3-17": "l",
|
||||
"3-18": "l",
|
||||
"3-19": "l",
|
||||
"4-1": "l",
|
||||
"4-2": "l",
|
||||
"4-3": "l",
|
||||
"4-4": 1,
|
||||
"4-5": "l",
|
||||
"4-6": "l",
|
||||
"4-7": "l",
|
||||
"4-8": "l",
|
||||
"4-9": "l",
|
||||
"4-10": "l",
|
||||
"4-11": "l",
|
||||
"4-12": "l",
|
||||
"4-13": "l",
|
||||
"4-14": "l",
|
||||
"4-15": "l",
|
||||
"4-16": 1,
|
||||
"4-17": "l",
|
||||
"4-18": "l",
|
||||
"4-19": "l",
|
||||
"5-1": "l",
|
||||
"5-2": "l",
|
||||
"5-3": "l",
|
||||
"5-4": "l",
|
||||
"5-5": "l",
|
||||
"5-6": "l",
|
||||
"5-7": "l",
|
||||
"5-8": "l",
|
||||
"5-9": "l",
|
||||
"5-10": "l",
|
||||
"5-11": "l",
|
||||
"5-12": "l",
|
||||
"5-13": "l",
|
||||
"5-14": "l",
|
||||
"5-15": "l",
|
||||
"5-16": "l",
|
||||
"5-17": "l",
|
||||
"5-18": "l",
|
||||
"5-19": "l",
|
||||
"6-1": "l",
|
||||
"6-2": "l",
|
||||
"6-3": "l",
|
||||
"6-4": "l",
|
||||
"6-5": "l",
|
||||
"6-6": "l",
|
||||
"6-7": "l",
|
||||
"6-8": "l",
|
||||
"6-9": "l",
|
||||
"6-10": "l",
|
||||
"6-11": "l",
|
||||
"6-12": "l",
|
||||
"6-13": "l",
|
||||
"6-14": "l",
|
||||
"6-15": "l",
|
||||
"6-16": "l",
|
||||
"6-17": "l",
|
||||
"6-18": "l",
|
||||
"6-19": "l",
|
||||
"7-1": "l",
|
||||
"7-2": "l",
|
||||
"7-3": "l",
|
||||
"7-4": "l",
|
||||
"7-5": "l",
|
||||
"7-6": "l",
|
||||
"7-7": "l",
|
||||
"7-8": "l",
|
||||
"7-9": "l",
|
||||
"7-10": "l",
|
||||
"7-11": "l",
|
||||
"7-12": "l",
|
||||
"7-13": "l",
|
||||
"7-14": "l",
|
||||
"7-15": "l",
|
||||
"7-16": "l",
|
||||
"7-17": "l",
|
||||
"7-18": "l",
|
||||
"7-19": "l",
|
||||
"8-1": "l",
|
||||
"8-2": "l",
|
||||
"8-3": "l",
|
||||
"8-4": "l",
|
||||
"8-5": "l",
|
||||
"8-6": "l",
|
||||
"8-7": "l",
|
||||
"8-8": "l",
|
||||
"8-9": "l",
|
||||
"8-10": "l",
|
||||
"8-11": "l",
|
||||
"8-12": "l",
|
||||
"8-13": "l",
|
||||
"8-14": "l",
|
||||
"8-15": "l",
|
||||
"8-16": "l",
|
||||
"8-17": "l",
|
||||
"8-18": "l",
|
||||
"8-19": "l",
|
||||
"9-1": "l",
|
||||
"9-2": "l",
|
||||
"9-3": "l",
|
||||
"9-4": "l",
|
||||
"9-5": "l",
|
||||
"9-6": "l",
|
||||
"9-7": "l",
|
||||
"9-8": "l",
|
||||
"9-9": "l",
|
||||
"9-10": "l",
|
||||
"9-11": "l",
|
||||
"9-12": "l",
|
||||
"9-13": "l",
|
||||
"9-14": "l",
|
||||
"9-15": "l",
|
||||
"9-16": "l",
|
||||
"9-17": "l",
|
||||
"9-18": "l",
|
||||
"9-19": "l",
|
||||
"10-1": "l",
|
||||
"10-2": "l",
|
||||
"10-3": "l",
|
||||
"10-4": "l",
|
||||
"10-5": "l",
|
||||
"10-6": "l",
|
||||
"10-7": "l",
|
||||
"10-8": "l",
|
||||
"10-9": "l",
|
||||
"10-10": "l",
|
||||
"10-11": "l",
|
||||
"10-12": "l",
|
||||
"10-13": "l",
|
||||
"10-14": "l",
|
||||
"10-15": "l",
|
||||
"10-16": "l",
|
||||
"10-17": "l",
|
||||
"10-18": "l",
|
||||
"10-19": "l",
|
||||
"11-1": "l",
|
||||
"11-2": "l",
|
||||
"11-3": "l",
|
||||
"11-4": "l",
|
||||
"11-5": "l",
|
||||
"11-6": "l",
|
||||
"11-7": "l",
|
||||
"11-8": "l",
|
||||
"11-9": "l",
|
||||
"11-10": "l",
|
||||
"11-11": "l",
|
||||
"11-12": "l",
|
||||
"11-13": "l",
|
||||
"11-14": "l",
|
||||
"11-15": "l",
|
||||
"11-16": "l",
|
||||
"11-17": "l",
|
||||
"11-18": "l",
|
||||
"11-19": "l",
|
||||
"12-1": "l",
|
||||
"12-2": "l",
|
||||
"12-3": "l",
|
||||
"12-4": "l",
|
||||
"12-5": "l",
|
||||
"12-6": "l",
|
||||
"12-7": "l",
|
||||
"12-8": "l",
|
||||
"12-9": "l",
|
||||
"12-10": "l",
|
||||
"12-11": "l",
|
||||
"12-12": "l",
|
||||
"12-13": "l",
|
||||
"12-14": "l",
|
||||
"12-15": "l",
|
||||
"12-16": "l",
|
||||
"12-17": "l",
|
||||
"12-18": "l",
|
||||
"12-19": "l",
|
||||
"13-1": "l",
|
||||
"13-2": "l",
|
||||
"13-3": "l",
|
||||
"13-4": "l",
|
||||
"13-5": "l",
|
||||
"13-6": "l",
|
||||
"13-7": "l",
|
||||
"13-8": "l",
|
||||
"13-9": "l",
|
||||
"13-10": "l",
|
||||
"13-11": "l",
|
||||
"13-12": "l",
|
||||
"13-13": "l",
|
||||
"13-14": "l",
|
||||
"13-15": "l",
|
||||
"13-16": "l",
|
||||
"13-17": "l",
|
||||
"13-18": "l",
|
||||
"13-19": "l",
|
||||
"14-1": "l",
|
||||
"14-2": "l",
|
||||
"14-3": "l",
|
||||
"14-4": "l",
|
||||
"14-5": "l",
|
||||
"14-6": "l",
|
||||
"14-7": "l",
|
||||
"14-8": "l",
|
||||
"14-9": "l",
|
||||
"14-10": "l",
|
||||
"14-11": "l",
|
||||
"14-12": "l",
|
||||
"14-13": "l",
|
||||
"14-14": "l",
|
||||
"14-15": "l",
|
||||
"14-16": "l",
|
||||
"14-17": "l",
|
||||
"14-18": "l",
|
||||
"14-19": "l",
|
||||
"15-1": "l",
|
||||
"15-2": "l",
|
||||
"15-3": "l",
|
||||
"15-4": "l",
|
||||
"15-5": "l",
|
||||
"15-6": "l",
|
||||
"15-7": "l",
|
||||
"15-8": "l",
|
||||
"15-9": "l",
|
||||
"15-10": "l",
|
||||
"15-11": "l",
|
||||
"15-12": "l",
|
||||
"15-13": "l",
|
||||
"15-14": "l",
|
||||
"15-15": "l",
|
||||
"15-16": "l",
|
||||
"15-17": "l",
|
||||
"15-18": "l",
|
||||
"15-19": "l",
|
||||
"16-1": "l",
|
||||
"16-2": "l",
|
||||
"16-3": "l",
|
||||
"16-4": 1,
|
||||
"16-5": "l",
|
||||
"16-6": "l",
|
||||
"16-7": "l",
|
||||
"16-8": "l",
|
||||
"16-9": "l",
|
||||
"16-10": "l",
|
||||
"16-11": "l",
|
||||
"16-12": "l",
|
||||
"16-13": "l",
|
||||
"16-14": "l",
|
||||
"16-15": "l",
|
||||
"16-16": 1,
|
||||
"16-17": "l",
|
||||
"16-18": "l",
|
||||
"16-19": "l",
|
||||
"17-1": "l",
|
||||
"17-2": "l",
|
||||
"17-3": "l",
|
||||
"17-4": "l",
|
||||
"17-5": "l",
|
||||
"17-6": "l",
|
||||
"17-7": "l",
|
||||
"17-8": "l",
|
||||
"17-9": "l",
|
||||
"17-10": "l",
|
||||
"17-11": "l",
|
||||
"17-12": "l",
|
||||
"17-13": "l",
|
||||
"17-14": "l",
|
||||
"17-15": "l",
|
||||
"17-16": "l",
|
||||
"17-17": "l",
|
||||
"17-18": "l",
|
||||
"17-19": "l",
|
||||
"18-1": "l",
|
||||
"18-2": "l",
|
||||
"18-3": "l",
|
||||
"18-4": "l",
|
||||
"18-5": "l",
|
||||
"18-6": "l",
|
||||
"18-7": "l",
|
||||
"18-8": "l",
|
||||
"18-9": "l",
|
||||
"18-10": "l",
|
||||
"18-11": "l",
|
||||
"18-12": "l",
|
||||
"18-13": "l",
|
||||
"18-14": "l",
|
||||
"18-15": "l",
|
||||
"18-16": "l",
|
||||
"18-17": "l",
|
||||
"18-18": "l",
|
||||
"18-19": "l",
|
||||
"19-1": "l",
|
||||
"19-2": "l",
|
||||
"19-3": "l",
|
||||
"19-4": "l",
|
||||
"19-5": "l",
|
||||
"19-6": "l",
|
||||
"19-7": "l",
|
||||
"19-8": "l",
|
||||
"19-9": "l",
|
||||
"19-10": "l",
|
||||
"19-11": "l",
|
||||
"19-12": "l",
|
||||
"19-13": "l",
|
||||
"19-14": "l",
|
||||
"19-15": "l",
|
||||
"19-16": "l",
|
||||
"19-17": "l",
|
||||
"19-18": "l",
|
||||
"19-19": "l",
|
||||
};
|
||||
|
||||
const initialMeta = {
|
||||
winner: null,
|
||||
turn: 0,
|
||||
pass: 0,
|
||||
komi: 6.5,
|
||||
handicap: 0,
|
||||
boardSize: 19,
|
||||
playerState: {
|
||||
bCaptures: 0,
|
||||
wCaptures: 0,
|
||||
bScore: 0,
|
||||
wScore: 0,
|
||||
},
|
||||
gameRecord: [],
|
||||
score: 0,
|
||||
};
|
29
play-node-go/.flowconfig
Normal file
29
play-node-go/.flowconfig
Normal file
|
@ -0,0 +1,29 @@
|
|||
[ignore]
|
||||
.*/node_modules/.*
|
||||
.*/src/serviceWorker\.js
|
||||
.*/src/index\.js
|
||||
.*\.test
|
||||
.*/server/node_modules/.*
|
||||
.*/server/test/.*
|
||||
.*/server/knexfile\.js
|
||||
.*/public/.*
|
||||
.*\.scss
|
||||
.*\.css
|
||||
.+\.s?css
|
||||
|
||||
[include]
|
||||
.*/src/components/
|
||||
.*/src/pages/.*
|
||||
.*/src/reducers/.*
|
||||
.*/src/utils/.*
|
||||
.*/App.js
|
||||
|
||||
[libs]
|
||||
|
||||
[lints]
|
||||
|
||||
[options]
|
||||
|
||||
[strict]
|
||||
|
||||
[untyped]
|
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,22 @@
|
|||
{
|
||||
"name": "play-node-go",
|
||||
"name": "react-boilerplate",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@mars/heroku-js-runtime-env": "^3.0.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
"node-sass": "^4.14.1",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"flow-bin": "^0.114.0",
|
||||
"node-sass": "^4.13.0",
|
||||
"react": "^16.12.0",
|
||||
"react-dom": "^16.12.0",
|
||||
"react-router-dom": "^5.1.2",
|
||||
"react-scripts": "^3.4.0",
|
||||
"react-scripts": "3.3.0",
|
||||
"socket.io-client": "^2.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "REACT_APP_ENVIRONMENT='development' react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "CI=true react-scripts test",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"flow": "./node_modules/.bin/flow",
|
||||
"predeploy": "REACT_APP_ENVIRONMENT=production npm run build",
|
||||
|
@ -35,5 +36,10 @@
|
|||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.4.0",
|
||||
"react-test-renderer": "^16.12.0"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 318 B After Width: | Height: | Size: 318 B |
|
@ -11,7 +11,6 @@
|
|||
/>
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<link rel="stylesheet" type="text/css" href="%PUBLIC_URL%/reset.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=Oswald&display=swap" rel="stylesheet">
|
||||
<title>Node Go</title>
|
||||
</head>
|
||||
<body>
|
|
@ -1,8 +1,3 @@
|
|||
a, a:link, a:visited, a:focus, a:active {
|
||||
color: unset;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* http://meyerweb.com/eric/tools/css/reset/
|
||||
v2.0 | 20110126
|
||||
License: none (public domain)
|
||||
|
@ -51,8 +46,3 @@ table {
|
|||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
background: none;
|
||||
border: none;
|
||||
}
|
11
play-node-go/public/stylesheets/partials/_mixins.scss
Normal file
11
play-node-go/public/stylesheets/partials/_mixins.scss
Normal file
|
@ -0,0 +1,11 @@
|
|||
@mixin fullspan {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@mixin flexAround($direction) {
|
||||
display: flex;
|
||||
flex-direction: $direction;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
}
|
21
play-node-go/public/stylesheets/partials/_variables.scss
Normal file
21
play-node-go/public/stylesheets/partials/_variables.scss
Normal file
|
@ -0,0 +1,21 @@
|
|||
$dev-colors: (
|
||||
"a": #34dc90,
|
||||
"b": #9034dc,
|
||||
"c": #dc9034,
|
||||
"d": #dc34dc,
|
||||
"e": #34dcdc,
|
||||
"f": #dcdc34
|
||||
);
|
||||
|
||||
/* Responsive Design */
|
||||
$break-points: (
|
||||
"500": "only screen and (min-width: 500px)",
|
||||
"570": "only screen and (min-width: 570px)",
|
||||
"590": "only screen and (min-width: 590px)",
|
||||
"700": "only screen and (min-width: 700px)",
|
||||
"900": "only screen and (min-width: 900px)"
|
||||
);
|
||||
|
||||
$colors: (
|
||||
"error": #aa3333,
|
||||
);
|
8
play-node-go/public/stylesheets/style.css
Normal file
8
play-node-go/public/stylesheets/style.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
body {
|
||||
padding: 50px;
|
||||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #00B7FF;
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
import React, { useEffect, useReducer } from 'react';
|
||||
import { Switch, Route, BrowserRouter as Router } from 'react-router-dom';
|
||||
import React, {useState, useEffect, useReducer} from 'react';
|
||||
import config from './config';
|
||||
import { Switch, Route, BrowserRouter as Router, Redirect } from 'react-router-dom';
|
||||
import MainWrapper from './pages/Layout/MainWrapper/MainWrapper';
|
||||
import { stateReducer } from './reducers/reducer';
|
||||
import { initState } from './reducers/init/reducer.init';
|
||||
import { stateReducer } from './reducers/stateReducer';
|
||||
import { initState } from './reducers/init/stateReducer.init';
|
||||
import indexServices from './services/api/indexServices';
|
||||
import './App.scss';
|
||||
|
||||
|
@ -13,32 +14,31 @@ function App() {
|
|||
{},
|
||||
initState
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchIndexAPI = async () => {
|
||||
const response = await indexServices.indexService();
|
||||
if (response) {
|
||||
const action = {
|
||||
type: 'INDEX',
|
||||
message: 'SET_USER',
|
||||
body: response
|
||||
}
|
||||
dispatch(action)
|
||||
|
||||
const fetchIndexAPI = async () => {
|
||||
const response = await indexServices.indexService();
|
||||
if (response) {
|
||||
const action = {
|
||||
type: 'INDEX',
|
||||
message: 'SET_USER',
|
||||
body: response
|
||||
}
|
||||
dispatch(action)
|
||||
}
|
||||
fetchIndexAPI();
|
||||
}, [ ])
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const socketConnect = () => {
|
||||
if (state.connect.type) return;
|
||||
dispatch({type:'SOCKET', message: 'LAUNCH', body:{nsp:'', dispatch}});
|
||||
}
|
||||
socketConnect();
|
||||
fetchIndexAPI();
|
||||
}, [])
|
||||
|
||||
return () => dispatch({type: 'SOCKET', message: 'DISCONNECT', body: {}});
|
||||
}, [ state.connect ])
|
||||
const socketConnect = () => {
|
||||
if (state.connect.type) return;
|
||||
dispatch({type:'SOCKET', message: 'LAUNCH', body:{nsp:'', dispatch}});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
socketConnect();
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Router>
|
||||
|
@ -73,7 +73,8 @@ function App() {
|
|||
</Route>
|
||||
|
||||
</Switch>
|
||||
<p className="App__socket-flag">{state.connect.type ? '✓' : ' ⃠'}</p>
|
||||
<h1>React Boilerplate</h1>
|
||||
<p>{state.connect.type ? '✓' : ' ⃠'}</p>
|
||||
</div>
|
||||
</Router>
|
||||
);
|
58
play-node-go/src/components/Button/Game/Game.js
Normal file
58
play-node-go/src/components/Button/Game/Game.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import './Game.scss';
|
||||
|
||||
const GameButton = (props) => {
|
||||
const { game, dispatch, user } = props;
|
||||
|
||||
const requestJoinGame = () => {
|
||||
console.log(`request to Join Game ${game.id}!`)
|
||||
const requestAction = {
|
||||
type: 'GAMES',
|
||||
message: 'JOIN_REQUEST',
|
||||
body: {id: game.id}
|
||||
}
|
||||
dispatch(requestAction);
|
||||
}
|
||||
|
||||
const renderOpenGame = () => {
|
||||
return (
|
||||
<>
|
||||
<a onClick={() => requestJoinGame()} >Request to Join Game</a>
|
||||
|
||||
<div className="Game__playerData">
|
||||
<span className="Game__playerData__name">{game.playerBlack}</span>
|
||||
<span className="Game__playerData__rank">{game.playerBlackRank}</span>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const renderInProgressGame = () => {
|
||||
const gameLinkText = game.winType ? 'Study Game'
|
||||
: user ? 'Rejoin Game' : 'Watch Game'
|
||||
return (
|
||||
<>
|
||||
<Link to={`/games/${game.id}`}>{gameLinkText}</Link>
|
||||
|
||||
<div className="Game__playerData">
|
||||
<span className="Game__playerData__name">{game.playerBlack}</span>
|
||||
<span className="Game__playerData__rank">{game.playerBlackRank}</span>
|
||||
</div>
|
||||
|
||||
<div className="Game__playerData">
|
||||
<span className="Game__playerData__name">{game.playerWhite}</span>
|
||||
<span className="Game__playerData__rank">{game.playerWhiteRank}</span>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="GameButton" data-testid="GameButton">
|
||||
{game.open ? renderOpenGame() : renderInProgressGame()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default GameButton;
|
5
play-node-go/src/components/Button/Game/Game.scss
Normal file
5
play-node-go/src/components/Button/Game/Game.scss
Normal file
|
@ -0,0 +1,5 @@
|
|||
div.Game__playerData {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
12
play-node-go/src/components/Button/Library/Library.js
Normal file
12
play-node-go/src/components/Button/Library/Library.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import './Library.scss';
|
||||
|
||||
const LibraryButton = () => {
|
||||
return (
|
||||
<>
|
||||
Library
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default LibraryButton;
|
12
play-node-go/src/components/Button/NewGame/NewGame.js
Normal file
12
play-node-go/src/components/Button/NewGame/NewGame.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import './NewGame.scss';
|
||||
|
||||
const NewGameButton = () => {
|
||||
return (
|
||||
<>
|
||||
New Game
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default NewGameButton;
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue