Add basic multiplayer
This commit is contained in:
parent
0f0a1eaf67
commit
46a48e7c15
5 changed files with 1361 additions and 753 deletions
26
shared/src/objects/deserialize.ts
Normal file
26
shared/src/objects/deserialize.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { CreatePlayerCommand } from '../commands/types/create-player';
|
||||
import { MoveActionCommand } from '../commands/types/move-action';
|
||||
import { PrimaryActionCommand } from '../commands/types/primary-action';
|
||||
import { SecondaryActionCommand } from '../commands/types/secondary-action';
|
||||
import { SetViewAreaActionCommand } from '../commands/types/set-view-area-action';
|
||||
import { TernaryActionCommand } from '../commands/types/ternary-action';
|
||||
import { UpdateObjectsCommand } from '../commands/types/update-objects';
|
||||
import { Command, CreateObjectsCommand, DeleteObjectsCommand } from '../main';
|
||||
|
||||
export const commandConstructors: {
|
||||
[type: string]: new (...values: Array<any>) => any;
|
||||
} = {
|
||||
[CreateObjectsCommand.type]: CreateObjectsCommand,
|
||||
[DeleteObjectsCommand.type]: DeleteObjectsCommand,
|
||||
[CreatePlayerCommand.type]: CreatePlayerCommand,
|
||||
[MoveActionCommand.type]: MoveActionCommand,
|
||||
[PrimaryActionCommand.type]: PrimaryActionCommand,
|
||||
[SecondaryActionCommand.type]: SecondaryActionCommand,
|
||||
[TernaryActionCommand.type]: TernaryActionCommand,
|
||||
[SetViewAreaActionCommand.type]: SetViewAreaActionCommand,
|
||||
[UpdateObjectsCommand.type]: UpdateObjectsCommand,
|
||||
};
|
||||
|
||||
export const deserializeCommand = ([type, ...values]: [string, Array<any>]): Command => {
|
||||
return new commandConstructors[type](...values);
|
||||
};
|
||||
12
shared/src/objects/game-object.ts
Normal file
12
shared/src/objects/game-object.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { CommandReceiver } from '../commands/command-receiver';
|
||||
import { Id } from '../transport/identity';
|
||||
|
||||
export abstract class GameObject extends CommandReceiver {
|
||||
public get type(): string {
|
||||
return (this as any).constructor.type;
|
||||
}
|
||||
|
||||
constructor(public readonly id: Id) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
17
shared/src/objects/types/character-base.ts
Normal file
17
shared/src/objects/types/character-base.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Circle } from '../../helper/circle';
|
||||
import { Id } from '../../main';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
export abstract class CharacterBase extends GameObject {
|
||||
public static readonly type = 'Character';
|
||||
|
||||
constructor(
|
||||
id: Id,
|
||||
public head: Circle,
|
||||
public leftFoot: Circle,
|
||||
public rightFoot: Circle
|
||||
) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
11
shared/src/objects/types/lamp-base.ts
Normal file
11
shared/src/objects/types/lamp-base.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { Id } from '../../main';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
export abstract class LampBase extends GameObject {
|
||||
public static readonly type = 'Lamp';
|
||||
|
||||
constructor(id: Id, public center: vec2, public color: vec3, public lightness: number) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
17
shared/src/objects/types/tunnel-base.ts
Normal file
17
shared/src/objects/types/tunnel-base.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { GameObject, Id } from '../../main';
|
||||
import { typed } from '../../transport/typed';
|
||||
|
||||
export abstract class TunnelBase extends GameObject {
|
||||
public static readonly type = 'Tunnel';
|
||||
|
||||
constructor(
|
||||
id: Id,
|
||||
public readonly from: vec2,
|
||||
public readonly to: vec2,
|
||||
public readonly fromRadius: number,
|
||||
public readonly toRadius: number
|
||||
) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue