Simplify types

This commit is contained in:
schmelczerandras 2020-10-06 14:08:43 +02:00
commit ba8b1a29fd
30 changed files with 52 additions and 76 deletions

View file

@ -34,5 +34,5 @@
3000,
8080
],
"postCreateCommand": "npm install && npx lerna run initialize",
"postCreateCommand": "npm install && npx lerna run initialize"
}

View file

@ -6,6 +6,7 @@ import {
settings,
CommandExecutors,
MoveActionCommand,
typeToBaseType,
} from 'shared';
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
@ -14,6 +15,7 @@ import { CirclePhysical } from './circle-physical';
import { Physical } from '../physics/physical';
import { PhysicalContainer } from '../physics/containers/physical-container';
@typeToBaseType
export class CharacterPhysical extends CharacterBase implements Physical {
public readonly canCollide = true;
public readonly isInverted = false;
@ -34,7 +36,7 @@ export class CharacterPhysical extends CharacterBase implements Physical {
private static readonly leftFootOffset = vec2.fromValues(-20, -10);
private static readonly rightFootOffset = vec2.fromValues(20, -10);
constructor(container: PhysicalContainer) {
constructor(private readonly container: PhysicalContainer) {
super(
id(),
new CirclePhysical(vec2.clone(CharacterPhysical.headOffset), 50, null, container),
@ -159,6 +161,12 @@ export class CharacterPhysical extends CharacterBase implements Physical {
);*/
}
public destroy() {
this.container.removeObject(this.head);
this.container.removeObject(this.leftFoot);
this.container.removeObject(this.rightFoot);
}
public toJSON(): any {
const { type, id, head, leftFoot, rightFoot } = this;
return [type, id, head, leftFoot, rightFoot];

View file

@ -1,10 +1,11 @@
import { vec2, vec3 } from 'gl-matrix';
import { LampBase, settings, id } from 'shared';
import { LampBase, settings, id, typeToBaseType } from 'shared';
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
import { Physical } from '../physics/physical';
@typeToBaseType
export class LampPhysical extends LampBase implements Physical {
public readonly canCollide = false;
public readonly isInverted = false;

View file

@ -1,9 +1,10 @@
import { vec2 } from 'gl-matrix';
import { clamp01, mix, TunnelBase, id } from 'shared';
import { clamp01, mix, TunnelBase, id, typeToBaseType } from 'shared';
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
import { StaticPhysical } from '../physics/containers/static-physical-object';
@typeToBaseType
export class TunnelPhysical extends TunnelBase implements StaticPhysical {
public readonly canCollide = true;
public readonly isInverted = true;

View file

@ -2,7 +2,7 @@ import { Physical } from '../physical';
import { BoundingBoxBase } from '../bounding-boxes/bounding-box-base';
export class BoundingBoxList {
constructor(private objects: Array<Physical> = []) {}
constructor(private objects: Array<Physical> = []) { }
public insert(object: Physical) {
this.objects.push(object);

View file

@ -35,7 +35,7 @@ export class Player extends CommandReceiver {
},
};
protected defaultCommandExecutor(command: Command) {}
protected defaultCommandExecutor(command: Command) { }
constructor(
private readonly objects: PhysicalContainer,
@ -118,6 +118,7 @@ export class Player extends CommandReceiver {
public destroy() {
this.isActive = false;
this.character.destroy();
this.objects.removeObject(this.character);
}
}

View file

@ -1,8 +0,0 @@
{
"typescript.tsdk": "node_modules\\typescript\\lib",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}

View file

@ -2,8 +2,6 @@ import { vec2 } from 'gl-matrix';
import { Command } from 'shared';
export class MoveToCommand extends Command {
public static readonly type = 'MoveToCommand';
public constructor(public readonly position: vec2) {
super();
}

View file

@ -2,8 +2,6 @@ import { Renderer } from 'sdf-2d';
import { Command } from 'shared';
export class RenderCommand extends Command {
public static readonly type = 'RenderCommand';
public constructor(public readonly renderer: Renderer) {
super();
}

View file

@ -22,7 +22,7 @@ export const deserialize = (json: string): GameObject => {
};
export const deserializeJsonArray = (json: string): Array<GameObject> => {
return (JSON.parse(json) as Array<any>).map(
([type, ...values]) => new constructors[type](...values)
);
return (JSON.parse(json) as Array<any>).map(([type, ...values]) => {
return new constructors[type](...values);
});
};

View file

@ -7,7 +7,7 @@ export type CommandExecutors = {
export abstract class CommandReceiver {
protected commandExecutors: CommandExecutors = {};
protected defaultCommandExecutor(command: Command) {}
protected defaultCommandExecutor(command: Command) { }
public reactsToCommand(commandType: string): boolean {
return Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType);

View file

@ -1,7 +1,3 @@
import { Id } from '../transport/identity';
import { Typed } from '../transport/typed';
export abstract class Command {
public get type(): string {
return (this as any).constructor.type;
}
}
export abstract class Command extends Typed { }

View file

@ -1,8 +1,6 @@
import { Command } from '../command';
export class CreateObjectsCommand extends Command {
public static readonly type = 'CreateObjectsCommand';
public constructor(public readonly serializedObjects: string) {
super();
}

View file

@ -1,8 +1,6 @@
import { Command } from '../command';
export class CreatePlayerCommand extends Command {
public static readonly type = 'CreatePlayerCommand';
public constructor(public readonly serializedPlayer: string) {
super();
}

View file

@ -2,8 +2,6 @@ import { Id } from '../../transport/identity';
import { Command } from '../command';
export class DeleteObjectsCommand extends Command {
public static readonly type = 'DeleteObjectsCommand';
public constructor(public readonly ids: Array<Id>) {
super();
}

View file

@ -2,8 +2,6 @@ import { vec2 } from 'gl-matrix';
import { Command } from '../command';
export class MoveActionCommand extends Command {
public static readonly type = 'MoveActionCommand';
public constructor(public readonly delta: vec2) {
super();
}

View file

@ -2,8 +2,6 @@ import { vec2 } from 'gl-matrix';
import { Command } from '../command';
export class PrimaryActionCommand extends Command {
public static readonly type = 'PrimaryActionCommand';
public constructor(public readonly position: vec2) {
super();
}

View file

@ -2,8 +2,6 @@ import { vec2 } from 'gl-matrix';
import { Command } from '../command';
export class SecondaryActionCommand extends Command {
public static readonly type = 'SecondaryActionCommand';
public constructor(public readonly position: vec2) {
super();
}

View file

@ -2,8 +2,6 @@ import { Rectangle } from '../../helper/rectangle';
import { Command } from '../command';
export class SetViewAreaActionCommand extends Command {
public static readonly type = 'SetViewAreaAction';
public constructor(public readonly viewArea: Rectangle) {
super();
}

View file

@ -1,8 +1,6 @@
import { Command } from '../command';
export class StepCommand extends Command {
public static readonly type = 'StepCommand';
public constructor(public readonly deltaTimeInMiliseconds: DOMHighResTimeStamp) {
super();
}

Some files were not shown because too many files have changed in this diff Show more