mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-22 18:15:27 -04:00
c37e129a5b
* One or more preview windows can be launched and used with the GDevelop Debugger, like on the desktop app. * To run the Debugger, click on the button next to the Play button in the toolbar and choose "Start Preview with Debugger and Performance Profiler" * This is useful to inspect instances of objects, inspect internal messages or run the performance profiler. * A right click on the Play button will also allow to launch a new preview, in a new window. * Also fix the loading screen not shown in the preview on the web-app even when asked to be shown (using the game properties preview button)
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
namespace gdjs {
|
|
const logger = new gdjs.Logger('Debugger client (window message)');
|
|
|
|
/**
|
|
* This debugger client connects to the parent window, exchanging
|
|
* and receiving messages using `postMessage` and the `message` event listener.
|
|
*/
|
|
export class WindowMessageDebuggerClient extends gdjs.AbstractDebuggerClient {
|
|
_opener: Window | null = null;
|
|
|
|
/**
|
|
* @param path - The path of the property to modify, starting from the RuntimeGame.
|
|
*/
|
|
constructor(runtimeGame: RuntimeGame) {
|
|
super(runtimeGame);
|
|
|
|
this._opener = window.opener || null;
|
|
if (!this._opener) {
|
|
logger.info("`window.opener` not existing, the debugger won't work.");
|
|
return;
|
|
}
|
|
|
|
window.addEventListener('message', (event) => {
|
|
const data = event.data;
|
|
this.handleCommand(data);
|
|
});
|
|
}
|
|
|
|
protected _sendMessage(message: string) {
|
|
if (!this._opener) return;
|
|
|
|
try {
|
|
this._opener.postMessage(message, '*');
|
|
} catch (error) {
|
|
this._originalConsole.warn(
|
|
'Error while sending a message to the debugger:',
|
|
error
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Register the class to let the engine use it.
|
|
// @ts-ignore
|
|
export const DebuggerClient = WindowMessageDebuggerClient;
|
|
}
|