-
Notifications
You must be signed in to change notification settings - Fork 17
/
DepictIt.js
47 lines (40 loc) · 1.44 KB
/
DepictIt.js
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
import { GameStateMachine } from "./GameStateMachine.js";
import {
StartHandler, DealHandler, GetUserDrawingHandler, GetUserCaptionHandler, PassStacksAroundHandler,
GetUserScoresHandler, EndHandler
} from "./DepictIt.handlers.js";
export const DepictIt = (handlerContext) => new GameStateMachine({
steps: {
"StartHandler": new StartHandler(),
"DealHandler": new DealHandler(),
"GetUserDrawingHandler": new GetUserDrawingHandler(183_000),
"GetUserCaptionHandler": new GetUserCaptionHandler(63_000),
"PassStacksAroundHandler": new PassStacksAroundHandler(),
"GetUserScoresHandler": new GetUserScoresHandler(),
"EndHandler": new EndHandler()
},
context: handlerContext
});
export class DepictItClient {
constructor(gameId, channel) {
this.gameId = gameId;
this.channel = channel;
}
async sendImage(base64EncodedImage) {
const result = await fetch("/api/storeImage", {
method: "POST",
body: JSON.stringify({ gameId: this.gameId, imageData: base64EncodedImage })
});
const savedUrl = await result.json();
this.channel.sendMessage({ kind: "drawing-response", imageUrl: savedUrl.url });
}
async sendCaption(caption) {
this.channel.sendMessage({ kind: "caption-response", caption: caption });
}
async logVote(id) {
this.channel.sendMessage({ kind: "pick-one-response", id: id });
}
async hostProgressedVote() {
this.channel.sendMessage({ kind: "skip-scoring-forwards" })
}
}