Refactor
This commit is contained in:
parent
1ce961d6c2
commit
99cdb62928
44 changed files with 338 additions and 431 deletions
|
|
@ -1,7 +0,0 @@
|
|||
import { CommandReceiver } from './command-receiver';
|
||||
import { CommandGenerator } from './command-generator';
|
||||
|
||||
export const broadcastCommands = (
|
||||
commandGenerators: Array<CommandGenerator>,
|
||||
commandReceivers: Array<CommandReceiver>,
|
||||
) => commandReceivers.forEach((r) => commandGenerators.forEach((g) => g.subscribe(r)));
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
import { CommandReceiver } from './command-receiver';
|
||||
import { Command } from './command';
|
||||
|
||||
export class CommandGenerator {
|
||||
export abstract class CommandGenerator {
|
||||
private subscribers: Array<CommandReceiver> = [];
|
||||
|
||||
public subscribe(subscriber: CommandReceiver): void {
|
||||
this.subscribers.push(subscriber);
|
||||
}
|
||||
|
||||
public clearSubscribers(): void {
|
||||
this.subscribers = [];
|
||||
}
|
||||
|
||||
protected sendCommandToSubscribers(command: Command): void {
|
||||
this.subscribers.forEach((s) => s.sendCommand(command));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export abstract class CommandReceiver {
|
|||
const commandType = command.type;
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType)) {
|
||||
this.commandExecutors[commandType](command);
|
||||
this.commandExecutors[commandType]!(command);
|
||||
} else {
|
||||
this.defaultCommandExecutor(command);
|
||||
}
|
||||
|
|
|
|||
14
shared/src/commands/types/actions/move-action.ts
Normal file
14
shared/src/commands/types/actions/move-action.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../../serialization/serializable';
|
||||
import { Command } from '../../command';
|
||||
|
||||
@serializable
|
||||
export class MoveActionCommand extends Command {
|
||||
public constructor(public readonly direction: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.direction];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
import { serializable } from '../../../serialization/serializable';
|
||||
import { Command } from '../../command';
|
||||
|
||||
@serializable
|
||||
export class TernaryActionCommand extends Command {
|
||||
export class PrimaryActionCommand extends Command {
|
||||
public constructor(public readonly position: vec2) {
|
||||
super();
|
||||
}
|
||||
14
shared/src/commands/types/actions/secondary-action.ts
Normal file
14
shared/src/commands/types/actions/secondary-action.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../../serialization/serializable';
|
||||
import { Command } from '../../command';
|
||||
|
||||
@serializable
|
||||
export class SecondaryActionCommand extends Command {
|
||||
public constructor(public readonly position: vec2) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.position];
|
||||
}
|
||||
}
|
||||
13
shared/src/commands/types/actions/set-aspect-ratio-action.ts
Normal file
13
shared/src/commands/types/actions/set-aspect-ratio-action.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { serializable } from '../../../serialization/serializable';
|
||||
import { Command } from '../../command';
|
||||
|
||||
@serializable
|
||||
export class SetAspectRatioActionCommand extends Command {
|
||||
public constructor(public readonly aspectRatio: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.aspectRatio];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { GameObject } from '../../objects/game-object';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { PlayerCharacterBase } from '../../objects/types/player-character-base';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Id } from '../../communication/id';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { CharacterTeam } from '../../objects/types/character-team';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class GameEnd extends Command {
|
||||
export class GameEndCommand extends Command {
|
||||
constructor(
|
||||
public readonly winningTeam: CharacterTeam,
|
||||
public readonly endCardLengthInSeconds: number,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class GameStart extends Command {
|
||||
export class GameStartCommand extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class PlayerDiedCommand extends Command {
|
||||
public constructor(public readonly timeout: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.timeout];
|
||||
}
|
||||
}
|
||||
14
shared/src/commands/types/property-updates-for-objects.ts
Normal file
14
shared/src/commands/types/property-updates-for-objects.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { PropertyUpdatesForObject } from '../../objects/game-object';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class PropertyUpdatesForObjects extends Command {
|
||||
constructor(public readonly updates: Array<PropertyUpdatesForObject>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.updates];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
import { RemoteCallsForObject } from './remote-calls-for-objects';
|
||||
|
||||
@serializable
|
||||
export class RemoteCallsForObjects extends Command {
|
||||
constructor(public readonly callsForObjects: Array<RemoteCallsForObject>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.callsForObjects];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,23 @@
|
|||
import { Id } from '../../main';
|
||||
import { RemoteCall } from '../../objects/game-object';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { Id, RemoteCall } from '../../main';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
export class RemoteCallsForObject extends Command {
|
||||
constructor(public readonly id: Id, public readonly calls: Array<RemoteCall>) {
|
||||
super();
|
||||
}
|
||||
export class RemoteCallsForObject {
|
||||
constructor(public readonly id: Id, public readonly calls: Array<RemoteCall>) {}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.calls];
|
||||
}
|
||||
}
|
||||
|
||||
@serializable
|
||||
export class RemoteCallsForObjects extends Command {
|
||||
constructor(public readonly callsForObjects: Array<RemoteCallsForObject>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.callsForObjects];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Id } from '../../communication/id';
|
||||
import { CharacterTeam } from '../../objects/types/character-team';
|
||||
import { Id } from '../../transport/identity';
|
||||
import { serializable } from '../../transport/serialization/serializable';
|
||||
import { serializable } from '../../serialization/serializable';
|
||||
import { Command } from '../command';
|
||||
|
||||
@serializable
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue