Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions types/gimloader/gimloader-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ api.net.state.characters["..."].x; // $ExpectType number
api.net.state.characters.get("...")!.x; // $ExpectType number
api.net.state.teams[0].characters[0]; // $ExpectType string
api.net.state.mapSettings; // $ExpectType string
api.net.state.listen("teams", () => {});
api.net.state.characters.onAdd((item, index) => {
item; // $ExpectType ObjectSchema<CharacterState>
index; // $ExpectType string
item.listen("x", () => {});
});
api.net.state.teams.onAdd((item, index) => {
item; // $ExpectType ObjectSchema<TeamState>
index; // $ExpectType number
});
api.net.state.characters.onRemove((item, index) => {});
api.net.state.$callbacks;
api.net.state.characters.get("...")!.$callbacks;

// Test settings
api.settings.something;
Expand Down
32 changes: 22 additions & 10 deletions types/gimloader/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2261,19 +2261,24 @@ declare global {
error?: (error: any) => void;
}
namespace Schema {
type ObjectSchema<T extends object> = T & {
interface ColyseusMethods {
$callbacks: Record<string, any>;
$changes: any;
toJson(): any;
}
type ObjectSchema<T extends object> = T & ColyseusMethods & {
listen<K extends keyof T>(
key: K,
callback: (value: T[K], lastValue: T[K]) => void,
immediate?: boolean,
): () => void;
onChange(callback: () => void): () => void;
};
interface CollectionSchema<T, K> {
type CollectionSchema<T, K> = ColyseusMethods & {
onAdd(callback: (value: T, index: K) => void, immediate?: boolean): () => void;
onRemove(callback: (value: T, index: K) => void): () => void;
onChange(callback: (item: T, index: K) => void): () => void;
}
};
type MapSchema<T> =
& {
[key: string]: T;
Expand All @@ -2299,6 +2304,7 @@ declare global {
interface HealthState {
classImmunityActive: boolean;
fragility: number;
health: number;
lives: number;
maxHealth: number;
maxShield: number;
Expand All @@ -2316,11 +2322,16 @@ declare global {
waitingEndTime: number;
waitingStartTime: number;
}
interface SlotState {
amount: number;
}
interface InventoryState {
activeInteractiveSlot: number;
infiniteAmmo: boolean;
interactiveSlots: MapSchema<InteractiveSlotState>;
interactiveSlots: MapSchema<ObjectSchema<InteractiveSlotState>>;
interactiveSlotsOrder: ArraySchema<number>;
maxSlots: number;
slots: MapSchema<ObjectSchema<SlotState>>;
}
interface PermissionsState {
adding: boolean;
Expand Down Expand Up @@ -2386,8 +2397,8 @@ declare global {
url: string;
}
interface CallToActionState {
categories: ArraySchema<ActionCategoryState>;
items: ArraySchema<ActionItemState>;
categories: ArraySchema<ObjectSchema<ActionCategoryState>>;
items: ArraySchema<ObjectSchema<ActionItemState>>;
}
interface GameSessionState {
callToAction: ObjectSchema<CallToActionState>;
Expand Down Expand Up @@ -2437,15 +2448,16 @@ declare global {
score: number;
}
interface GimkitState {
characters: MapSchema<CharacterState>;
customAssets: MapSchema<CustomAssetState>;
characters: MapSchema<ObjectSchema<CharacterState>>;
customAssets: MapSchema<ObjectSchema<CustomAssetState>>;
hooks: ObjectSchema<HooksState>;
mapSettings: string;
matchmaker: ObjectSchema<MatchmakerState>;
session: ObjectSchema<SessionState>;
teams: ArraySchema<TeamState>;
teams: ArraySchema<ObjectSchema<TeamState>>;
world: ObjectSchema<WorldState>;
}
type GimkitSchema = ObjectSchema<GimkitState>;
}
class BaseNetApi extends EventEmitter2 {
constructor();
Expand All @@ -2456,7 +2468,7 @@ declare global {
/** The room that the client is connected to, or null if there is no connection */
get room(): any;
/** Gimkit's internal Colyseus state */
get state(): Schema.GimkitState;
get state(): Schema.GimkitSchema;
/** Whether the user is the one hosting the current game */
get isHost(): boolean;
/** Sends a message to the server on a specific channel */
Expand Down