-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
199 lines (199 loc) · 5.69 KB
/
index.d.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
/*
* partygame.show 1.0.0-alpha.13 (https://github.com/molisani/partygame.show-protocol)
* Copyright 2017 Michael Molisani
* Licensed under LGPL-3.0 (https://github.com/molisani/partygame.show-protocol/blob/master/LICENSE)
*/
declare namespace PartyGameShow {
namespace Game {
interface Metadata {
active: boolean;
title: string;
subtitle: string;
version: string;
minPlayers: number;
maxPlayers?: number;
}
interface Loader {
gametype: string;
metadata: Metadata;
}
interface ContentPack {
packID: string;
data: object;
}
interface Content {
base: ContentPack;
extra: ContentPack[];
}
}
interface Room {
roomID?: string;
lobbyCode: string;
}
interface Player {
playerID: string;
displayName: string;
color: string;
}
namespace Requests {
interface JoinLobby {
playerID: string;
lobbyCode: string;
}
interface ManagePlayers {
[playerID: string]: "add" | "kick" | "ban";
}
interface NewGame {
gametype: string;
playerIDs: string[];
}
interface UpdatePlayerState {
[playerID: string]: object | null;
}
}
namespace Responses {
interface AvailableGames {
games: Game.Loader[];
}
interface LoadGame extends Requests.NewGame {
reload: boolean;
}
}
interface PlayerMap<T> {
[playerID: string]: T;
}
interface PlayerScoreEntry {
score: number;
}
namespace Messages {
interface Payload {
type: string;
}
interface Packet {
msgID: string;
recipientIDs: string[];
payload: Payload;
expiresAfter: number;
notify: boolean;
}
interface ResponsePayload extends Payload {
authorID: string;
}
interface ResponsePacket {
msgID: string;
playerID: string;
response: ResponsePayload;
}
}
namespace Events {
interface ToHost {
availableGames: Responses.AvailableGames;
onRoom: Room;
gameContent: Game.Content;
playerJoinedLobby: Player;
playerUpdated: Player;
playerReady: Player;
playerReturned: Messages.ResponsePacket;
onError: object;
}
interface FromHost {
listGames: void;
startRoom: void;
endRoom: void;
managePlayers: Requests.ManagePlayers;
startGame: Requests.NewGame;
endGame: void;
updateState: Requests.UpdatePlayerState;
sendPacket: Messages.Packet;
forceClear: void;
}
interface ToClient {
playerInfo: Player;
joinedRoom: Room;
roomClosed: void;
loadGame: Responses.LoadGame;
unloadGame: void;
stateChanged: object | null;
onPacket: Messages.Packet;
onClear: void;
onError: object;
}
interface FromClient {
getPlayerInfo: void;
updatePlayerInfo: Partial<Player>;
joinLobby: Requests.JoinLobby;
gameReady: void;
stateChanged: object;
returnResponse: Messages.ResponsePacket;
}
}
namespace Signals {
interface ToHost {
availableGames(games: Responses.AvailableGames): void;
onRoom(room: Room): void;
gameContent(content: Game.Content): void;
playerJoinedLobby(player: Player): void;
playerUpdated(player: Player): void;
playerReady(player: Player): void;
playerReturned(packet: Messages.ResponsePacket): void;
onError(err: object): void;
}
interface FromHost {
listGames(_: void): void;
startRoom(_: void): void;
endRoom(_: void): void;
managePlayers(players: Requests.ManagePlayers): void;
startGame(game: Requests.NewGame): void;
endGame(_: void): void;
updateState(states: Requests.UpdatePlayerState): void;
sendPacket(packet: Messages.Packet): void;
forceClear(_: void): void;
}
interface ToClient {
playerInfo(player: Player): void;
joinedRoom(room: Room): void;
roomClosed(_: void): void;
loadGame(game: Responses.LoadGame): void;
unloadGame(_: void): void;
stateChanged(state: object | null): void;
onPacket(packet: Messages.Packet): void;
onClear(_: void): void;
onError(err: object): void;
}
interface FromClient {
getPlayerInfo(_: void): void;
updatePlayerInfo(request: Partial<Player>): void;
joinLobby(request: Requests.JoinLobby): void;
gameReady(_: void): void;
returnResponse(packet: Messages.ResponsePacket): void;
}
}
interface Listener<Events> {
addListener<E extends keyof Events, T>(event: E, listener: (this: T, data: Events[E]) => void, context?: T): string;
addOneTimeListener<E extends keyof Events, T>(event: E, listener: (this: T, data: Events[E]) => void, context?: T): string;
removeListener<E extends keyof Events>(event: E, id: string): void;
removeAllListeners<E extends keyof Events>(event: E): void;
}
namespace Services {
interface Host extends Signals.FromHost, Listener<Events.ToHost> { }
interface Client extends Signals.FromClient, Listener<Events.ToClient> { }
}
namespace Managers {
interface Host extends Signals.ToHost, Listener<Events.FromHost> { }
interface Client extends Signals.ToClient, Listener<Events.FromClient> { }
}
interface Server extends Signals.FromHost {
clientConnected(client: Managers.Client): void;
}
namespace Views {
interface GameHost {
start(host: Services.Host, players: Player[]): Promise<PlayerMap<PlayerScoreEntry>>;
}
interface GameClientRequestHandler<P extends Messages.Payload> {
handle(self: Player, payload: P): Promise<Messages.ResponsePayload>;
}
interface GameClient {
getHandler(payloadType: string): GameClientRequestHandler<Messages.Payload>;
}
}
}