Refactor frontend to use commands
This commit is contained in:
parent
be26ab422c
commit
503c99cb1f
25 changed files with 8031 additions and 23084 deletions
|
|
@ -13,6 +13,6 @@ export abstract class CommandGenerator {
|
|||
}
|
||||
|
||||
protected sendCommandToSubscribers(command: Command): void {
|
||||
this.subscribers.forEach((s) => s.sendCommand(command));
|
||||
this.subscribers.forEach((s) => s.handleCommand(command));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,9 @@ import { Command } from './command';
|
|||
export abstract class CommandReceiver {
|
||||
protected commandExecutors: CommandExecutors = {};
|
||||
|
||||
public reactsToCommand(commandType: string): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType);
|
||||
}
|
||||
|
||||
protected defaultCommandExecutor(_: Command) {}
|
||||
|
||||
public sendCommand(command: Command) {
|
||||
public handleCommand(command: Command) {
|
||||
const commandType = command.type;
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType)) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { Command } from '../commands/command';
|
||||
import { CommandReceiver } from '../commands/command-receiver';
|
||||
import { Id } from '../communication/id';
|
||||
import { serializable } from '../serialization/serializable';
|
||||
|
||||
|
|
@ -11,12 +13,14 @@ export class RemoteCall {
|
|||
}
|
||||
|
||||
@serializable
|
||||
export class UpdateProperty {
|
||||
export class UpdatePropertyCommand extends Command {
|
||||
constructor(
|
||||
public readonly propertyKey: string,
|
||||
public readonly propertyValue: any,
|
||||
public readonly rateOfChange: any,
|
||||
) {}
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.propertyKey, this.propertyValue, this.rateOfChange];
|
||||
|
|
@ -25,17 +29,22 @@ export class UpdateProperty {
|
|||
|
||||
@serializable
|
||||
export class PropertyUpdatesForObject {
|
||||
constructor(public readonly id: Id, public readonly updates: Array<UpdateProperty>) {}
|
||||
constructor(
|
||||
public readonly id: Id,
|
||||
public readonly updates: Array<UpdatePropertyCommand>,
|
||||
) {}
|
||||
|
||||
public toArray(): Array<any> {
|
||||
return [this.id, this.updates];
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class GameObject {
|
||||
export abstract class GameObject extends CommandReceiver {
|
||||
private remoteCalls: Array<RemoteCall> = [];
|
||||
|
||||
constructor(public readonly id: Id) {}
|
||||
constructor(public readonly id: Id) {
|
||||
super();
|
||||
}
|
||||
|
||||
public processRemoteCalls(remoteCalls: Array<RemoteCall>) {
|
||||
remoteCalls.forEach((r) =>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { serializable } from '../../serialization/serializable';
|
|||
import { GameObject } from '../game-object';
|
||||
import { Id } from '../../communication/id';
|
||||
import { CharacterTeam } from './character-base';
|
||||
import { CommandExecutors } from '../../commands/command-executors';
|
||||
|
||||
@serializable
|
||||
export class ProjectileBase extends GameObject {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue