-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequests.ts
60 lines (47 loc) · 1.31 KB
/
requests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Rotation } from './types'
export enum MovementDirection {
Forward = 'forward',
Backward = 'backward'
}
export enum RequestTypes {
Rotate,
Shoot,
Move,
DeployMine,
Exit
}
export interface RotateRequest {
type: RequestTypes.Rotate
data: {
rotation: Rotation
}
}
export interface MoveRequest {
type: RequestTypes.Move
data: {
direction: MovementDirection
withTurbo: boolean
}
}
export interface ShootRequest {
type: RequestTypes.Shoot
}
export interface DeployMineRequest {
type: RequestTypes.DeployMine
}
export type Request = RotateRequest | MoveRequest | ShootRequest | DeployMineRequest
export function rotateRequest (rotation: Rotation): RotateRequest {
return { type: RequestTypes.Rotate, data: { rotation } }
}
export function moveForwardRequest (options: { withTurbo: boolean }): MoveRequest {
return { type: RequestTypes.Move, data: { direction: MovementDirection.Forward, ...options } }
}
export function moveBackwardRequest (options: { withTurbo: boolean }): MoveRequest {
return { type: RequestTypes.Move, data: { direction: MovementDirection.Backward, ...options } }
}
export function shootRequest (): ShootRequest {
return { type: RequestTypes.Shoot }
}
export function deployMineRequest (): DeployMineRequest {
return { type: RequestTypes.DeployMine }
}