forked from timetocode/nengi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
287 lines (233 loc) · 7.39 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
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
// Type definitions for nengi.js
// Project: https://timetocode.com/nengi
// Definitions by: Alex // timetocode <https://github.com/timetocode>
interface EDictionary {
/**
* Iterates through the EDictionary
* @param fn Provides (obj: any, i: number) to your function
*/
forEach(fn: (obj: any, i: number) => void)
/**
* Adds an object to the EDictionary. The object *MUST* have a nid/id property as defined in the nengiConfig
* @param obj
*/
add(obj: any): void
/**
* Removes an object from the EDictionary by reference
* @param obj
*/
remove(obj: any): void
/**
* Removes an object from the EDictionary by type
* @param id
*/
removeById(id: number): void
/**
* Provides access to the underlying data as an array. There is no performance penalty as the underlying data *is* an array. Do not mutate it, use add and remove instead.
*/
toArray(): any[]
}
declare namespace nengi {
export class Instance {
constructor(config: any, webConfig: any)
clients: EDictionary
//on(event: 'disconnect', callback: (client: any) => {}): void
//on(event: string, callback: (a: any, b: any, c: any) => {}): void
//on(event: string, callback: (a: any, b: any) => {}): void
on(event: string, callback: (client: any) => void)
// Warning: this function is only present if a nengi hooks mixin has been used.
emitCommands(): void
/**
* (NOT WORKING) Disables interpolation for an entity for one frame.
* @param nid
*/
noInterp(nid: number): void
/**
* Sleeps an entity, aka stops nengi from scanning the entity for changes each fick
* @param entity
*/
sleep(entity: any): void
/**
* Returns true if entity is awake
* @param entity
*/
isAwake(entity: any): boolean
/**
* Rreturns true if entity is asleep
* @param entity
*/
isAsleep(entity: any): boolean
/**
* Wakes an entity, aka enables nengi scanning the entity for changes each tick
* @param entity
*/
wake(entity: any): void
/**
* Wakes an entity for one server tick, so that changes to it will be networked. Entity will return to sleep the following tick.
* @param entity
*/
wakeOnce(entity: any): void
// none of these are intended for public consumption
//onMessage(message: any, client: any): void
//getNextCommand(): any
//onConnect(callback: any): void
//onDisconnect(callback: any): void
//acceptConnection(client: any, text: string): void
//denyConnection(client: any, text: string): void
//connect(connection: any)
/**
* Adds an entity to the game instance where it will be automatically synchronized to game clients. Assigns a nid and ntype to the entity.
* @param entity
*/
addEntity(entity: any): void
/**
* Removes an entity from the instance, causes it to disappear from all game clients. Changes entity nid to -1.
* @param entity
*/
removeEntity(entity: any): void
/**
* Gets an entity from the instance by nid. Will scan channels and all forms of visibility.
* @param id
*/
getEntity(id: number): any
/**
* Sends a message to one or more clients.
*
* @param message Message
* @param clientOrClients A client or an array of clients
*/
message(message: any, clientOrClients: any): any
/**
* Sends a message to all clients.
* @param message
*/
messageAll(message: any): void
/**
* Sends network snapshots to all clients. To be invoked towards the end of a game tick in most cases.
*/
update(): void
}
export class Client {
constructor(config: any, interDelay: number)
/**
* Connect to an instance
*
* @param address Address, e.g. ws://localhost:8001
* @param handshake (optional) Handshake object with any properties and values to pass to the server.
*/
connect(address: string, handshake?: any): void
/**
* Adds a command to the outbound queue
* @param command
*/
addCommand(command: any): void
/**
* Reads any queued data from the server, and returns them in snapshot format.
* @returns {object}
*/
readNetwork(): any
/**
* Flushes (sends) any outbound commands.
*/
update(): void
/**
* Reads any queued data from the server and emits it in the nengi hooks api format. Warning: this function is only present if a nengi hooks mixin has been used.
*/
readNetworkAndEmit(): any
// TODO
on(event: string, callback: (message: any) => void)
}
/**
* Holds a boolean value, serializes over the network to 1 bit
*/
export const Boolean: number
/**
* Holds any integer in the range 0 to3
*/
export const UInt2: number
/**
* Holds any integer in the range 0 to 7
*/
export const UInt3: number
/**
* Holds any integer in the range -8 to 7
*/
export const Int4: number
/**
* Holds any integer in the range 0 to 15
*/
export const UInt4: number
/**
* Holds any integer in the range -32 to 31
*/
export const Int6: number
/**
* Holds any integer in the range 0 to 65535
*/
export const UInt6: number
/**
* Holds any integer in the range -128 to 127
*/
export const Int8: number
/**
* Holds any integer in the range -512 to 511
*/
export const UInt8: number
/**
* Holds any integer in the range -512 to 511
*/
export const Int10: number
/**
* Holds any integer in the range 0 to 1023
*/
export const UInt10: number
/**
* Holds any integer in the range 0 to 4095
*/
export const UInt12: number
/**
* Holds any integer in the range -32768 to 32767
*/
export const Int16: number
/**
* Holds any integer in the range 0 to 65535
*/
export const UInt16: number
/**
* Holds any integer in the range -2147483648 to 2147483647
*/
export const Int32: number
/**
* Holds any integer in the range 0 to 4294967295
*/
export const UInt32: number
/**
* Holds a JavaScript Number (64 bit), same as Float64
*/
export const Number: number
/**
* Holds a 32 bit floating point, half the resolution of Float64 aka Number
*/
export const Float32: number
/**
* Holds a 64 bit floating point, same as Number
*/
export const Float64: number
/**
* Holds a 32 bit floating point that will be interpolated around
*/
export const RotationFloat32: number
/**
* Holds a string with a max length of 255 where each character is networked as byte (not utf8 safe!).
*/
export const ASCIIString: number
/**
* Alias to UTF8String
*/
export const String: number
/**
* Holds a string of UTF8 characters, maximum 4294967295 bytes
*/
export const UTF8String: number
}
export = nengi