-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.ts
425 lines (393 loc) · 11.1 KB
/
types.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
import { Dispatch as ReduxDispatch } from "redux";
import * as ta from "typesafe-actions";
import * as ro from "redux-observable";
import * as ct from "./common-types";
export * from "./common-types";
// export type CardId = string;
// export type GameId = string;
// export type UserId = string | undefined;
// export type HintNumber = number | "Zero" | "Infinity";
// export interface SetPage {
// type: ActionType.SET_PAGE;
// page: Page;
// }
// export interface SetCardFlipped {
// type: ActionType.SET_CARD_FLIPPED;
// cardId: CardId;
// }
// export interface PickRole {
// type: ActionType.PICK_ROLE;
// team: Team;
// role: Role;
// }
// export interface SetTime {
// type: ActionType.SET_TIME;
// seconds: number;
// }
// export interface ToggleTitle {
// type: ActionType.TOGGLE_TITLE;
// }
// export interface ErrorOccured {
// type: ActionType.ERROR_OCCURED;
// text: string;
// severity: Severity;
// }
// export interface DimissError {
// type: ActionType.DISMISS_ERROR;
// }
// export interface SetWs {
// type: ActionType.SET_WS;
// ws: any;
// }
// export interface SetUsername {
// type: ActionType.SET_USERNAME;
// username: string;
// }
// export interface SetEditing {
// type: ActionType.SET_EDITING;
// flag: boolean;
// }
// export interface UpdateUserList {
// type: ActionType.UPDATE_USER_LIST;
// }
// export interface UpdateRemoteState {
// type: ActionType.UPDATE_REMOTE_STATE;
// remoteState: any;
// }
// export interface AddUser {
// type: ActionType.ADD_USER;
// userId: UserId;
// ws: any;
// }
// export interface RemoveUser {
// type: ActionType.REMOVE_USER;
// userId: UserId;
// }
// export interface UpdateUsername {
// type: ActionType.UPDATE_USERNAME;
// }
// export interface UpdateHint {
// type: ActionType.UPDATE_HINT;
// hint: string;
// }
// export interface StartTimer {
// type: ActionType.START_TIMER;
// }
// export interface UpdateHintNumber {
// type: ActionType.UPDATE_HINT_NUMBER;
// hintNumber: HintNumber;
// }
// export interface NextTurn {
// type: ActionType.NEXT_TURN;
// }
// export interface Forfeit {
// type: ActionType.FORFEIT;
// team: Team;
// }
// export interface StopTimer {
// type: ActionType.STOP_TIMER;
// }
// export interface NewGame {
// type: ActionType.NEW_GAME;
// }
// export interface EmitAction {
// type: ActionType.EMIT_ACTION;
// }
// export interface SetServerUsername {
// type: ActionType.SET_SERVER_USERNAME;
// username: string;
// }
// export interface ListenToWebsocket {
// type: ActionType.LISTEN_TO_WEBSOCKET;
// }
// export interface ChangeBackgroundColor {
// type: ActionType.CHANGE_BACKGROUND_COLOR;
// team: Team;
// backgroundColor: string;
// }
// export interface SubmitHint {
// type: ActionType.SUBMIT_HINT;
// }
// export interface FlipCard {
// type: ActionType.FLIP_CARD;
// cardId: CardId;
// }
// export interface NewGame2 {
// type: ActionType.NEW_GAME_2;
// }
// export interface SetUserId {
// type: ActionType.SET_USER_ID;
// userId: UserId;
// }
// export interface SetGameIds {
// type: ActionType.SET_GAME_IDS;
// gameIds: GameId[];
// }
// export interface SetGameId {
// type: ActionType.SET_GAME_ID;
// gameId: GameId;
// }
// export interface JoinGame {
// type: ActionType.JOIN_GAME;
// userId: UserId;
// gameId: GameId;
// }
// export interface ConnectToServer {
// type: ActionType.CONNECT_TO_SERVER;
// serverAddress: string;
// }
// export interface UpdateServerAddress {
// type: ActionType.UPDATE_SERVER_ADDRESS;
// serverAddress: string;
// }
// export interface SetConnected {
// type: ActionType.SET_CONNECTED;
// flag: boolean;
// }
// export interface ToServer {
// type: ActionType.TO_SERVER;
// action: ServerAction;
// }
// export type ServerAction = any;
// export type Action =
// | ToServer
// | SetPage
// | SetCardFlipped
// | PickRole
// | SetTime
// | ToggleTitle
// | ErrorOccured
// | DimissError
// | SetWs
// | SetUsername
// | SetEditing
// | UpdateUserList
// | UpdateRemoteState
// | AddUser
// | RemoveUser
// | UpdateUsername
// | UpdateHint
// | StartTimer
// | UpdateHintNumber
// | NextTurn
// | Forfeit
// | StopTimer
// | NewGame
// | EmitAction
// | SetServerUsername
// | ListenToWebsocket
// | ChangeBackgroundColor
// | SubmitHint
// | FlipCard
// | NewGame2
// | SetUserId
// | SetGameIds
// | SetGameId
// | JoinGame
// | ConnectToServer
// | UpdateServerAddress
// | SetConnected;
// export enum ActionType {
// TO_SERVER = "async server action",
// SET_PAGE = "set page",
// SET_CARD_FLIPPED = "flip this card",
// PICK_ROLE = "change role",
// SET_TIME = "set time",
// TOGGLE_TITLE = "toggle title",
// ERROR_OCCURED = "an error has occured",
// DISMISS_ERROR = "dismiss error",
// SET_WS = "set ws",
// SET_USERNAME = "set username",
// SET_EDITING = "set editing",
// UPDATE_USER_LIST = "update user list",
// UPDATE_REMOTE_STATE = "update remote state",
// ADD_USER = "server add user",
// REMOVE_USER = "server remove user",
// UPDATE_USERNAME = "server update username",
// UPDATE_HINT = "update hint",
// START_TIMER = "async start timer",
// UPDATE_HINT_NUMBER = "update hint number",
// NEXT_TURN = "next turn",
// FORFEIT = "forfeit",
// STOP_TIMER = "async stop timer",
// NEW_GAME = "async new game",
// EMIT_ACTION = "async emit",
// SET_SERVER_USERNAME = "async set server username",
// LISTEN_TO_WEBSOCKET = "async listen to websocket",
// CHANGE_BACKGROUND_COLOR = "async change backgroundColor",
// SUBMIT_HINT = "async submit hint",
// FLIP_CARD = "async flip card",
// NEW_GAME_2 = "async new game 2",
// SET_USER_ID = "set user id",
// SET_GAME_IDS = "set game ids",
// SET_GAME_ID = "set game id",
// JOIN_GAME = "async join game",
// CONNECT_TO_SERVER = "async connect to server",
// UPDATE_SERVER_ADDRESS = "update server address",
// SET_CONNECTED = "set connected"
// }
// export enum Page {
// GAME_MODE_PICK_TEAM = "pick team",
// LOBBY = "lobby",
// GAME_MODE_GAME = "game mode game"
// }
// export enum Team {
// TEAM_1 = "team1",
// TEAM_2 = "team2",
// ASSASSIN = "assassin",
// BYSTANDER = "bystander"
// }
// export interface Card {
// text: string;
// flipped: boolean;
// id: CardId;
// team: Team;
// }
// export enum Role {
// SPYMASTER = "spymaster",
// AGENT = "spymaster"
// }
// export enum Severity {
// ERROR = "error",
// WARN = "warn"
// }
// interface Settings {
// showTitle: boolean;
// }
// export interface Error {
// text: string;
// severity: Severity;
// }
// interface PlayerType {
// team: Team;
// role: Role;
// }
// export interface LocalState {
// ws: any;
// userId: UserId;
// connected: boolean;
// serverAddress: string;
// username: string;
// settings: Settings;
// error: fp.option.Option<Error>;
// page: Page;
// playerType: PlayerType;
// gameIds: GameId[];
// gameId?: GameId;
// }
// interface Score {
// [Team.TEAM_1]: number;
// [Team.TEAM_2]: number;
// }
// interface Hint {
// text: string;
// number: HintNumber;
// submitted: boolean;
// }
// export type Cards = { [cardId: string]: Card };
// export interface Style {
// [Team.TEAM_1]: React.CSSProperties;
// [Team.TEAM_2]: React.CSSProperties;
// [Team.ASSASSIN]: React.CSSProperties;
// [Team.BYSTANDER]: React.CSSProperties;
// }
// export interface RemoteState {
// winner: fp.option.Option<Team>;
// time: number;
// score: Score;
// hint: Hint;
// cards: Cards;
// style: Style;
// clientUsers: string[];
// currentTeam: Team;
// }
// export interface ReduxState {
// localState: LocalState;
// remoteState: fp.option.Option<RemoteState>;
// }
// export interface Api {
// dismissError: () => void;
// changeUsername: (username: string) => void;
// joinGame: (gameId: GameId, userId: UserId) => void;
// pickRole: (team: Team, role: Role) => void;
// setBackgroundColor: (team: Team, color: string) => void;
// connectToServer: (serverAddress: string) => void;
// newGame: () => void;
// }
// export const lens = (() => {
// const reduxStateFP = m.Lens.fromProp<ReduxState>();
// const reduxStateFOP = m.Optional.fromOptionProp<ReduxState>();
// const localStateFP = m.Lens.fromProp<LocalState>();
// const remoteStateFP = m.Lens.fromProp<RemoteState>();
// const playerTypeFP = m.Lens.fromProp<PlayerType>();
// const cardFP = m.Lens.fromProp<Card>();
// const localStateL = reduxStateFP("localState");
// const remoteStateL = reduxStateFOP("remoteState");
// const playerTypeL = localStateL.compose(localStateFP("playerType"));
// const playerType = {
// team: playerTypeL.compose(playerTypeFP("team")),
// role: playerTypeL.compose(playerTypeFP("role"))
// };
// const localState = {
// ws: localStateL.compose(localStateFP("ws")),
// userId: localStateL.compose(localStateFP("userId")),
// connected: localStateL.compose(localStateFP("connected")),
// serverAddress: localStateL.compose(localStateFP("serverAddress")),
// username: localStateL.compose(localStateFP("username")),
// settings: localStateL.compose(localStateFP("settings")),
// error: localStateL.compose(localStateFP("error")),
// page: localStateL.compose(localStateFP("page")),
// playerType,
// gameIds: localStateL.compose(localStateFP("gameIds")),
// gameId: localStateL.compose(localStateFP("gameId"))
// };
// const remoteState = {
// winner: remoteStateL.compose(remoteStateFP("winner").asOptional()),
// time: remoteStateL.compose(remoteStateFP("time").asOptional()),
// score: remoteStateL.compose(remoteStateFP("score").asOptional()),
// hint: remoteStateL.compose(remoteStateFP("hint").asOptional()),
// cards: {
// l: remoteStateL.compose(remoteStateFP("cards").asOptional()),
// idx: (i: number) => {
// const cardsLens = remoteStateL.compose(
// remoteStateFP("cards")
// .asOptional()
// .compose(
// new m.Lens(
// (a: Cards) => a[i],
// (c: Card) => (cs: Cards) => ({ ...cs, [c.id]: c })
// ).asOptional()
// )
// );
// const card = {
// text: cardsLens.compose(cardFP("text").asOptional())
// };
// return {
// card: cardsLens,
// ...card
// };
// }
// },
// style: remoteStateL.compose(remoteStateFP("style").asOptional()),
// clientUsers: remoteStateL.compose(
// remoteStateFP("clientUsers").asOptional()
// ),
// currentTeam: remoteStateL.compose(remoteStateFP("currentTeam").asOptional())
// };
// return {
// reduxState: {
// localState,
// remoteState
// }
// };
// })();
export type RootAction = ta.ActionType<typeof import("./redux/actions")>;
export interface ReduxState2 {
socket: ct.Option<SocketIOClient.Socket>;
playerId: ct.Option<ct.PlayerId>;
page: ct.Page;
gameIds: ct.GameId[];
game: ct.Option<ct.Game>;
}
export type Dispatch = ReduxDispatch<RootAction>;
export type Epic = ro.Epic<RootAction, RootAction, ReduxState2>;