-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from PaimaStudios/feature/hex-battle
Hex-Battle preview
- Loading branch information
Showing
199 changed files
with
240,678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
node_modules | ||
*.tsbuildinfo | ||
|
||
build | ||
lib | ||
dist | ||
dist-ssr | ||
|
||
# Editor directories and files | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
snapshots | ||
|
||
*.local | ||
|
||
.env | ||
.env.production | ||
.env.development | ||
|
||
# Frontend | ||
build.zip | ||
WebGL | ||
|
||
# recompiled code for standalone purposes | ||
packaged/* | ||
|
||
engineCorePacked.js | ||
paima-engine | ||
paima-engine-mac | ||
paima-engine-linux | ||
|
||
production/ | ||
contracts/ | ||
frontend/site/bundle.js.LICENSE.txt | ||
frontend/patch.front.js | ||
frontend/stats.json | ||
upload.sh | ||
packaged/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## CHAIN DATA | ||
# Example: "https://rpc-devnet-cardano-evm.c1.milkomeda.com" | ||
CHAIN_URI="" | ||
# Example: "https://explorer-devnet-cardano-evm.c1.milkomeda.com" | ||
CHAIN_EXPLORER_URI="" | ||
# Example: "Milkomeda C1 Testnet" | ||
CHAIN_NAME="" | ||
# Example: "200101" | ||
CHAIN_ID="" | ||
# Example: "Milk Test Ada" | ||
CHAIN_CURRENCY_NAME="" | ||
# Note: The shorthand currency name/sybol shown in the user's wallet | ||
# Example: "mtADA" | ||
CHAIN_CURRENCY_SYMBOL="" | ||
# Note: The number of decimals of the native/gas asset of the chain | ||
# Example: "18" | ||
CHAIN_CURRENCY_DECIMALS="" | ||
# Note: This is in seconds as a float | ||
# Example: "2.0" | ||
BLOCK_TIME="" | ||
|
||
## CONTRACT DEPLOYMENT | ||
# Example: "0xA02F7744868945A346Ee6994068F54D039683445" | ||
CONTRACT_ADDRESS="" | ||
# Note: This is the block height to start syncing from; usually the contract deployment block height | ||
# Example: "9000000" | ||
START_BLOCKHEIGHT="" | ||
|
||
|
||
## Middleware | ||
# Note: This is the URL which your middleware will use to interact with your game node webserver | ||
# Example: "http://localhost:3333" | ||
BACKEND_URI="" | ||
|
||
|
||
## MISC | ||
# Note: This is the port your game node webserver will use | ||
# Example: "3333" | ||
WEBSERVER_PORT="" | ||
# Note: This enables running your game node with just the webserver running, meaning no new blocks will be synced. | ||
# This is primarily useful for development, devops, or testing other edge cases where you want to interact with | ||
# the game node but not have the game state progress forward. | ||
SERVER_ONLY_MODE="false" | ||
|
||
## DATABASE | ||
DB_NAME="postgres" | ||
DB_USER="postgres" | ||
DB_PW="postgres" | ||
DB_HOST="localhost" | ||
DB_PORT="5432" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
extends: ['prettier', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], | ||
parserOptions: { | ||
ecmaVersion: 2019, | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'@typescript-eslint/explicit-member-accessibility': 0, | ||
'@typescript-eslint/explicit-function-return-type': 0, | ||
'@typescript-eslint/no-parameter-properties': 0, | ||
'@typescript-eslint/interface-name-prefix': 0, | ||
'@typescript-eslint/explicit-module-boundary-types': 0, | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/ban-types': 'off', | ||
'@typescript-eslint/no-var-requires': 'off', | ||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], | ||
'@typescript-eslint/naming-convention': [ | ||
'error', | ||
{ | ||
selector: 'default', | ||
format: null, | ||
leadingUnderscore: 'allow', | ||
}, | ||
{ | ||
selector: 'typeLike', | ||
format: ['PascalCase'], | ||
leadingUnderscore: 'allow', | ||
}, | ||
], | ||
'node/no-extraneous-import': 'off', | ||
'@typescript-eslint/consistent-type-imports': 'error', | ||
'spaced-comment': 'warn', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/hydrogen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
db/src/*.queries.ts | ||
api/src/tsoa/routes.ts | ||
|
||
build | ||
lib | ||
dist | ||
|
||
packaged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": ["*.js", "*.ts", "*.jsx", "*.tsx", "*.css", "*.json"], | ||
"options": { | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"printWidth": 100, | ||
"arrowParens": "avoid" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Chess Game Node Template | ||
|
||
This documentation provides a basic overview of the template. Each module has its own `README` file with more detailed information. | ||
|
||
## Installation | ||
|
||
To install dependencies and perform initial setup, run the following command: | ||
|
||
``` | ||
npm run initialize | ||
``` | ||
|
||
This does the following: | ||
|
||
- install dependencies of this template | ||
- copies `.env.example` as `.env.development` to the parent folder | ||
|
||
### MacOS specific | ||
|
||
If you're using Mac and run into installation issues you can add `--target=esbuild-darwin-arm64` as a workaround to `npm install`. This installs the correct version of a problematic package. For example: | ||
|
||
``` | ||
npm install --save-dev esbuild@latest --target=esbuild-darwin-arm64 | ||
``` | ||
|
||
## Building | ||
|
||
To compile the Game Node into `endpoints` and `gameCode` entrypoints used by Paima Engine, use the following command: | ||
|
||
``` | ||
npm run pack | ||
``` | ||
|
||
To compile the JavaScript Bundle of the middleware for the game frontend, run the command: | ||
|
||
``` | ||
npm run pack:middleware | ||
``` | ||
|
||
## Prerequisites | ||
|
||
Ensure that the `paima-engine-{linux|mac}` executable is located in the parent directory of this project. The directory structure should be as follows: | ||
|
||
``` | ||
this-template | ||
../paima-engine-linux | ||
../.env | ||
``` | ||
|
||
## Environment Setup | ||
|
||
Config file `.env.development` is created during `npm run initialize` in the parent folder, based on `.env.example` in this project. This is an empty file that you need to fill in with your specific values, before running Paima Engine. | ||
|
||
Feel free to use examples written in the file for initial testing. | ||
|
||
## Development | ||
|
||
To reflect changes in the `API`, use the following command to regenerate all `tsoa` routes: | ||
|
||
``` | ||
npm run compile:api | ||
``` | ||
|
||
If there are any changes to the DB schema or queries, start the `pgtyped` watcher process using the following command. It will regenerate all the DB types used in the project: | ||
|
||
``` | ||
npm run compile:db | ||
``` | ||
|
||
To speed up the development cycle you can at any time completely reset the database and start syncing from the latest blockheight. Run this command, that will modify your `.env.development` and `docker-compose.yml` files: | ||
|
||
``` | ||
npm run database:reset | ||
``` | ||
|
||
## Production | ||
|
||
To start the database, run the command: | ||
|
||
``` | ||
npm run database:up | ||
``` | ||
|
||
To run the Game Node, follow these steps: | ||
|
||
1. Change to the parent directory where the packaged folder was generated: | ||
|
||
``` | ||
cd .. | ||
``` | ||
|
||
2. Execute the following command: | ||
|
||
``` | ||
./paima-engine-linux run | ||
``` | ||
|
||
You can set the `NODE_ENV` variable if you want to load a custom config for your Game Node. For example to load `.env.devnet` use: | ||
|
||
``` | ||
NODE_ENV=devnet ./paima-engine-linux run | ||
``` | ||
|
||
## Documentation | ||
|
||
If you've got this far you're probably already familiar with our documentation. But if you need to refresh your knowledge you can copy the documentation files to your file system by using the standalone CLI command: | ||
|
||
``` | ||
./paima-engine-linux docs | ||
``` | ||
|
||
Or you can visit our [Paima Documentation Website](docs.paimastudios.com) at any time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Webserver | ||
|
||
This package implements the REST API that serves data from the game node database to the middleware (which is then used by the game frontend). | ||
|
||
## How to run | ||
|
||
This package uses [tsoa](https://github.com/lukeautry/tsoa) to generate type safe API endpoints. | ||
`tsoa` requires a configuration file, `tsoa.json`. Every endpoint (called "controller" in `tsoa` convention) needs to be a single TypeScript file. To generate the endpoints, you must run the `tsoa` CLI. You can do that by running `npm run compile`. | ||
|
||
The CLI will generate a `routes.ts` file, which exports a function called `RegisterRoutes`. The function takes an Express server as its sole argument. This package exports that function, to be imported by the game backend and passed to Paima Engine to run the server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@hexbattle/api", | ||
"version": "1.0.0", | ||
"description": "Webserver REST API for the middleware to interact with game node.", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"compile": "npx tsoa spec-and-routes" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@hexbattle/utils": "1.0.0", | ||
"@hexbattle/db": "1.0.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.18.1", | ||
"fp-ts": "^2.12.3", | ||
"io-ts": "^2.2.18", | ||
"tsoa": "^4.1.2" | ||
}, | ||
"devDependencies": { | ||
"@types/cors": "^2.8.12", | ||
"@types/express": "^4.17.14" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { IGetMovesForRoundResult } from '@hexbattle/db'; | ||
import { getGameState, getMovesForRound, requirePool } from '@hexbattle/db'; | ||
import { Controller, Get, Query, Route } from 'tsoa'; | ||
|
||
@Route('game') | ||
export class GameController extends Controller { | ||
@Get('/move') | ||
public async getMoveForRound( | ||
@Query() lobby_id: string, | ||
@Query() round: number | ||
): Promise<{ | ||
move: IGetMovesForRoundResult; | ||
}> { | ||
const pool = requirePool(); | ||
const [move] = await getMovesForRound.run( | ||
{ | ||
lobby_id, | ||
round, | ||
}, | ||
pool | ||
); | ||
return { move }; | ||
} | ||
@Get('/is_game_over') | ||
public async isGameOver( | ||
@Query() lobby_id: string | ||
): Promise<{ isGameOver: boolean; current_round: number }> { | ||
const pool = requirePool(); | ||
const [lobby] = await getGameState.run({ lobby_id }, pool); | ||
if (!lobby) throw new Error('Lobby does not exist'); | ||
|
||
const isGameOver = lobby.lobby_state === 'closed' || lobby.lobby_state === 'finished'; | ||
return { isGameOver, current_round: lobby.current_round }; | ||
} | ||
} |
Oops, something went wrong.