From dd850d11d1cb66f09d639c6cec9fa07dd6fbd861 Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Wed, 7 Oct 2020 16:40:21 +0200 Subject: [PATCH] Setup formatting --- .devcontainer/devcontainer.json | 42 +++++++++++-------- .eslintignore | 5 ++- .eslintrc.json | 24 +++++++---- .prettierrc | 2 +- backend/.dockerignore | 0 backend/Dockerfile | 0 backend/package.json | 42 +++++++++---------- backend/src/main.ts | 4 +- backend/src/map/create-dungeon.ts | 8 ++-- backend/src/objects/character-physical.ts | 16 +++---- backend/src/objects/circle-physical.ts | 20 ++++----- backend/src/objects/lamp-physical.ts | 2 +- backend/src/objects/tunnel-physical.ts | 2 +- .../bounding-boxes/bounding-box-base.ts | 4 +- .../physics/containers/bounding-box-list.ts | 4 +- .../physics/containers/bounding-box-tree.ts | 6 +-- .../physics/containers/physical-container.ts | 2 +- backend/src/physics/move-circle.ts | 11 ++--- backend/src/players/player.ts | 25 +++++------ backend/webpack.config.js | 6 +-- frontend/package.json | 40 +++++++++--------- .../commands/generators/touch-listener.ts | 6 +-- frontend/src/scripts/game.ts | 6 +-- .../scripts/helper/delta-time-calculator.ts | 2 +- frontend/src/scripts/objects/camera.ts | 4 +- .../scripts/objects/game-object-container.ts | 2 +- frontend/src/scripts/shapes/blob-shape.ts | 4 +- frontend/tsconfig.json | 16 +++++++ frontend/webpack.config.js | 8 ++-- package.json | 23 +++++----- shared/package.json | 15 ++++--- shared/src/commands/broadcast-commands.ts | 2 +- shared/src/commands/command-receiver.ts | 6 +-- shared/src/helper/circle.ts | 2 +- shared/src/helper/rectangle.ts | 2 +- shared/src/main.ts | 1 - shared/src/objects/types/character-base.ts | 2 +- shared/src/objects/types/tunnel-base.ts | 2 +- .../serialization/deserializable-class.ts | 2 +- .../serialization/override-deserialization.ts | 2 +- .../serialization/serializable-class.ts | 2 +- shared/src/transport/type-to-base-type.ts | 14 ------- shared/tsconfig.json | 7 +--- shared/webpack.config.js | 9 ++-- tsconfig.json | 16 +++++++ 45 files changed, 230 insertions(+), 190 deletions(-) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile create mode 100644 frontend/tsconfig.json delete mode 100644 shared/src/transport/type-to-base-type.ts create mode 100644 tsconfig.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 882c26b..ea22d35 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,3 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/typescript-node { "name": "Node.js & TypeScript", "build": { @@ -8,31 +6,39 @@ "VARIANT": "14" } }, - // Set *default* container specific settings.json values on container create. "settings": { "terminal.integrated.shell.linux": "/bin/zsh", - "workbench.sideBar.location": "right", "files.exclude": { "**/node_modules": true, - "**/package-lock.json": true - } + "**/package-lock.json": true, + "**/dist": true, + "**/lib": true + }, + "editor.tabSize": 2, + "editor.detectIndentation": false, + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "eslint.enable": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "eslint.validate": ["json"], + "markdown.extension.toc.levels": "2..4" }, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "dbaeumer.vscode-eslint", - "ms-vscode.vscode-typescript-tslint-plugin" + "esbenp.prettier-vscode", + "yzhang.markdown-all-in-one", + "hediet.vscode-drawio" ], "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached", "workspaceFolder": "/workspace", "mounts": [ - "source=decla-red-root-node_modules,target=/workspace/node_modules,type=volume", - "source=decla-red-frontend-node_modules,target=/workspace/frontend/node_modules,type=volume", - "source=decla-red-backend-node_modules,target=/workspace/backend/node_modules,type=volume", - "source=decla-red-shared-node_modules,target=/workspace/shared/node_modules,type=volume", + "source=decla-red-root-node_modules2,target=/workspace/node_modules,type=volume", + "source=decla-red-frontend-node_modules2,target=/workspace/frontend/node_modules,type=volume", + "source=decla-red-backend-node_modules2,target=/workspace/backend/node_modules,type=volume", + "source=decla-red-shared-node_modules2,target=/workspace/shared/node_modules,type=volume" ], - "forwardPorts": [ - 3000, - 8080 - ], - "postCreateCommand": "npm install && npx lerna run initialize" -} \ No newline at end of file + "forwardPorts": [3000, 8080], + "postCreateCommand": "sudo npm install && sudo npm run initialize && npm run build" +} diff --git a/.eslintignore b/.eslintignore index 2cb7d2a..ef20d97 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,4 @@ -**/*.js +**/node_modules/**/*.js +node_modules/**/*.js +**/package-lock.json +package-lock.json \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 8275ed8..e646fad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,25 +5,33 @@ "es2020": true }, "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", - "prettier", - "prettier/@typescript-eslint" + "prettier/@typescript-eslint", + "plugin:prettier/recommended" ], "parser": "@typescript-eslint/parser", "parserOptions": { - "ecmaVersion": 11, + "ecmaVersion": 2020, "sourceType": "module" }, - "plugins": ["unused-imports", "@typescript-eslint", "prettier"], + "plugins": ["unused-imports", "@typescript-eslint", "json-format", "prettier"], + "settings": { + "json/sort-package-json": true + }, "rules": { "prettier/prettier": "error", "no-unused-vars": "off", "unused-imports/no-unused-imports-ts": "error", - "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], + "@typescript-eslint/no-unused-vars": [ + "warn", + { + "argsIgnorePattern": "^_" + } + ], "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-non-null-assertion": "off" + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-var-requires": "off" } } diff --git a/.prettierrc b/.prettierrc index 5aae580..84d3cf1 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "trailingComma": "es5", + "trailingComma": "all", "printWidth": 90, "tabWidth": 2, "singleQuote": true, diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/backend/package.json b/backend/package.json index 5f5ec46..ad36970 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,28 +1,15 @@ { "name": "decla.red-server", - "description": "Game server for decla.red", "private": true, - "main": "index.js", - "scripts": { - "start": "concurrently --kill-others \"webpack --mode development -w\" \"nodemon --legacy-watch dist/main.js\"", - "lint": "eslint --fix \"src/**/*.ts\" && prettier --write \"src/**/*.ts\"", - "build": "webpack --mode production", - "try-build": "npm run build && node dist/main.js", - "initialize": "npm install" - }, + "description": "Game server for decla.red", "keywords": [], "author": "András Schmelczer (https://schmelczer.dev/)", - "devDependencies": { - "clean-webpack-plugin": "^3.0.0", - "concurrently": "^5.3.0", - "esbuild-loader": "^2.4.0", - "nodemon": "^2.0.4", - "raw-loader": "^4.0.1", - "resolve-url-loader": "^3.1.1", - "terser-webpack-plugin": "^2.3.5", - "webpack": "^4.43.0", - "webpack-cli": "^3.3.11", - "webpack-dev-server": "^3.10.3" + "main": "index.js", + "scripts": { + "build": "webpack --mode production", + "initialize": "npm install", + "start": "concurrently --kill-others \"webpack --mode development -w\" \"nodemon --legacy-watch dist/main.js\"", + "try-build": "npm run build && node dist/main.js" }, "dependencies": { "cors": "^2.8.5", @@ -31,5 +18,18 @@ "socket.io": "^2.3.0", "uws": "^10.148.1", "webpack-node-externals": "^2.5.2" + }, + "devDependencies": { + "clean-webpack-plugin": "^3.0.0", + "concurrently": "^5.3.0", + "esbuild-loader": "^2.4.0", + "nodemon": "^2.0.4", + "raw-loader": "^4.0.1", + "resolve-url-loader": "^3.1.1", + "terser-webpack-plugin": "^2.3.5", + "typescript": "^3.9.7", + "webpack": "^4.43.0", + "webpack-cli": "^3.3.11", + "webpack-dev-server": "^3.10.3" } -} \ No newline at end of file +} diff --git a/backend/src/main.ts b/backend/src/main.ts index 72f472f..3b9f43c 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -40,16 +40,18 @@ app.use( callback(null, true); }, credentials: true, - }) + }), ); const port = 3000; const server = new Server(app); const io = ioserver(server); +/* const log = (text: string) => { io.to('insights').emit('insights', text + '\n'); }; +*/ app.get('/', function (req, res) { res.sendFile('dist/index.html', { root: '.' }); diff --git a/backend/src/map/create-dungeon.ts b/backend/src/map/create-dungeon.ts index 8257b66..237831b 100644 --- a/backend/src/map/create-dungeon.ts +++ b/backend/src/map/create-dungeon.ts @@ -20,7 +20,7 @@ export const createDungeon = (objects: PhysicalContainer) => { previousEnd, currentEnd, previousRadius, - currentToRadius + currentToRadius, ); objects.addObject(tunnel); @@ -31,10 +31,10 @@ export const createDungeon = (objects: PhysicalContainer) => { currentEnd, vec3.normalize( vec3.create(), - vec3.fromValues(Random.getRandom(), 0, Random.getRandom()) + vec3.fromValues(Random.getRandom(), 0, Random.getRandom()), ), - 0.5 - ) + 0.5, + ), ); tunnelsCountSinceLastLight = 0; } diff --git a/backend/src/objects/character-physical.ts b/backend/src/objects/character-physical.ts index 66e4274..1be5b9e 100644 --- a/backend/src/objects/character-physical.ts +++ b/backend/src/objects/character-physical.ts @@ -44,14 +44,14 @@ export class CharacterPhysical extends CharacterBase implements Physical { vec2.clone(CharacterPhysical.leftFootOffset), 20, null, - container + container, ), new CirclePhysical( vec2.clone(CharacterPhysical.rightFootOffset), 20, null, - container - ) + container, + ), ); this.head.owner = this; @@ -89,7 +89,7 @@ export class CharacterPhysical extends CharacterBase implements Physical { const movementForce = this.movementActions.reduce( (sum, current) => vec2.add(sum, sum, current.delta), - vec2.create() + vec2.create(), ); vec2.scale(movementForce, movementForce, 1 / this.movementActions.length); @@ -113,25 +113,25 @@ export class CharacterPhysical extends CharacterBase implements Physical { const bodyCenter = vec2.sub( vec2.create(), this.head.center, - CharacterPhysical.headOffset + CharacterPhysical.headOffset, ); const leftFootPositon = vec2.add( vec2.create(), bodyCenter, - CharacterPhysical.leftFootOffset + CharacterPhysical.leftFootOffset, ); const rightFootPositon = vec2.add( vec2.create(), bodyCenter, - CharacterPhysical.rightFootOffset + CharacterPhysical.rightFootOffset, ); const leftFootDelta = vec2.sub(vec2.create(), this.leftFoot.center, leftFootPositon); const rightFootDelta = vec2.sub( vec2.create(), this.rightFoot.center, - rightFootPositon + rightFootPositon, ); vec2.scale(leftFootDelta, leftFootDelta, 0.0006); diff --git a/backend/src/objects/circle-physical.ts b/backend/src/objects/circle-physical.ts index 492e248..ba1b4be 100644 --- a/backend/src/objects/circle-physical.ts +++ b/backend/src/objects/circle-physical.ts @@ -39,9 +39,9 @@ export class CirclePhysical implements Circle, Physical { private _center: vec2, private _radius: number, public owner: GameObject, - private readonly container: PhysicalContainer + private readonly container: PhysicalContainer, ) { - this._boundingBox = new BoundingBox(null); + this._boundingBox = new BoundingBox(); this.recalculateBoundingBox(); } @@ -93,8 +93,8 @@ export class CirclePhysical implements Circle, Physical { result.push( vec2.fromValues( Math.cos((2 * Math.PI * i) / count) * this.radius + this.center.x, - Math.sin((2 * Math.PI * i) / count) * this.radius + this.center.y - ) + Math.sin((2 * Math.PI * i) / count) * this.radius + this.center.y, + ), ); } return result; @@ -111,13 +111,13 @@ export class CirclePhysical implements Circle, Physical { vec2.add( this.velocity, this.velocity, - vec2.scale(vec2.create(), force, timeInMilliseconds) + vec2.scale(vec2.create(), force, timeInMilliseconds), ); vec2.set( this.velocity, clamp(this.velocity.x, -settings.maxVelocityX, settings.maxVelocityX), - clamp(this.velocity.y, -settings.maxVelocityY, settings.maxVelocityY) + clamp(this.velocity.y, -settings.maxVelocityY, settings.maxVelocityY), ); } @@ -129,7 +129,7 @@ export class CirclePhysical implements Circle, Physical { vec2.scale( this.velocity, this.velocity, - Math.pow(settings.velocityAttenuation, timeInMilliseconds) + Math.pow(settings.velocityAttenuation, timeInMilliseconds), ); const distance = vec2.scale(vec2.create(), this.velocity, timeInMilliseconds); @@ -140,13 +140,13 @@ export class CirclePhysical implements Circle, Physical { let wasHit = false; for (let i = 0; i < stepCount; i++) { - const { normal, tangent, hitSurface } = moveCircle( + const { tangent, hitSurface } = moveCircle( this, distance, - this.container.findIntersecting(this.boundingBox) + this.container.findIntersecting(this.boundingBox), ); if (hitSurface) { - vec2.scale(this.velocity, tangent, vec2.dot(tangent, this.velocity)); + vec2.scale(this.velocity, tangent!, vec2.dot(tangent!, this.velocity)); wasHit = true; } diff --git a/backend/src/objects/lamp-physical.ts b/backend/src/objects/lamp-physical.ts index 6b71cab..f93e9d9 100644 --- a/backend/src/objects/lamp-physical.ts +++ b/backend/src/objects/lamp-physical.ts @@ -23,7 +23,7 @@ export class LampPhysical extends LampBase implements Physical { this.center.x - settings.lightCutoffDistance, this.center.x + settings.lightCutoffDistance, this.center.y - settings.lightCutoffDistance, - this.center.y + settings.lightCutoffDistance + this.center.y + settings.lightCutoffDistance, ); } diff --git a/backend/src/objects/tunnel-physical.ts b/backend/src/objects/tunnel-physical.ts index 73a046f..54042f7 100644 --- a/backend/src/objects/tunnel-physical.ts +++ b/backend/src/objects/tunnel-physical.ts @@ -21,7 +21,7 @@ export class TunnelPhysical extends TunnelBase implements StaticPhysical { const targetFromDelta = vec2.subtract(vec2.create(), target, this.from); const h = clamp01( - vec2.dot(targetFromDelta, toFromDelta) / vec2.dot(toFromDelta, toFromDelta) + vec2.dot(targetFromDelta, toFromDelta) / vec2.dot(toFromDelta, toFromDelta), ); return ( diff --git a/backend/src/physics/bounding-boxes/bounding-box-base.ts b/backend/src/physics/bounding-boxes/bounding-box-base.ts index 713db3a..8bb1c1b 100644 --- a/backend/src/physics/bounding-boxes/bounding-box-base.ts +++ b/backend/src/physics/bounding-boxes/bounding-box-base.ts @@ -1,11 +1,11 @@ import { vec2 } from 'gl-matrix'; -export abstract class BoundingBoxBase { +export class BoundingBoxBase { constructor( protected _xMin: number = 0, protected _xMax: number = 0, protected _yMin: number = 0, - protected _yMax: number = 0 + protected _yMax: number = 0, ) {} public get 0(): number { diff --git a/backend/src/physics/containers/bounding-box-list.ts b/backend/src/physics/containers/bounding-box-list.ts index 3e6c8f9..df48c07 100644 --- a/backend/src/physics/containers/bounding-box-list.ts +++ b/backend/src/physics/containers/bounding-box-list.ts @@ -2,7 +2,7 @@ import { Physical } from '../physical'; import { BoundingBoxBase } from '../bounding-boxes/bounding-box-base'; export class BoundingBoxList { - constructor(private objects: Array = []) { } + constructor(private objects: Array = []) {} public insert(object: Physical) { this.objects.push(object); @@ -11,7 +11,7 @@ export class BoundingBoxList { public remove(object: Physical) { this.objects.splice( this.objects.findIndex((i) => i === object), - 1 + 1, ); } diff --git a/backend/src/physics/containers/bounding-box-tree.ts b/backend/src/physics/containers/bounding-box-tree.ts index 90b3dff..3821033 100644 --- a/backend/src/physics/containers/bounding-box-tree.ts +++ b/backend/src/physics/containers/bounding-box-tree.ts @@ -22,7 +22,7 @@ export class BoundingBoxTree { private buildRecursive( objects: Array, depth: number, - parent: Node + parent: Node, ): Node { if (objects.length === 0) { return null; @@ -71,7 +71,7 @@ export class BoundingBoxTree { private findMaybeIntersecting( boundingBox: BoundingBoxBase, node: Node, - depth: number + depth: number, ): Array { if (node === null) { return []; @@ -104,7 +104,7 @@ export class BoundingBoxTree { object: StaticPhysical, node: Node, depth: number, - parent: Node + parent: Node, ): [Node, number] { if (node === null) { return [parent, depth - 1]; diff --git a/backend/src/physics/containers/physical-container.ts b/backend/src/physics/containers/physical-container.ts index 440b3a0..ab34fda 100644 --- a/backend/src/physics/containers/physical-container.ts +++ b/backend/src/physics/containers/physical-container.ts @@ -53,7 +53,7 @@ export class PhysicalContainer { const array = this.objectsGroupedByAbilities.get(command); array.splice( array.findIndex((i) => i.id == object.gameObject.id), - 1 + 1, ); } } diff --git a/backend/src/physics/move-circle.ts b/backend/src/physics/move-circle.ts index d152c57..d470c5d 100644 --- a/backend/src/physics/move-circle.ts +++ b/backend/src/physics/move-circle.ts @@ -6,7 +6,7 @@ import { Physical } from './physical'; export const moveCircle = ( circle: CirclePhysical, delta: vec2, - possibleIntersectors: Array + possibleIntersectors: Array, ): { realDelta: vec2; hitSurface: boolean; @@ -16,7 +16,8 @@ export const moveCircle = ( circle.center = vec2.add(circle.center, circle.center, delta); const intersecting = possibleIntersectors.filter( - (b) => b.gameObject !== circle.gameObject && circle.areIntersecting(b) && b.canCollide + (b) => + b.gameObject !== circle.gameObject && circle.areIntersecting(b) && b.canCollide, ); if (intersecting.length === 0) { @@ -43,7 +44,7 @@ export const moveCircle = ( const distancesOfIntersectingPoints = distancesOfPoints.filter( (d) => (d.closest.distance > 0 && d.closest.inverted) || - (d.closest.distance < 0 && !d.closest.inverted) + (d.closest.distance < 0 && !d.closest.inverted), ); if (distancesOfIntersectingPoints.length === 0) { @@ -59,14 +60,14 @@ export const moveCircle = ( vec2.scale( pointDistance.point, pointDistance.point, - (pointDistance.closest.inverted ? 1 : -1) * pointDistance.closest.distance + (pointDistance.closest.inverted ? 1 : -1) * pointDistance.closest.distance, ); return pointDistance.point; }); const approxNormal = deltas.reduce( (sum, current) => vec2.add(sum, sum, current), - vec2.create() + vec2.create(), ); vec2.scale(approxNormal, approxNormal, 1 / deltas.length); diff --git a/backend/src/players/player.ts b/backend/src/players/player.ts index 75452b2..9d3c16b 100644 --- a/backend/src/players/player.ts +++ b/backend/src/players/player.ts @@ -1,6 +1,5 @@ import { vec2 } from 'gl-matrix'; import { - Command, CommandExecutors, CommandReceiver, CreateObjectsCommand, @@ -35,11 +34,9 @@ export class Player extends CommandReceiver { }, }; - protected defaultCommandExecutor(command: Command) { } - constructor( private readonly objects: PhysicalContainer, - private readonly socket: SocketIO.Socket + private readonly socket: SocketIO.Socket, ) { super(); this.character = new CharacterPhysical(objects); @@ -50,7 +47,7 @@ export class Player extends CommandReceiver { socket.emit( TransportEvents.ServerToPlayer, - serialize(new CreatePlayerCommand(this.character)) + serialize(new CreatePlayerCommand(this.character)), ); this.sendObjects(); @@ -66,11 +63,11 @@ export class Player extends CommandReceiver { public sendObjects() { const newlyIntersecting = this.objectsInViewArea.filter( - (o) => !this.objectsPreviouslyInViewArea.includes(o) + (o) => !this.objectsPreviouslyInViewArea.includes(o), ); const noLongerIntersecting = this.objectsPreviouslyInViewArea.filter( - (o) => !this.objectsInViewArea.includes(o) + (o) => !this.objectsInViewArea.includes(o), ); this.objectsPreviouslyInViewArea = this.objectsInViewArea; @@ -80,8 +77,8 @@ export class Player extends CommandReceiver { serialize( new DeleteObjectsCommand([ ...new Set(noLongerIntersecting.map((p) => p.gameObject.id)), - ]) - ) + ]), + ), ); } @@ -91,8 +88,8 @@ export class Player extends CommandReceiver { serialize( new CreateObjectsCommand([ ...new Set(newlyIntersecting.map((p) => p.gameObject)), - ]) - ) + ]), + ), ); } @@ -101,10 +98,10 @@ export class Player extends CommandReceiver { serialize( new UpdateObjectsCommand([ ...new Set( - this.objectsInViewArea.filter((p) => p.canMove).map((p) => p.gameObject) + this.objectsInViewArea.filter((p) => p.canMove).map((p) => p.gameObject), ), - ]) - ) + ]), + ), ); if (this.isActive) { diff --git a/backend/webpack.config.js b/backend/webpack.config.js index 2b572cd..34c4fc5 100644 --- a/backend/webpack.config.js +++ b/backend/webpack.config.js @@ -25,7 +25,7 @@ module.exports = (env, argv) => ({ }, devtool: argv.mode === 'development' ? 'source-map' : false, watchOptions: { - poll: true + poll: true, }, optimization: { minimize: argv.mode !== 'development', @@ -35,7 +35,7 @@ module.exports = (env, argv) => ({ test: /\.js$/, terserOptions: { keep_classnames: true, - } + }, }), ], }, @@ -64,7 +64,7 @@ module.exports = (env, argv) => ({ options: { loader: 'ts', target: 'es2015', - } + }, }, ], }, diff --git a/frontend/package.json b/frontend/package.json index 5b7e6f9..a13af73 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,24 +1,23 @@ { "name": "decla.red-frontend", - "description": "![logo](media/declared.png)", "private": true, - "main": "index.js", - "scripts": { - "start": "webpack-dev-server --mode development", - "lint": "eslint --fix \"src/**/*.ts\" && prettier --write \"src/**/*.ts\"", - "build": "webpack --mode production", - "try-build": "npm run build && cd dist && python3 -m http.server 8080", - "initialize": "npm install" - }, + "description": "![logo](media/declared.png)", "keywords": [], "author": "András Schmelczer (https://schmelczer.dev/)", - "postcss": { - "plugins": { - "autoprefixer": {} - } + "sideEffects": [ + "*.scss" + ], + "main": "index.js", + "scripts": { + "build": "webpack --mode production", + "initialize": "npm install", + "start": "webpack-dev-server --mode development", + "try-build": "npm run build && cd dist && python3 -m http.server 8080" }, + "browserslist": [ + "defaults" + ], "devDependencies": { - "terser-webpack-plugin": "^4.2.2", "clean-webpack-plugin": "^3.0.0", "esbuild-loader": "^2.4.0", "html-webpack-inline-source-plugin": "0.0.10", @@ -32,15 +31,16 @@ "sass": "^1.26.3", "sass-loader": "^9.0.2", "svg-url-loader": "^6.0.0", + "terser-webpack-plugin": "^4.2.2", + "typescript": "^3.9.7", "webpack": "^4.43.0", "webpack-bundle-analyzer": "^3.9.0", "webpack-cli": "^3.3.11", "webpack-dev-server": "^3.10.3" }, - "browserslist": [ - "defaults" - ], - "sideEffects": [ - "*.scss" - ] + "postcss": { + "plugins": { + "autoprefixer": {} + } + } } diff --git a/frontend/src/scripts/commands/generators/touch-listener.ts b/frontend/src/scripts/commands/generators/touch-listener.ts index 2760483..86f5da2 100644 --- a/frontend/src/scripts/commands/generators/touch-listener.ts +++ b/frontend/src/scripts/commands/generators/touch-listener.ts @@ -36,8 +36,8 @@ export class TouchListener extends CommandGenerator { this.sendCommandToSubcribers( new MoveActionCommand( - vec2.subtract(vec2.create(), position, this.previousPosition) - ) + vec2.subtract(vec2.create(), position, this.previousPosition), + ), ); this.previousPosition = position; @@ -49,7 +49,7 @@ export class TouchListener extends CommandGenerator { event.touches, (center: vec2, touch: Touch) => vec2.add(center, center, vec2.fromValues(-touch.clientX, touch.clientY)), - vec2.create() + vec2.create(), ); return vec2.scale(center, center, 1 / event.touches.length); diff --git a/frontend/src/scripts/game.ts b/frontend/src/scripts/game.ts index 782512b..6bf7919 100644 --- a/frontend/src/scripts/game.ts +++ b/frontend/src/scripts/game.ts @@ -70,7 +70,7 @@ export class Game { new MouseListener(this.canvas), new TouchListener(this.canvas), ], - [this.gameObjects, new CommandReceiverSocket(this.socket)] + [this.gameObjects, new CommandReceiverSocket(this.socket)], ); } @@ -105,7 +105,7 @@ export class Game { shadowTraceCount: 16, paletteSize: 10, enableStopwatch: true, - } + }, ); this.renderer.setRuntimeSettings({ @@ -151,7 +151,7 @@ export class Game { // todo: Should only send aspect ratio this.socket.emit( TransportEvents.PlayerToServer, - serialize(new SetViewAreaActionCommand(this.gameObjects.camera.viewArea)) + serialize(new SetViewAreaActionCommand(this.gameObjects.camera.viewArea)), ); } diff --git a/frontend/src/scripts/helper/delta-time-calculator.ts b/frontend/src/scripts/helper/delta-time-calculator.ts index f616553..7f93741 100644 --- a/frontend/src/scripts/helper/delta-time-calculator.ts +++ b/frontend/src/scripts/helper/delta-time-calculator.ts @@ -6,7 +6,7 @@ export class DeltaTimeCalculator { } public getNextDeltaTimeInMilliseconds( - currentTime: DOMHighResTimeStamp + currentTime: DOMHighResTimeStamp, ): DOMHighResTimeStamp { if (this.previousTime === null) { this.previousTime = currentTime; diff --git a/frontend/src/scripts/objects/camera.ts b/frontend/src/scripts/objects/camera.ts index 86ed5e4..fb2c5c8 100644 --- a/frontend/src/scripts/objects/camera.ts +++ b/frontend/src/scripts/objects/camera.ts @@ -23,12 +23,12 @@ export class Camera extends GameObject { this._viewArea.topLeft = vec2.fromValues( this.center.x - this._viewArea.size.x / 2, - this.center.y + this._viewArea.size.y / 2 + this.center.y + this._viewArea.size.y / 2, ); this._viewArea.size = vec2.fromValues( Math.sqrt(Camera.inViewAreaSize * canvasAspectRatio), - Math.sqrt(Camera.inViewAreaSize / canvasAspectRatio) + Math.sqrt(Camera.inViewAreaSize / canvasAspectRatio), ); c.renderer.setViewArea(this._viewArea.topLeft, this._viewArea.size); diff --git a/frontend/src/scripts/objects/game-object-container.ts b/frontend/src/scripts/objects/game-object-container.ts index 0b4cf36..c29866e 100644 --- a/frontend/src/scripts/objects/game-object-container.ts +++ b/frontend/src/scripts/objects/game-object-container.ts @@ -26,7 +26,7 @@ export class GameObjectContainer extends CommandReceiver { this.addObject(this.camera); }, - [StepCommand.type]: (c: StepCommand) => { + [StepCommand.type]: (_: StepCommand) => { if (this.player) { this.camera.center = this.player.position; } diff --git a/frontend/src/scripts/shapes/blob-shape.ts b/frontend/src/scripts/shapes/blob-shape.ts index 6be10e5..17dbdbf 100644 --- a/frontend/src/scripts/shapes/blob-shape.ts +++ b/frontend/src/scripts/shapes/blob-shape.ts @@ -115,12 +115,12 @@ export class BlobShape extends Drawable { leftFootCenter: vec2.transformMat2d( vec2.create(), this.leftFoot.center, - transform2d + transform2d, ), rightFootCenter: vec2.transformMat2d( vec2.create(), this.rightFoot.center, - transform2d + transform2d, ), headRadius: this.head.radius * transform1d, footRadius: this.leftFoot.radius * transform1d, diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 0000000..fa9d96f --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "target": "es6", + "esModuleInterop": true, + "strict": true, + "experimentalDecorators": true, + "downlevelIteration": true, + "moduleResolution": "Node", + "module": "es6", + "composite": true, + "lib": ["dom", "es2017"] + } +} diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index 6df57c2..fa96363 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -28,7 +28,7 @@ module.exports = (env, argv) => ({ host: '0.0.0.0', disableHostCheck: true, watchOptions: { - poll: true + poll: true, }, }, optimization: { @@ -39,7 +39,7 @@ module.exports = (env, argv) => ({ test: /\.js$/, terserOptions: { keep_classnames: true, - } + }, }), new OptimizeCSSAssetsPlugin({}), ], @@ -55,7 +55,7 @@ module.exports = (env, argv) => ({ removeRedundantAttributes: true, removeScriptTypeAttributes: true, removeStyleLinkTypeAttributes: true, - useShortDoctype: true + useShortDoctype: true, }, inlineSource: '.(js|css)$', }), @@ -108,7 +108,7 @@ module.exports = (env, argv) => ({ options: { loader: 'ts', target: 'es2015', - } + }, }, ], }, diff --git a/package.json b/package.json index 2fa8566..36a6e67 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,16 @@ "name": "root", "private": true, "scripts": { + "build": "lerna run build-before && lerna run build", + "initialize": "lerna link && lerna run initialize", + "lint": "eslint './**/src/**/*.{js,ts,json}' --fix", "start": "lerna run --parallel start", - "try-build": "lerna run --parallel try-build-before && lerna run --parallel try-build", - "build": "lerna run build", - "initialize": "lerna run initialize" + "try-build": "lerna run --parallel try-build-before && lerna run --parallel try-build" + }, + "dependencies": { + "decla.red-frontend": "file:frontend", + "decla.red-server": "file:backend", + "shared": "file:shared" }, "devDependencies": { "@types/cors": "^2.8.7", @@ -17,26 +23,21 @@ "@typescript-eslint/eslint-plugin": "^3.9.1", "@typescript-eslint/parser": "^3.9.1", "autoprefixer": "^9.8.5", - "lerna": "^3.22.1", "css-loader": "^3.5.2", "cssnano": "^4.1.10", "eslint": "^7.2.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-import": "^2.21.2", + "eslint-plugin-json-format": "^2.0.1", "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-unused-imports": "^0.1.3", "file-loader": "^6.1.0", "firebase": "^7.22.0", "gl-matrix": "^3.3.0", + "lerna": "^3.22.1", "prettier": "^2.0.5", "sdf-2d": "^0.4.0", "socket.io-client": "^2.3.1", - "typescript": "^3.8.3", "uuid": "^8.2.0" - }, - "dependencies": { - "decla.red-frontend": "file:frontend", - "decla.red-server": "file:backend", - "shared": "file:shared" } -} \ No newline at end of file +} diff --git a/shared/package.json b/shared/package.json index 94afceb..1ebaa18 100644 --- a/shared/package.json +++ b/shared/package.json @@ -3,18 +3,23 @@ "private": true, "description": "Shared library between backend and frontend", "main": "lib/main.js", + "types": "lib/src/main.d.ts", + "files": [ + "lib" + ], "scripts": { - "start": "webpack --mode development --watch", - "lint": "eslint --fix \"src/**/*.ts\" && prettier --write \"src/**/*.ts\"", "build": "webpack --mode production", - "try-build-before": "npm run build", - "initialize": "npm install" + "build-before": "npm run build", + "initialize": "npm install", + "start": "webpack --mode development --watch", + "try-build-before": "npm run build-before" }, "devDependencies": { "clean-webpack-plugin": "^3.0.0", "terser-webpack-plugin": "^2.3.8", "ts-loader": "^8.0.3", + "typescript": "^3.9.7", "webpack": "^4.43.0", "webpack-cli": "^3.3.11" } -} \ No newline at end of file +} diff --git a/shared/src/commands/broadcast-commands.ts b/shared/src/commands/broadcast-commands.ts index 773f58c..a5da5b5 100644 --- a/shared/src/commands/broadcast-commands.ts +++ b/shared/src/commands/broadcast-commands.ts @@ -3,5 +3,5 @@ import { CommandGenerator } from './command-generator'; export const broadcastCommands = ( commandGenerators: Array, - commandReceivers: Array + commandReceivers: Array, ) => commandReceivers.forEach((r) => commandGenerators.forEach((g) => g.subscribe(r))); diff --git a/shared/src/commands/command-receiver.ts b/shared/src/commands/command-receiver.ts index 7aa255b..385874f 100644 --- a/shared/src/commands/command-receiver.ts +++ b/shared/src/commands/command-receiver.ts @@ -1,18 +1,18 @@ import { Command } from './command'; export type CommandExecutors = { - [type: string]: (command: Command) => void; + [type: string]: (command: any) => unknown; }; export abstract class CommandReceiver { protected commandExecutors: CommandExecutors = {}; - protected defaultCommandExecutor(command: Command) { } - public reactsToCommand(commandType: string): boolean { return Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType); } + protected defaultCommandExecutor(_: Command) {} + public sendCommand(command: Command) { const commandType = command.type; diff --git a/shared/src/helper/circle.ts b/shared/src/helper/circle.ts index 0418921..5710478 100644 --- a/shared/src/helper/circle.ts +++ b/shared/src/helper/circle.ts @@ -3,7 +3,7 @@ import { serializable } from '../transport/serialization/serializable'; @serializable export class Circle { - constructor(public center: vec2, public radius: number) { } + constructor(public center: vec2, public radius: number) {} public toArray(): Array { return [this.center, this.radius]; diff --git a/shared/src/helper/rectangle.ts b/shared/src/helper/rectangle.ts index 9758cce..25ea3cb 100644 --- a/shared/src/helper/rectangle.ts +++ b/shared/src/helper/rectangle.ts @@ -3,7 +3,7 @@ import { serializable } from '../transport/serialization/serializable'; @serializable export class Rectangle { - constructor(public topLeft = vec2.create(), public size = vec2.create()) { } + constructor(public topLeft = vec2.create(), public size = vec2.create()) {} public toArray(): Array { return [this.topLeft, this.size]; diff --git a/shared/src/main.ts b/shared/src/main.ts index abef016..9e02766 100644 --- a/shared/src/main.ts +++ b/shared/src/main.ts @@ -33,4 +33,3 @@ export * from './objects/types/tunnel-base'; export * from './settings'; export * from './transport/transport-events'; export * from './transport/identity'; -export * from './transport/type-to-base-type'; diff --git a/shared/src/objects/types/character-base.ts b/shared/src/objects/types/character-base.ts index 799d273..eb1a731 100644 --- a/shared/src/objects/types/character-base.ts +++ b/shared/src/objects/types/character-base.ts @@ -9,7 +9,7 @@ export class CharacterBase extends GameObject { id: Id, public head: Circle, public leftFoot: Circle, - public rightFoot: Circle + public rightFoot: Circle, ) { super(id); } diff --git a/shared/src/objects/types/tunnel-base.ts b/shared/src/objects/types/tunnel-base.ts index 79ac7da..58dea4d 100644 --- a/shared/src/objects/types/tunnel-base.ts +++ b/shared/src/objects/types/tunnel-base.ts @@ -10,7 +10,7 @@ export class TunnelBase extends GameObject { public readonly from: vec2, public readonly to: vec2, public readonly fromRadius: number, - public readonly toRadius: number + public readonly toRadius: number, ) { super(id); } diff --git a/shared/src/transport/serialization/deserializable-class.ts b/shared/src/transport/serialization/deserializable-class.ts index 9913aa1..11d0a4f 100644 --- a/shared/src/transport/serialization/deserializable-class.ts +++ b/shared/src/transport/serialization/deserializable-class.ts @@ -1 +1 @@ -export type DeserializableClass = { new(...args: Array): {}; name: string }; +export type DeserializableClass = { new (...args: Array): unknown; name: string }; diff --git a/shared/src/transport/serialization/override-deserialization.ts b/shared/src/transport/serialization/override-deserialization.ts index d80d202..c59bcee 100644 --- a/shared/src/transport/serialization/override-deserialization.ts +++ b/shared/src/transport/serialization/override-deserialization.ts @@ -4,7 +4,7 @@ import { serializableMapping } from './serializable-mapping'; export const overrideDeserialization = ( source: SerializableClass, - target: DeserializableClass + target: DeserializableClass, ) => { serializableMapping.set(source.name, { constructor: target, diff --git a/shared/src/transport/serialization/serializable-class.ts b/shared/src/transport/serialization/serializable-class.ts index 41438ca..88eb2d4 100644 --- a/shared/src/transport/serialization/serializable-class.ts +++ b/shared/src/transport/serialization/serializable-class.ts @@ -1,4 +1,4 @@ export type SerializableClass = { - new(...args: Array): { toArray(): Array }; + new (...args: Array): { toArray(): Array }; name: string; }; diff --git a/shared/src/transport/type-to-base-type.ts b/shared/src/transport/type-to-base-type.ts deleted file mode 100644 index 1cf8012..0000000 --- a/shared/src/transport/type-to-base-type.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const typeToBaseType = ( - constructor: T -) => { - const parent = constructor; - return class extends constructor { - public static get type(): string { - return Object.getPrototypeOf((parent as any).prototype).constructor.name; - } - - public get type(): string { - return Object.getPrototypeOf((parent as any).prototype).constructor.name; - } - }; -}; diff --git a/shared/tsconfig.json b/shared/tsconfig.json index 786ccc7..9b6f578 100644 --- a/shared/tsconfig.json +++ b/shared/tsconfig.json @@ -12,9 +12,6 @@ "moduleResolution": "Node", "module": "es6", "composite": true, - "lib": [ - "dom", - "es2017" - ] + "lib": ["dom", "es2017"] } -} \ No newline at end of file +} diff --git a/shared/webpack.config.js b/shared/webpack.config.js index 8db7d86..4101d1a 100644 --- a/shared/webpack.config.js +++ b/shared/webpack.config.js @@ -20,7 +20,10 @@ module.exports = (env, argv) => ({ devtool: argv.mode === 'development' ? 'source-map' : false, watchOptions: { poll: true, - ignored: /node_modules/ + ignored: /node_modules/, + }, + externals: { + 'gl-matrix': 'gl-matrix', }, optimization: { minimize: false, @@ -39,10 +42,10 @@ module.exports = (env, argv) => ({ loader: 'ts-loader', }, exclude: /node_modules/, - } + }, ], }, resolve: { - extensions: ['.ts', '.js'], + extensions: ['.ts'], }, }); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..fa9d96f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "target": "es6", + "esModuleInterop": true, + "strict": true, + "experimentalDecorators": true, + "downlevelIteration": true, + "moduleResolution": "Node", + "module": "es6", + "composite": true, + "lib": ["dom", "es2017"] + } +}