Add linting

This commit is contained in:
schmelczerandras 2020-08-18 16:52:11 +02:00
parent 76282a4cf7
commit 40a660b7cb
49 changed files with 237 additions and 334 deletions

View file

@ -1,8 +1,6 @@
import { Command } from '../commands/command';
import { CommandReceiver } from '../commands/command-receiver';
import { IdentityManager } from '../identity/identity-manager';
import { Objects } from './objects';
import { Physics } from '../physics/physics';
export abstract class GameObject implements CommandReceiver {
public readonly id = IdentityManager.generateId();
@ -12,13 +10,13 @@ export abstract class GameObject implements CommandReceiver {
} = {};
public reactsToCommand(commandType: string): boolean {
return this.commandExecutors.hasOwnProperty(commandType);
return Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType);
}
public sendCommand(command: Command) {
const commandType = command.type;
if (this.commandExecutors.hasOwnProperty(commandType)) {
if (Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType)) {
this.commandExecutors[commandType](command);
}
}

View file

@ -5,12 +5,13 @@ import { GameObject } from './game-object';
export class Objects implements CommandReceiver {
private objects: Map<Id, GameObject> = new Map();
private objectsGroupedByAbilities: Map<string, Array<GameObject>> = new Map();
public addObject(o: GameObject) {
this.objects.set(o.id, o);
for (let command of this.objectsGroupedByAbilities.keys()) {
for (const command of this.objectsGroupedByAbilities.keys()) {
if (o.reactsToCommand(command)) {
this.objectsGroupedByAbilities.get(command).push(o);
}
@ -30,9 +31,7 @@ export class Objects implements CommandReceiver {
this.createGroupForCommand(e.type);
}
this.objectsGroupedByAbilities
.get(e.type)
.forEach((o, _) => o.sendCommand(e));
this.objectsGroupedByAbilities.get(e.type).forEach((o, _) => o.sendCommand(e));
}
private createGroupForCommand(commandType: string) {

View file

@ -4,13 +4,12 @@ import { CursorMoveCommand } from '../../input/commands/cursor-move-command';
import { ZoomCommand } from '../../input/commands/zoom';
import { MoveToCommand } from '../../physics/commands/move-to';
import { BoundingBox } from '../../shapes/bounding-box';
import { Physics } from '../../physics/physics';
import { GameObject } from '../game-object';
import { Lamp } from './lamp';
export class Camera extends GameObject {
private inViewAreaSize = 1920 * 1080 * 5;
private cursorPosition = vec2.create();
private _viewArea: BoundingBox;
constructor() {

View file

@ -1,31 +1,25 @@
import { vec2, vec3 } from 'gl-matrix';
import { RenderCommand } from '../../drawing/commands/render';
import { DrawableBlob } from '../../drawing/drawables/drawable-blob';
import { IGame } from '../../i-game';
import { KeyDownCommand } from '../../input/commands/key-down';
import { KeyUpCommand } from '../../input/commands/key-up';
import { SwipeCommand } from '../../input/commands/swipe';
import { MoveToCommand } from '../../physics/commands/move-to';
import { StepCommand } from '../../physics/commands/step';
import { TeleportToCommand } from '../../physics/commands/teleport-to';
import { Physics } from '../../physics/physics';
import { GameObject } from '../game-object';
import { Camera } from './camera';
import { IShape } from '../../shapes/i-shape';
import { Blob } from '../../shapes/types/blob';
import { RenderCommand } from '../../drawing/commands/render';
import { DrawableBlob } from '../../drawing/drawables/drawable-blob';
import { GameObject } from '../game-object';
import { Lamp } from './lamp';
import { Game } from '../../game';
import { IGame } from '../../i-game';
export class Character extends GameObject {
private keysDown: Set<string> = new Set();
private light = new Lamp(
vec2.create(),
40,
vec3.fromValues(0.67, 0.0, 0.33),
2
);
private light = new Lamp(vec2.create(), 40, vec3.fromValues(0.67, 0.0, 0.33), 2);
private shape = new DrawableBlob(vec2.create());
private static speed = 1.5;
constructor(private game: IGame) {
@ -35,15 +29,11 @@ export class Character extends GameObject {
this.addCommandExecutor(StepCommand, this.stepHandler.bind(this));
this.addCommandExecutor(RenderCommand, this.draw.bind(this));
this.addCommandExecutor(TeleportToCommand, (c) =>
this.setPosition(c.position)
);
this.addCommandExecutor(TeleportToCommand, (c) => this.setPosition(c.position));
this.addCommandExecutor(KeyDownCommand, (c) => this.keysDown.add(c.key));
this.addCommandExecutor(KeyUpCommand, (c) => this.keysDown.delete(c.key));
this.addCommandExecutor(SwipeCommand, (c) => {
this.tryMoving(
vec2.multiply(vec2.create(), c.delta, this.game.viewArea.size)
);
this.tryMoving(vec2.multiply(vec2.create(), c.delta, this.game.viewArea.size));
});
}
@ -90,9 +80,8 @@ export class Character extends GameObject {
const intersecting = nextNearShapes
.filter(
(n) =>
currentNearShapes.find(
(c) => c.shape === n.shape && c.distance <= 0
) !== undefined
currentNearShapes.find((c) => c.shape === n.shape && c.distance <= 0) !==
undefined
)
.sort((e) => Math.abs(e.distance));
@ -101,23 +90,16 @@ export class Character extends GameObject {
}
const normal = intersecting[0].shape.normal(this.shape.center);
const maxDistance = intersecting.reduce((p, c) =>
p.distance > c.distance ? p : c
).distance;
const maxDistance = intersecting.reduce((p, c) => (p.distance > c.distance ? p : c))
.distance;
vec2.add(
delta,
delta,
vec2.scale(vec2.create(), normal, -maxDistance - 2)
);
vec2.add(delta, delta, vec2.scale(vec2.create(), normal, -maxDistance - 2));
this.tryMoving(delta, false);
}
}
private getNearShapesTo(
shape: Blob
): Array<{ shape: IShape; distance: number }> {
private getNearShapesTo(shape: Blob): Array<{ shape: IShape; distance: number }> {
return this.game
.findIntersecting(shape.boundingBox)
.filter((b) => b.shape)

View file

@ -1,5 +1,5 @@
import { GameObject } from '../game-object';
import { RenderCommand } from '../../drawing/commands/render';
import { GameObject } from '../game-object';
export class InfoText extends GameObject {
constructor() {

View file

@ -1,8 +1,8 @@
import { vec2, vec3 } from 'gl-matrix';
import { GameObject } from '../game-object';
import { CircleLight } from '../../drawing/drawables/lights/circle-light';
import { RenderCommand } from '../../drawing/commands/render';
import { CircleLight } from '../../drawing/drawables/lights/circle-light';
import { MoveToCommand } from '../../physics/commands/move-to';
import { GameObject } from '../game-object';
export class Lamp extends GameObject {
private light: CircleLight;

View file

@ -1,9 +1,8 @@
import { vec2 } from 'gl-matrix';
import { GameObject } from '../game-object';
import { RenderCommand } from '../../drawing/commands/render';
import { Physics } from '../../physics/physics';
import { TunnelShape } from '../../shapes/types/tunnel-shape';
import { DrawableTunnel } from '../../drawing/drawables/drawable-tunnel';
import { Physics } from '../../physics/physics';
import { GameObject } from '../game-object';
export class Tunnel extends GameObject {
private shape: DrawableTunnel;

View file

@ -30,7 +30,7 @@ export const createDungeon = (objects: Objects, physics: Physics): Tunnel => {
objects.addObject(tunnel);
/*if (deltaHeight > 0 && Random.getRandom() > 0.8) {
/* if (deltaHeight > 0 && Random.getRandom() > 0.8) {
objects.addObject(
new Lamp(
currentEnd,
@ -43,7 +43,7 @@ export const createDungeon = (objects: Objects, physics: Physics): Tunnel => {
1
)
);
}*/
} */
previousEnd = currentEnd;
previousRadius = currentToRadius;