36 lines
666 B
TypeScript
36 lines
666 B
TypeScript
type GameLaunchState = {
|
|
isOpen: boolean;
|
|
placeId?: string;
|
|
gameInstanceId?: string;
|
|
};
|
|
|
|
let state: GameLaunchState = { isOpen: false };
|
|
const listeners = new Set<() => void>();
|
|
|
|
function emit() {
|
|
listeners.forEach((listener) => listener());
|
|
}
|
|
|
|
export function getGameLaunchState() {
|
|
return state;
|
|
}
|
|
|
|
export function subscribeGameLaunch(listener: () => void) {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
}
|
|
|
|
export function openGameLaunchWithParams(placeId: string, jobId?: string) {
|
|
state = {
|
|
isOpen: true,
|
|
placeId,
|
|
gameInstanceId: jobId
|
|
};
|
|
emit();
|
|
}
|
|
|
|
export function closeGameLaunch() {
|
|
state = { isOpen: false };
|
|
emit();
|
|
}
|