Skip to content

Add support of Panorama Events #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 7, 2025
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
48 changes: 33 additions & 15 deletions packages/panorama-types/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ declare namespace GameEvents {
: InferCustomGameEventType<T, TUntyped>;
}

declare namespace PanoramaEvents {
type PanoramaEventName = keyof PanoramaEvent;
type InferPanoramaEventParams<T extends string, TUntyped> = T extends PanoramaEventName
? PanoramaEvent[T] extends (...args: infer P) => void
? P | [PanelBase, ...P]
: TUntyped
: TUntyped;
type InferPanoramaCallback<T extends string> = T extends PanoramaEventName
? PanoramaEvent[T] extends (...args: infer P) => void
? (...args: P) => void
: (...args: any[]) => void
: (...args: any[]) => void;
}

interface CDOTA_PanoramaScript_GameEvents {
/**
* Subscribe to a game event.
Expand Down Expand Up @@ -1972,10 +1986,16 @@ interface DollarStatic {
GetContextPanel(): Panel;
Schedule(time: number, callback: () => void): ScheduleID;
CancelScheduled(scheduledEvent: ScheduleID): void;
DispatchEvent(event: string, panelID?: string, ...args: any[]): void;
DispatchEvent(event: string, panel: PanelBase, ...args: any[]): void;
DispatchEventAsync(delay: number, event: string, panelID?: string, ...args: any[]): void;
DispatchEventAsync(delay: number, event: string, panel: PanelBase, ...args: any[]): void;

DispatchEvent<E extends PanoramaEvents.PanoramaEventName | string>(
eventName: E extends PanoramaEvents.PanoramaEventName ? E : string,
...args: PanoramaEvents.InferPanoramaEventParams<E, any[]>
): void;
DispatchEventAsync<E extends PanoramaEvents.PanoramaEventName | string>(
eventName: E extends PanoramaEvents.PanoramaEventName ? E : string,
...args: PanoramaEvents.InferPanoramaEventParams<E, any[]>
): void;

Language(): string;
/**
* Localize a string. Optionally accepts Quantity, Precision, and Panel arguments.
Expand All @@ -1986,18 +2006,16 @@ interface DollarStatic {
* @deprecated
*/
LocalizePlural(token: string, value: number, parent?: PanelBase): string;
RegisterEventHandler(
event: 'DragStart',
parent: PanelBase,
handler: (panelID: string, settings: DragSettings) => boolean,
): void;
RegisterEventHandler(
event: 'DragEnd' | 'DragDrop' | 'DragEnter' | 'DragLeave',
parent: PanelBase,
handler: (panelID: string, dragged: Panel) => boolean,

RegisterEventHandler<E extends PanoramaEvents.PanoramaEventName | string>(
eventName: E extends PanoramaEvents.PanoramaEventName ? E : string,
panel: PanelBase | string,
callback: PanoramaEvents.InferPanoramaCallback<E>,
): void;
RegisterEventHandler(event: string, parent: PanelBase, handler: (...args: any[]) => void): void;
RegisterForUnhandledEvent(event: string, handler: (...args: any[]) => void): UnhandledEventListenerID;
RegisterForUnhandledEvent<E extends PanoramaEvents.PanoramaEventName | string>(
eventName: E extends PanoramaEvents.PanoramaEventName ? E : string,
callback: PanoramaEvents.InferPanoramaCallback<E>,
): UnhandledEventListenerID;
UnregisterForUnhandledEvent(event: string, handle: UnhandledEventListenerID): void;
Each<T>(list: T[], callback: (item: T, index: number) => void): void;
Each<T>(map: { [key: string]: T }, callback: (value: T, key: string) => void): void;
Expand Down
1 change: 1 addition & 0 deletions packages/panorama-types/types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference path="css.d.ts" />
/// <reference path="events.generated.d.ts" />
/// <reference path="panels.d.ts" />
/// <reference path="panorama-events.d.ts" />
/// <reference path="stack-trace-api.d.ts" />

type EntityIndex = number & { _entityIndex: never };
Expand Down
Loading