Add input handling
This commit is contained in:
parent
29c6b14440
commit
d5be727040
36 changed files with 417 additions and 113 deletions
13
frontend/src/scripts/commands/command-broadcaster.ts
Normal file
13
frontend/src/scripts/commands/command-broadcaster.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { CommandReceiver } from './command-receiver';
|
||||
import { CommandGenerator } from './command-generator';
|
||||
|
||||
export class CommandBroadcaster {
|
||||
constructor(
|
||||
commandGenerators: Array<CommandGenerator>,
|
||||
commandReceivers: Array<CommandReceiver>
|
||||
) {
|
||||
commandReceivers.forEach((r) =>
|
||||
commandGenerators.forEach((g) => g.subscribe(r))
|
||||
);
|
||||
}
|
||||
}
|
||||
14
frontend/src/scripts/commands/command-generator.ts
Normal file
14
frontend/src/scripts/commands/command-generator.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { CommandReceiver } from './command-receiver';
|
||||
import { Command } from './command';
|
||||
|
||||
export class CommandGenerator {
|
||||
private subscribers: Array<CommandReceiver> = [];
|
||||
|
||||
public subscribe(subscriber: CommandReceiver): void {
|
||||
this.subscribers.push(subscriber);
|
||||
}
|
||||
|
||||
protected sendCommand(command: Command): void {
|
||||
this.subscribers.forEach((s) => s.sendCommand(command));
|
||||
}
|
||||
}
|
||||
5
frontend/src/scripts/commands/command-receiver.ts
Normal file
5
frontend/src/scripts/commands/command-receiver.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { Command } from './command';
|
||||
|
||||
export interface CommandReceiver {
|
||||
sendCommand(command: Command): void;
|
||||
}
|
||||
3
frontend/src/scripts/commands/command.ts
Normal file
3
frontend/src/scripts/commands/command.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { Typed } from '../transport/serializable';
|
||||
|
||||
export abstract class Command extends Typed {}
|
||||
7
frontend/src/scripts/commands/types/key-down.ts
Normal file
7
frontend/src/scripts/commands/types/key-down.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Command } from '../command';
|
||||
|
||||
export class KeyDownCommand extends Command {
|
||||
public constructor(public readonly key: string) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
7
frontend/src/scripts/commands/types/key-up.ts
Normal file
7
frontend/src/scripts/commands/types/key-up.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Command } from '../command';
|
||||
|
||||
export class KeyUpCommand extends Command {
|
||||
public constructor(public readonly key: string) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
8
frontend/src/scripts/commands/types/primary-action.ts
Normal file
8
frontend/src/scripts/commands/types/primary-action.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Command } from '../command';
|
||||
import { Vec2 } from '../../math/vec2';
|
||||
|
||||
export class PrimaryActionCommand extends Command {
|
||||
public constructor(public readonly position: Vec2) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
8
frontend/src/scripts/commands/types/secondary-action.ts
Normal file
8
frontend/src/scripts/commands/types/secondary-action.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Command } from '../command';
|
||||
import { Vec2 } from '../../math/vec2';
|
||||
|
||||
export class SecondaryActionCommand extends Command {
|
||||
public constructor(public readonly position: Vec2) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
8
frontend/src/scripts/commands/types/swipe.ts
Normal file
8
frontend/src/scripts/commands/types/swipe.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Command } from '../command';
|
||||
import { Vec2 } from '../../math/vec2';
|
||||
|
||||
export class SwipeCommand extends Command {
|
||||
public constructor(public readonly delta: Vec2) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue