Skip to content

Commit

Permalink
feat(example game): adding client and server folders for psychic
Browse files Browse the repository at this point in the history
  • Loading branch information
rallieon committed Apr 14, 2021
1 parent 5a39221 commit 0b7b5eb
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/psychic-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# psychic-client

## Overview

The psychic client is an example of the @haste-sdk/client package. It utilizes the haste arcade api to demonstrate how to leverge a shared leaderboard and secure ILP interactions.

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md) for an overview of the haste-sdk repository.

<Add deploy badge here>

## Table of Contents

- [Background and Use Case](#background)
- [Setup](#setup)
- [Usage](#usage)
- [Deploy](#deploy)
- [Documentation](#documentation)
- [License](#license)
- [Contributing](#contributing)
- [Authors](#authors)

## Background

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Background) for a detailed background.

## Setup

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Setup) for a detailed setup guide.

## Usage

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Usage) for a detailed usage guide.

### Testing

@haste-sdk/psychic-client utilizes Jest for running tests. To run all tests in the psychic-client package use the following command

`npm run test`

## Documentation

Currently there is no documentation setup, but please check back in the future.

## License

haste-sdk is currently licensed under [MIT](https://github.com/playhaste/haste-sdk/blob/main/LICENSE)

## Contributing

Please read our contribution [policy](https://github.com/playhaste/haste-sdk/blob/main/CONTRIBUTING.md).

## Authors

- Keith LaForce ([klaforce](https://github.com/klaforce/))
- Eric LaForce ([elaforc](https://github.com/elaforc/))
- Dan Wagner ([danwag06](https://github.com/danwag06))
7 changes: 7 additions & 0 deletions packages/psychic-client/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
};
54 changes: 54 additions & 0 deletions packages/psychic-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@haste-sdk/psychic-client",
"version": "0.0.0",
"description": "The psychic client is an example of the @haste-sdk/client package. It utilizes the haste arcade api to demonstrate how to leverge a shared leaderboard and secure ILP interactions.",
"contributors": [
"Keith LaForce <keith@playhaste.com>",
"Eric LaForce <eric@playhaste.com>",
"Dan Wagner <dan@playhaste.com>"
],
"homepage": "https://playhaste.com",
"license": "MIT",
"main": "dist/index",
"types": "dist/index",
"repository": {
"type": "git",
"url": "git+https://github.com/playhaste/haste-sdk.git"
},
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.build.json",
"clean": "rimraf -rf ./dist ./coverage",
"test": "jest --coverage=true",
"lint": "eslint src --ext .ts",
"pretty": "prettier --write \"src/**/*.ts\""
},
"lint-staged": {
"*.ts": "eslint src --ext .ts --fix"
},
"bugs": {
"url": "https://github.com/playhaste/haste-sdk/issues"
},
"dependencies": {
"@haste-sdk/domain": "0.0.0"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^4.3.1",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
}
}
20 changes: 20 additions & 0 deletions packages/psychic-client/src/__tests__/game/game.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Game, Player, Score } from '@haste-sdk/domain';
import { getHighScore } from '../..';

const game = new Game('testgame');

const initializeTestGame = () => {
game.addLeader(new Player('test@gmail.com'), new Score(0));
game.addLeader(new Player('test@gmail1.com'), new Score(1));
game.addLeader(new Player('test@gmail2.com'), new Score(2));
game.addLeader(new Player('test@gmail3.com'), new Score(3));
game.addLeader(new Player('test@gmail4.com'), new Score(4));
};

beforeEach(() => {
initializeTestGame();
});

test('getHighScore', () => {
expect(getHighScore(game)).toBe(4);
});
4 changes: 4 additions & 0 deletions packages/psychic-client/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions packages/psychic-client/src/game/game.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Game } from '@haste-sdk/domain';

export function getHighScore(game: Game): number {
if (game.name === 'test') {
return 32;
}
const scores = game.getScores().map((g) => g.score.getScore());
return Math.max(...scores);
}
1 change: 1 addition & 0 deletions packages/psychic-client/src/game/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getHighScore } from './game';
1 change: 1 addition & 0 deletions packages/psychic-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './game';
8 changes: 8 additions & 0 deletions packages/psychic-client/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
3 changes: 3 additions & 0 deletions packages/psychic-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
}
56 changes: 56 additions & 0 deletions packages/psychic-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# psychic-server

## Overview

The psychic server is an example of the @haste-sdk/server package. It utilizes the haste arcade api to demonstrate how to leverge a shared leaderboard and payouts.

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md) for an overview of the haste-sdk repository.

<Add deploy badge here>

## Table of Contents

- [Background and Use Case](#background)
- [Setup](#setup)
- [Usage](#usage)
- [Deploy](#deploy)
- [Documentation](#documentation)
- [License](#license)
- [Contributing](#contributing)
- [Authors](#authors)

## Background

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Background) for a detailed background.

## Setup

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Setup) for a detailed setup guide.

## Usage

See [here](https://github.com/playhaste/haste-sdk/blob/main/README.md#Usage) for a detailed usage guide.

### Testing

@haste-sdk/psychic-server utilizes Jest for running tests. To run all tests in the psychic-server package use the following command

`npm run test`

## Documentation

Currently there is no documentation setup, but please check back in the future.

## License

haste-sdk is currently licensed under [MIT](https://github.com/playhaste/haste-sdk/blob/main/LICENSE)

## Contributing

Please read our contribution [policy](https://github.com/playhaste/haste-sdk/blob/main/CONTRIBUTING.md).

## Authors

- Keith LaForce ([klaforce](https://github.com/klaforce/))
- Eric LaForce ([elaforc](https://github.com/elaforc/))
- Dan Wagner ([danwag06](https://github.com/danwag06))
7 changes: 7 additions & 0 deletions packages/psychic-server/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
};
54 changes: 54 additions & 0 deletions packages/psychic-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@haste-sdk/psychic-server",
"version": "0.0.0",
"description": "The psychic server is an example of the @haste-sdk/server package. It utilizes the haste arcade api to demonstrate how to leverge a shared leaderboard and payouts.",
"contributors": [
"Keith LaForce <keith@playhaste.com>",
"Eric LaForce <eric@playhaste.com>",
"Dan Wagner <dan@playhaste.com>"
],
"homepage": "https://playhaste.com",
"license": "MIT",
"main": "dist/index",
"types": "dist/index",
"repository": {
"type": "git",
"url": "git+https://github.com/playhaste/haste-sdk.git"
},
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.build.json",
"clean": "rimraf -rf ./dist ./coverage",
"test": "jest --coverage=true",
"lint": "eslint src --ext .ts",
"pretty": "prettier --write \"src/**/*.ts\""
},
"lint-staged": {
"*.ts": "eslint src --ext .ts --fix"
},
"bugs": {
"url": "https://github.com/playhaste/haste-sdk/issues"
},
"dependencies": {
"@haste-sdk/domain": "0.0.0"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^4.3.1",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
}
}
20 changes: 20 additions & 0 deletions packages/psychic-server/src/__tests__/game/game.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Game, Player, Score } from '@haste-sdk/domain';
import { getHighScore } from '../..';

const game = new Game('testgame');

const initializeTestGame = () => {
game.addLeader(new Player('test@gmail.com'), new Score(0));
game.addLeader(new Player('test@gmail1.com'), new Score(1));
game.addLeader(new Player('test@gmail2.com'), new Score(2));
game.addLeader(new Player('test@gmail3.com'), new Score(3));
game.addLeader(new Player('test@gmail4.com'), new Score(4));
};

beforeEach(() => {
initializeTestGame();
});

test('getHighScore', () => {
expect(getHighScore(game)).toBe(4);
});
4 changes: 4 additions & 0 deletions packages/psychic-server/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions packages/psychic-server/src/game/game.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Game } from '@haste-sdk/domain';

export function getHighScore(game: Game): number {
if (game.name === 'test') {
return 32;
}
const scores = game.getScores().map((g) => g.score.getScore());
return Math.max(...scores);
}
1 change: 1 addition & 0 deletions packages/psychic-server/src/game/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getHighScore } from './game';
1 change: 1 addition & 0 deletions packages/psychic-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './game';
8 changes: 8 additions & 0 deletions packages/psychic-server/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
3 changes: 3 additions & 0 deletions packages/psychic-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
}

0 comments on commit 0b7b5eb

Please sign in to comment.