Skip to content

Commit e628d8c

Browse files
authored
🤖 Merge PR DefinitelyTyped#73756 [Gimloader] Add types for gamemode header/apis by @TheLazySquid
1 parent 593b104 commit e628d8c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

‎types/gimloader/gimloader-tests.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ api.UI.showModal(document.createElement("div"), {
4141

4242
api.patcher.before({}, "foo", () => {});
4343
api.patcher.before({}, "foo", () => true);
44+
GL.net.gamemode; // $ExpectType string
45+
api.net.gamemode; // $ExpectType string
46+
api.net.onLoad((type, gamemode) => {});

‎types/gimloader/index.d.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ declare namespace Gimloader {
188188
needsLib: string[];
189189
optionalLib: string[];
190190
syncEval: string;
191+
gamemode: string[];
191192
hasSettings: string;
192193
};
193194
/** Gets the exported values of a plugin, if it has been enabled */
@@ -219,6 +220,7 @@ declare namespace Gimloader {
219220
needsLib: string[];
220221
optionalLib: string[];
221222
syncEval: string;
223+
gamemode: string[];
222224
hasSettings: string;
223225
};
224226
/** Gets the exported values of a library */
@@ -403,12 +405,14 @@ declare namespace Gimloader {
403405

404406
class ScopedNetApi extends BaseNetApi {
405407
private readonly id;
406-
constructor(id: string);
408+
private readonly defaultGamemode;
409+
constructor(id: string, defaultGamemode: string[]);
407410
/**
408-
* Runs a callback when the game is loaded, or runs it immediately if the game has already loaded
411+
* Runs a callback when the game is loaded, or runs it immediately if the game has already loaded.
412+
* If the \@gamemode header is set the callback will only fire if the gamemode matches one of the provided gamemodes.
409413
* @returns A function to cancel waiting for load
410414
*/
411-
onLoad(callback: (type: ConnectionType) => void): () => void;
415+
onLoad(callback: (type: ConnectionType, gamemode: string) => void, gamemode?: string | string[]): () => void;
412416
}
413417

414418
type ConnectionType = "None" | "Colyseus" | "Blueboat";
@@ -417,6 +421,8 @@ declare namespace Gimloader {
417421
constructor();
418422
/** Which type of server the client is currently connected to */
419423
get type(): ConnectionType;
424+
/** The id of the gamemode the player is currently playing */
425+
get gamemode(): string;
420426
/** The room that the client is connected to, or null if there is no connection */
421427
get room(): any;
422428
/** Whether the user is the one hosting the current game */
@@ -431,7 +437,11 @@ declare namespace Gimloader {
431437
* Runs a callback when the game is loaded, or runs it immediately if the game has already loaded
432438
* @returns A function to cancel waiting for load
433439
*/
434-
onLoad(id: string, callback: (type: ConnectionType) => void): () => void;
440+
onLoad(
441+
id: string,
442+
callback: (type: ConnectionType, gamemode: string) => void,
443+
gamemode?: string | string[],
444+
): () => void;
435445
/** Cancels any calls to {@link onLoad} with the same id */
436446
offLoad(id: string): void;
437447
/**

‎types/gimloader/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/gimloader",
4-
"version": "1.7.9999",
4+
"version": "1.8.9999",
55
"nonNpm": "conflict",
66
"nonNpmDescription": "Types for the Gimloader global variables",
77
"projects": [

0 commit comments

Comments
 (0)