Setup formatting

This commit is contained in:
schmelczerandras 2020-10-07 16:40:21 +02:00
parent d34f25295c
commit dd850d11d1
45 changed files with 230 additions and 190 deletions

View file

@ -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"
}
}
}

View file

@ -3,5 +3,5 @@ import { CommandGenerator } from './command-generator';
export const broadcastCommands = (
commandGenerators: Array<CommandGenerator>,
commandReceivers: Array<CommandReceiver>
commandReceivers: Array<CommandReceiver>,
) => commandReceivers.forEach((r) => commandGenerators.forEach((g) => g.subscribe(r)));

View file

@ -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;

View file

@ -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<any> {
return [this.center, this.radius];

View file

@ -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<any> {
return [this.topLeft, this.size];

View file

@ -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';

View file

@ -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);
}

View file

@ -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);
}

View file

@ -1 +1 @@
export type DeserializableClass = { new(...args: Array<any>): {}; name: string };
export type DeserializableClass = { new (...args: Array<any>): unknown; name: string };

View file

@ -4,7 +4,7 @@ import { serializableMapping } from './serializable-mapping';
export const overrideDeserialization = (
source: SerializableClass,
target: DeserializableClass
target: DeserializableClass,
) => {
serializableMapping.set(source.name, {
constructor: target,

View file

@ -1,4 +1,4 @@
export type SerializableClass = {
new(...args: Array<any>): { toArray(): Array<any> };
new (...args: Array<any>): { toArray(): Array<any> };
name: string;
};

View file

@ -1,14 +0,0 @@
export const typeToBaseType = <T extends { new(...args: any[]): {} }>(
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;
}
};
};

View file

@ -12,9 +12,6 @@
"moduleResolution": "Node",
"module": "es6",
"composite": true,
"lib": [
"dom",
"es2017"
]
"lib": ["dom", "es2017"]
}
}
}

View file

@ -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'],
},
});